public function testAddSummaryVariantOnlyDescribedOnGenomicLevel()
{
// Wait for redirect
$this->waitUntil(WebDriverExpectedCondition::titleContains("View genomic variant"));
$this->assertTrue((bool) preg_match('/^[\\s\\S]*\\/src\\/variants\\/0000000003$/', $this->driver->getCurrentURL()));
$element = $this->driver->findElement(WebDriverBy::id("tab_submit"));
$element->click();
$this->assertTrue((bool) preg_match('/^[\\s\\S]*\\/src\\/submit$/', $this->driver->getCurrentURL()));
$element = $this->driver->findElement(WebDriverBy::xpath("//div/table/tbody/tr/td/table/tbody/tr[2]/td[2]/b"));
$element->click();
$this->assertTrue((bool) preg_match('/^[\\s\\S]*Please reconsider to submit individual data as well, as it makes the data you submit much more valuable![\\s\\S]*$/', $this->getConfirmation()));
$this->chooseOkOnNextConfirmation();
$this->assertTrue((bool) preg_match('/^[\\s\\S]*\\/src\\/variants[\\s\\S]create$/', $this->driver->getCurrentURL()));
$element = $this->driver->findElement(WebDriverBy::xpath("//div/table/tbody/tr/td/table/tbody/tr[2]/td[2]/b"));
$element->click();
$this->assertTrue((bool) preg_match('/^[\\s\\S]*\\/src\\/variants[\\s\\S]create&reference=Genome$/', $this->driver->getCurrentURL()));
$option = $this->driver->findElement(WebDriverBy::xpath('//select[@name="allele"]/option[text()="Paternal (confirmed)"]'));
$option->click();
$option = $this->driver->findElement(WebDriverBy::xpath('//select[@name="chromosome"]/option[text()="15"]'));
$option->click();
$this->enterValue(WebDriverBy::name("VariantOnGenome/DNA"), "g.40702976G>T");
$element = $this->driver->findElement(WebDriverBy::linkText("PubMed"));
$element->click();
// Move mouse to let browser hide tooltip of pubmed link (needed for chrome)
$this->driver->getMouse()->mouseMove(null, 200, 200);
$this->enterValue(WebDriverBy::name("VariantOnGenome/Reference"), "{PMID:Fokkema et al (2011):21520333}");
$this->enterValue(WebDriverBy::name("VariantOnGenome/Frequency"), "11/10000");
$option = $this->driver->findElement(WebDriverBy::xpath('//select[@name="effect_reported"]/option[text()="Effect unknown"]'));
$option->click();
$element = $this->driver->findElement(WebDriverBy::xpath("//input[@value='Create variant entry']"));
$element->click();
$this->assertTrue((bool) preg_match('/^Successfully processed your submission and sent an email notification to the relevant curator[\\s\\S]*$/', $this->driver->findElement(WebDriverBy::cssSelector("table[class=info]"))->getText()));
}
public function testTestReadOnlyState()
{
// Test that LOVD is in the read-only state.
// First, log out of any session that might exist at this time.
$this->logout();
// There should be no link to register yourself.
// First, I had this findElements(), but Chrome doesn't like that at all, and times out.
// Firefox anyway took quite some time, because of the timeout that we have set if elements are not found immediately (normally needed if pages load slowly).
// $this->assertFalse((bool) count($this->driver->findElements(WebDriverBy::xpath('//a/b[text()="Register as submitter"]'))));
// New attempt to test for absence of register link.
$this->assertFalse(strpos($this->driver->findElement(WebDriverBy::xpath('//table[@class="logo"]//td[3]'))->getText(), 'Register as submitter'));
$this->driver->get(ROOT_URL . '/src/login');
$this->assertTrue((bool) preg_match('/^[\\s\\S]*\\/src\\/login$/', $this->driver->getCurrentURL()));
// Verify warning exists. Finds any TD with this text.
$this->driver->findElement(WebDriverBy::xpath('//td[text()="This installation is currently configured to be read-only. Only Managers and higher level users can log in."]'));
// Attempt to log in, should fail in a specific way.
$this->enterValue(WebDriverBy::name('username'), 'submitter');
$this->enterValue(WebDriverBy::name('password'), 'test1234');
$element = $this->driver->findElement(WebDriverBy::xpath('//input[@value="Log in"]'));
$element->click();
// Should return a proper error message.
$this->assertEquals('This installation is currently configured to be read-only. Your user level is not sufficient to log in.', $this->driver->findElement(WebDriverBy::cssSelector('div[class=err]'))->getText());
// Also curators should fail.
$this->enterValue(WebDriverBy::name('username'), 'curator');
$this->enterValue(WebDriverBy::name('password'), 'test1234');
$element = $this->driver->findElement(WebDriverBy::xpath('//input[@value="Log in"]'));
$element->click();
// Should return a proper error message.
$this->assertEquals('This installation is currently configured to be read-only. Your user level is not sufficient to log in.', $this->driver->findElement(WebDriverBy::cssSelector('div[class=err]'))->getText());
}
public function testCreateAnnouncementReadOnly()
{
// Create an announcement, that switches LOVD into the read-only state.
// This test assumes you're logged in as manager or admin.
$sAnnouncement = 'This is a test announcement. LOVD will be closed for registrations, and lower level users can not log in.';
$this->driver->get(ROOT_URL . '/src/announcements?create');
$this->assertTrue((bool) preg_match('/^[\\s\\S]*\\/src\\/announcements[\\s\\S]create$/', $this->driver->getCurrentURL()));
$option = $this->driver->findElement(WebDriverBy::xpath('//select[@name="type"]/option[text()="Warning"]'));
$option->click();
$this->enterValue(WebDriverBy::name('announcement'), $sAnnouncement);
$this->enterValue(WebDriverBy::name('start_date'), '');
// No value, means active from now().
$this->enterValue(WebDriverBy::name('end_date'), '');
// No value, means active until '9999-12-31 23:59:59'.
$this->check(WebDriverBy::name('lovd_read_only'));
$this->enterValue(WebDriverBy::name('password'), 'test1234');
$element = $this->driver->findElement(WebDriverBy::xpath('//input[@value="Create announcement"]'));
$element->click();
$this->driver->findElement(WebDriverBy::xpath('//td[text()="Successfully created the announcement!"]'));
// Finds any TD with this text.
// Also check if announcement is actually visible.
$this->assertEquals($sAnnouncement, $this->driver->findElement(WebDriverBy::cssSelector('table[class=info]'))->getText());
// Wait for redirect...
$this->waitUntil(WebDriverExpectedCondition::titleContains('View announcement'));
$this->assertTrue((bool) preg_match('/^[\\s\\S]*\\/src\\/announcements\\/\\d{5}$/', $this->driver->getCurrentURL()));
}
public function testCheckCustomLinks()
{
// This test checks some basic functionality of the custom links. It
// doesn't require authorization, just checks some VLs if the links are
// rendered correctly.
// Load the common variant overview.
$this->driver->get(ROOT_URL . '/src/variants');
// Find a custom link, and move the mouse over it.
$oCustomLink = $this->driver->findElement(WebDriverBy::xpath('//table[@class="data"]/tbody/tr/td/span[text()="dbSNP"]'));
$this->driver->getMouse()->mouseMove($oCustomLink->getCoordinates());
// Now find the tooltip that should have shown.
$sToolTipLinkText = $this->driver->findElement(WebDriverBy::xpath('//div[@id="tooltip"]/a'))->getText();
$this->assertTrue(strpos($sToolTipLinkText, 'http') === 0 && strpos($sToolTipLinkText, 'SNP'));
// This test data does not have many links, try and find a PubMed link.
// Load the in_gene view.
$this->driver->get(ROOT_URL . '/src/variants/in_gene');
// Filter on Reference, so we can find this link on the first page.
$sSelector = WebDriverBy::name('search_VariantOnGenome/Reference');
$this->enterValue($sSelector, 'Fokkema');
$oElement = $this->driver->findElement($sSelector);
// Use json_decode to send enter key to browser.
$oElement->sendKeys(json_decode('"\\uE007"'));
// FIXME: It would be good if we can test for the VL to renew. Now just waiting a second.
sleep(1);
// Find a custom link, and move the mouse over it.
$oCustomLink = $this->driver->findElement(WebDriverBy::xpath('//table[@class="data"]/tbody/tr/td/span[text()="Fokkema et al (2011)"]'));
$this->driver->getMouse()->mouseMove($oCustomLink->getCoordinates());
// Now find the tooltip that should have shown.
$sToolTipLinkText = $this->driver->findElement(WebDriverBy::xpath('//div[@id="tooltip"]/a'))->getText();
$this->assertTrue(strpos($sToolTipLinkText, 'http') === 0 && strpos($sToolTipLinkText, 'pubmed'));
}
/**
* Sub class of RemoteWebDriver. Overloading its findElement method
* to make use of RefreshingWebDriverElement.
*/
public function findElement(WebDriverBy $by)
{
// This method is similar to RemoteWebDriver::findElement() but
// returns an instance of RefreshingWebElement.
$params = array('using' => $by->getMechanism(), 'value' => $by->getValue());
$raw_element = $this->execute(DriverCommand::FIND_ELEMENT, $params);
// Create a RefreshingWebElement and set resources needed to let the
// element refresh in the future.
$element = new RefreshingWebElement($this->getExecuteMethod(), $raw_element['ELEMENT']);
$element->setLocator($by);
$element->setWebDriver($this);
return $element;
}
public function clear()
{
$elements = $this->webDriver->findElements(WebDriverBy::xpath('//tr[@class="filter"]/descendant::input[@type="text"]'));
foreach ($elements as $element) {
$element->clear();
}
}
请发表评论