Commit fec70c8f authored by catch's avatar catch

Issue #2797943 by jmuzz, claudiu.cristea, dawehner: Add support for...

Issue #2797943 by jmuzz, claudiu.cristea, dawehner: Add support for clickLink()'s second argument to BrowserTestBase
parent 22e8b2eb
......@@ -11,9 +11,10 @@ class TestPageTestController {
* Returns a test page and sets the title.
*/
public function testPage() {
$link_text = t('Visually identical test links');
return [
'#title' => t('Test page'),
'#markup' => t('Test page text.'),
'#markup' => t('Test page text.') . "<a href=\"/user/login\">$link_text</a><a href=\"/user/register\">$link_text</a>",
'#attached' => [
'drupalSettings' => [
'test-setting' => 'azAZ09();.,\\\/-_{}',
......
......@@ -81,6 +81,21 @@ public function testForm() {
$this->assertSame('green', $value);
}
/**
* Tests clickLink() functionality.
*/
public function testClickLink() {
$this->drupalGet('test-page');
$this->clickLink('Visually identical test links');
$this->assertContains('user/login', $this->getSession()->getCurrentUrl());
$this->drupalGet('test-page');
$this->clickLink('Visually identical test links', 0);
$this->assertContains('user/login', $this->getSession()->getCurrentUrl());
$this->drupalGet('test-page');
$this->clickLink('Visually identical test links', 1);
$this->assertContains('user/register', $this->getSession()->getCurrentUrl());
}
public function testError() {
$this->setExpectedException('\Exception', 'User notice: foo');
$this->drupalGet('test-error');
......
......@@ -1615,10 +1615,14 @@ protected function cssSelect($selector) {
*
* @param string|\Drupal\Component\Render\MarkupInterface $label
* Text between the anchor tags.
* @param int $index
* (optional) The index number for cases where multiple links have the same
* text. Defaults to 0.
*/
protected function clickLink($label) {
protected function clickLink($label, $index = 0) {
$label = (string) $label;
$this->getSession()->getPage()->clickLink($label);
$links = $this->getSession()->getPage()->findAll('named', ['link', $label]);
$links[$index]->click();
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment