diff --git a/core/modules/simpletest/src/AssertContentTrait.php b/core/modules/simpletest/src/AssertContentTrait.php index 5a6c8c0..afd4392 100644 --- a/core/modules/simpletest/src/AssertContentTrait.php +++ b/core/modules/simpletest/src/AssertContentTrait.php @@ -300,7 +300,7 @@ protected function getAllOptions(\SimpleXMLElement $element) { protected function assertLink($label, $index = 0, $message = '', $group = 'Other') { // Cast MarkupInterface objects to string. $label = (string) $label; - $links = $this->xpath('//a[normalize-space(text())=:label]', [':label' => $label]); + $links = $this->xpath('//a[normalize-space()=:label]', [':label' => $label]); $message = ($message ? $message : strtr('Link with label %label found.', ['%label' => $label])); return $this->assert(isset($links[$index]), $message, $group); } @@ -327,7 +327,7 @@ protected function assertLink($label, $index = 0, $message = '', $group = 'Other protected function assertNoLink($label, $message = '', $group = 'Other') { // Cast MarkupInterface objects to string. $label = (string) $label; - $links = $this->xpath('//a[normalize-space(text())=:label]', [':label' => $label]); + $links = $this->xpath('//a[normalize-space()=:label]', [':label' => $label]); $message = ($message ? $message : SafeMarkup::format('Link with label %label not found.', ['%label' => $label])); return $this->assert(empty($links), $message, $group); } diff --git a/core/modules/simpletest/src/Tests/BrowserTest.php b/core/modules/simpletest/src/Tests/BrowserTest.php index fdfaff8..cba169f 100644 --- a/core/modules/simpletest/src/Tests/BrowserTest.php +++ b/core/modules/simpletest/src/Tests/BrowserTest.php @@ -23,7 +23,7 @@ class BrowserTest extends WebTestBase { * * @var string[] */ - public static $modules = ['block']; + public static $modules = ['block', 'node']; /** * {@inheritdoc} @@ -86,6 +86,56 @@ public function testXPathEscaping() { } /** + * Tests link recognition when markup is within the link tags. + * Regression test to validate xpaths used by simpletest link helpers. + * + * @see https://www.drupal.org/node/855726 + */ + public function testLinkMatchingXpath() { + // Content to use for testing the functions which act on links: + $test_content = '

Some text and a link with a kitten span in the middle
'; + $test_content .= 'Some more text and a link with emphasized text in the middle
'; + $test_content .= 'Even more text and a link with a bold kitten span

'; + + // Ensure an `article` node type exists. + $this->createContentType(['type' => 'page']); + + // Create Full HTML text format. + $full_html_format = \Drupal\filter\Entity\FilterFormat::create([ + 'format' => 'full_html', + 'name' => 'Full HTML', + ]); + $full_html_format->save(); + + // Create and log in an administrative user having access to the Full HTML + // text format. + $adminUser = $this->drupalCreateUser([ + 'access administration pages', + 'create page content', + $full_html_format->getPermissionName(), + ]); + $this->drupalLogin($adminUser); + + $edit = [ + 'title[0][value]' => 'test links', + 'body[0][value]' => $test_content + ]; + + $this->drupalPostForm("node/add/page", $edit, t('Save')); + $this->drupalGet("node/1"); + $links = [ + "a link with a kitten span in the middle", + "a link with emphasized text in the middle", + "a link with a bold kitten span", + ]; + // The same pattern is used for assertLink() and clickLink(). Verify both. + foreach ($links as $link) { + $this->assertLink($link); + $this->clickLink($link); + } + } + + /** * Tests that cookies set during a request are available for testing. */ public function testCookies() { diff --git a/core/modules/views/src/Tests/SearchIntegrationTest.php b/core/modules/views/src/Tests/SearchIntegrationTest.php index 1b6ab89..5c2ac63 100644 --- a/core/modules/views/src/Tests/SearchIntegrationTest.php +++ b/core/modules/views/src/Tests/SearchIntegrationTest.php @@ -141,7 +141,7 @@ public function testSearchIntegration() { * TRUE if the assertion succeeded, FALSE otherwise. */ protected function assertOneLink($label) { - $links = $this->xpath('//a[normalize-space(text())=:label]', [':label' => $label]); + $links = $this->xpath('//a[normalize-space()=:label]', [':label' => $label]); $message = SafeMarkup::format('Link with label %label found once.', ['%label' => $label]); return $this->assert(isset($links[0]) && !isset($links[1]), $message); } diff --git a/core/modules/views_ui/src/Tests/DefaultViewsTest.php b/core/modules/views_ui/src/Tests/DefaultViewsTest.php index a709d1f..17503e7 100644 --- a/core/modules/views_ui/src/Tests/DefaultViewsTest.php +++ b/core/modules/views_ui/src/Tests/DefaultViewsTest.php @@ -228,7 +228,7 @@ public function testPathDestination() { * failure. Failure also results in a failed assertion. */ public function clickViewsOperationLink($label, $unique_href_part) { - $links = $this->xpath('//a[normalize-space(text())=:label]', [':label' => $label]); + $links = $this->xpath('//a[normalize-space()=:label]', [':label' => $label]); foreach ($links as $link_index => $link) { $position = strpos($link['href'], $unique_href_part); if ($position !== FALSE) {