diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php index d639a73..fb903f7 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php @@ -262,24 +262,49 @@ function testTranslationRendering() { $this->assertText($values[$langcode]['title'][0]['value']); } + // Need to check from the beginning, including the base_path, in the url + // since the pattern for the default language might be a substring of + // the strings for other languages. + $base_path = base_path(); + // Check the frontpage for 'Read more' links to each translation. // See also assertTaxonomyPage() in NodeAccessBaseTableTest. - $node_href = '/node/' . $node->id(); + $node_href = 'node/' . $node->id(); foreach ($this->langcodes as $langcode) { - $match_found = FALSE; + $num_match_found = 0; if ($langcode == 'en') { // Site default language does not have langcode prefix in the URL. - $expected_href = $node_href; + $expected_href = $base_path . $node_href; } else { - $expected_href = '/' . $langcode . $node_href; + $expected_href = $base_path . $langcode . '/' . $node_href; } - $pattern = '|' . $expected_href . '$|'; + $pattern = '|^' . $expected_href . '$|'; foreach ($this->xpath("//a[text()='Read more']") as $link) { if (preg_match($pattern, (string) $link['href'], $matches) == TRUE) { - $match_found = TRUE; + $num_match_found++; + } + } + $this->assertTrue($num_match_found == 1, 'There is 1 Read more link, ' . $expected_href . ', for the ' . $langcode . ' translation of a node on the frontpage. (Found ' . $num_match_found . '.)'); + } + + // Check the frontpage for 'Add new comment' links that include the + // language. + $comment_form_href = 'node/' . $node->id() . '#comment-form'; + foreach ($this->langcodes as $langcode) { + $num_match_found = 0; + if ($langcode == 'en') { + // Site default language does not have langcode prefix in the URL. + $expected_href = $base_path . $comment_form_href; + } else { + $expected_href = $base_path . $langcode . '/' . $comment_form_href; + } + $pattern = '|^' . $expected_href . '$|'; + foreach ($this->xpath("//a[text()='Add new comment']") as $link) { + if (preg_match($pattern, (string) $link['href'], $matches) == TRUE) { + $num_match_found++; } } - $this->assertTrue($match_found, 'There is a Read more link for the ' . $langcode . ' translation of a node on the frontpage.'); + $this->assertTrue($num_match_found == 1, 'There is 1 Add new comment link, ' . $expected_href . ', for the ' . $langcode . ' translation of a node on the frontpage. (Found ' . $num_match_found . '.)'); } // Test that the node page displays the correct translations.