diff --git a/core/modules/system/tests/modules/test_page_test/src/Controller/TestPageTestController.php b/core/modules/system/tests/modules/test_page_test/src/Controller/TestPageTestController.php index 16369c0faae684367cadd9071233e664d3704225..02ea524b09eecc5c879ec7bde56d9bd400360771 100644 --- a/core/modules/system/tests/modules/test_page_test/src/Controller/TestPageTestController.php +++ b/core/modules/system/tests/modules/test_page_test/src/Controller/TestPageTestController.php @@ -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();.,\\\/-_{}', diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index e4979d376cd493efbb3689702151bed85fc5f22c..eb5ba4bb5e98d3e60b92701d2a6c11c61c2191c0 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -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'); diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index ea88906dc5abebda5a3bee160636bda1a592a9cc..b4a685eafe55c6c003dacd2676f12bc07433cd5e 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -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(); } /**