diff --git a/core/modules/comment/src/Tests/CommentTestBase.php b/core/modules/comment/src/Tests/CommentTestBase.php index b09d402..40970b8 100644 --- a/core/modules/comment/src/Tests/CommentTestBase.php +++ b/core/modules/comment/src/Tests/CommentTestBase.php @@ -2,6 +2,8 @@ namespace Drupal\comment\Tests; +@trigger_error(__NAMESPACE__ . '\CommentTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use \Drupal\Tests\comment\Functional\CommentTestBase instead. See http://www.drupal.org/node/2908490', E_USER_DEPRECATED); + use Drupal\comment\Entity\CommentType; use Drupal\comment\Entity\Comment; use Drupal\comment\CommentInterface; @@ -12,6 +14,11 @@ /** * Provides setup and helper methods for comment tests. + * + * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. + * Use \Drupal\Tests\comment\Functional\CommentTestBase instead. + * + * @see https://www.drupal.org/node/2908490 */ abstract class CommentTestBase extends WebTestBase { diff --git a/core/modules/comment/src/Tests/Views/CommentTestBase.php b/core/modules/comment/src/Tests/Views/CommentTestBase.php index d7bec04..3d10858 100644 --- a/core/modules/comment/src/Tests/Views/CommentTestBase.php +++ b/core/modules/comment/src/Tests/Views/CommentTestBase.php @@ -2,13 +2,20 @@ namespace Drupal\comment\Tests\Views; +@trigger_error(__NAMESPACE__ . '\CommentTestBase is deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. Use \Drupal\Tests\comment\Functional\Views\CommentTestBase instead. See http://www.drupal.org/node/2908490', E_USER_DEPRECATED); + use Drupal\comment\Tests\CommentTestTrait; use Drupal\views\Tests\ViewTestBase; use Drupal\views\Tests\ViewTestData; use Drupal\comment\Entity\Comment; /** - * Tests the argument_comment_user_uid handler. + * Provides setup and helper methods for comment views tests. + * + * @deprecated in Drupal 8.4.0 and will be removed before Drupal 9.0.0. + * Use \Drupal\Tests\comment\Functional\Views\CommentTestBase instead. + * + * @see https://www.drupal.org/node/2908490 */ abstract class CommentTestBase extends ViewTestBase { diff --git a/core/modules/comment/src/Tests/CommentActionsTest.php b/core/modules/comment/tests/src/Functional/CommentActionsTest.php similarity index 97% rename from core/modules/comment/src/Tests/CommentActionsTest.php rename to core/modules/comment/tests/src/Functional/CommentActionsTest.php index 56d34e4..79786fc 100644 --- a/core/modules/comment/src/Tests/CommentActionsTest.php +++ b/core/modules/comment/tests/src/Functional/CommentActionsTest.php @@ -1,6 +1,6 @@ drupalPostForm($this->node->urlInfo(), $edit, t('Preview')); // Cannot use assertRaw here since both title and body are in the form. - $preview = (string) $this->cssSelect('.preview')[0]->asXML(); + $preview = (string) $this->cssSelect('.preview')[0]->getHtml(); $this->assertTrue(strpos($preview, $title) !== FALSE, 'Anonymous user can preview comment title.'); $this->assertTrue(strpos($preview, $body) !== FALSE, 'Anonymous user can preview comment body.'); @@ -56,7 +56,7 @@ public function testAnonymous() { $edit['comment_body[0][value]'] = $body; $this->drupalPostForm($this->node->urlInfo(), $edit, t('Preview')); // Cannot use assertRaw here since both title and body are in the form. - $preview = (string) $this->cssSelect('.preview')[0]->asXML(); + $preview = (string) $this->cssSelect('.preview')[0]->getHtml(); $this->assertTrue(strpos($preview, $title) !== FALSE, 'Anonymous user can preview comment title.'); $this->assertTrue(strpos($preview, $body) !== FALSE, 'Anonymous user can preview comment body.'); user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['skip comment approval']); diff --git a/core/modules/comment/src/Tests/CommentBlockTest.php b/core/modules/comment/tests/src/Functional/CommentBlockTest.php similarity index 98% rename from core/modules/comment/src/Tests/CommentBlockTest.php rename to core/modules/comment/tests/src/Functional/CommentBlockTest.php index 37cc5de..db7d1bd 100644 --- a/core/modules/comment/src/Tests/CommentBlockTest.php +++ b/core/modules/comment/tests/src/Functional/CommentBlockTest.php @@ -1,6 +1,6 @@ drupalGet($this->node->urlInfo()); $element = $this->cssSelect('article.js-comment > div'); // Get last child element. - $element = end($element[0]); - $this->assertIdentical($element[0]->getName(), 'div', 'Last element is comment body.'); + $element = end($element); + $this->assertIdentical($element->getTagName(), 'div', 'Last element is comment body.'); // Change weight to make links go after comment body. entity_get_display('comment', 'comment', 'default') @@ -118,8 +118,8 @@ public function testCommentLinks() { $this->drupalGet($this->node->urlInfo()); $element = $this->cssSelect('article.js-comment > div'); // Get last child element. - $element = end($element[0]); - $this->assertIdentical($element[0]->getName(), 'ul', 'Last element is comment links.'); + $element = end($element); + $this->assertNotEmpty($element->find('css', 'ul.links'), 'Last element is comment links.'); // Make sure we can hide node links. entity_get_display('node', $this->node->bundle(), 'default') diff --git a/core/modules/comment/src/Tests/CommentNodeAccessTest.php b/core/modules/comment/tests/src/Functional/CommentNodeAccessTest.php similarity index 98% rename from core/modules/comment/src/Tests/CommentNodeAccessTest.php rename to core/modules/comment/tests/src/Functional/CommentNodeAccessTest.php index ffbffa1..6842dc1 100644 --- a/core/modules/comment/src/Tests/CommentNodeAccessTest.php +++ b/core/modules/comment/tests/src/Functional/CommentNodeAccessTest.php @@ -1,6 +1,6 @@ drupalGet('comment/reply/entity_test/' . $this->entity->id() . '/comment'); $xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a'; - $this->assertEqual(current($this->xpath($xpath)), $this->entity->label(), 'Last breadcrumb item is equal to node title on comment reply page.'); + $this->assertEqual(current($this->xpath($xpath))->getText(), $this->entity->label(), 'Last breadcrumb item is equal to node title on comment reply page.'); // Post a comment. /** @var \Drupal\comment\CommentInterface $comment1 */ @@ -283,17 +284,17 @@ public function testCommentFunctionality() { // Test breadcrumb on comment reply page. $this->drupalGet('comment/reply/entity_test/' . $this->entity->id() . '/comment/' . $comment1->id()); $xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a'; - $this->assertEqual(current($this->xpath($xpath)), $comment1->getSubject(), 'Last breadcrumb item is equal to comment title on comment reply page.'); + $this->assertEqual(current($this->xpath($xpath))->getText(), $comment1->getSubject(), 'Last breadcrumb item is equal to comment title on comment reply page.'); // Test breadcrumb on comment edit page. $this->drupalGet('comment/' . $comment1->id() . '/edit'); $xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a'; - $this->assertEqual(current($this->xpath($xpath)), $comment1->getSubject(), 'Last breadcrumb item is equal to comment subject on edit page.'); + $this->assertEqual(current($this->xpath($xpath))->getText(), $comment1->getSubject(), 'Last breadcrumb item is equal to comment subject on edit page.'); // Test breadcrumb on comment delete page. $this->drupalGet('comment/' . $comment1->id() . '/delete'); $xpath = '//nav[@class="breadcrumb"]/ol/li[last()]/a'; - $this->assertEqual(current($this->xpath($xpath)), $comment1->getSubject(), 'Last breadcrumb item is equal to comment subject on delete confirm page.'); + $this->assertEqual(current($this->xpath($xpath))->getText(), $comment1->getSubject(), 'Last breadcrumb item is equal to comment subject on delete confirm page.'); // Unpublish the comment. $this->performCommentOperation($comment1, 'unpublish'); diff --git a/core/modules/comment/src/Tests/CommentPreviewTest.php b/core/modules/comment/tests/src/Functional/CommentPreviewTest.php similarity index 92% rename from core/modules/comment/src/Tests/CommentPreviewTest.php rename to core/modules/comment/tests/src/Functional/CommentPreviewTest.php index 1b07fe6..89ac668 100644 --- a/core/modules/comment/src/Tests/CommentPreviewTest.php +++ b/core/modules/comment/tests/src/Functional/CommentPreviewTest.php @@ -1,11 +1,12 @@ assertFieldByName('comment_body[0][value]', $edit['comment_body[0][value]'], 'Comment field displayed.'); // Store the content of this page. - $content = $this->getRawContent(); $this->drupalPostForm(NULL, [], 'Save'); $this->assertText('Your comment has been posted.'); $elements = $this->xpath('//section[contains(@class, "comment-wrapper")]/article'); $this->assertEqual(1, count($elements)); - // Reset the content of the page to simulate the browser's back button, and - // re-submit the form. - $this->setRawContent($content); - $this->drupalPostForm(NULL, [], 'Save'); + // Go back and re-submit the form. + $this->getSession()->getDriver()->back(); $this->assertText('Your comment has been posted.'); $elements = $this->xpath('//section[contains(@class, "comment-wrapper")]/article'); $this->assertEqual(2, count($elements)); @@ -173,11 +175,11 @@ public function testCommentEditPreviewSave() { // Submit the form using the displayed values. $displayed = []; - $displayed['subject[0][value]'] = (string) current($this->xpath("//input[@id='edit-subject-0-value']/@value")); - $displayed['comment_body[0][value]'] = (string) current($this->xpath("//textarea[@id='edit-comment-body-0-value']")); - $displayed['uid'] = (string) current($this->xpath("//input[@id='edit-uid']/@value")); - $displayed['date[date]'] = (string) current($this->xpath("//input[@id='edit-date-date']/@value")); - $displayed['date[time]'] = (string) current($this->xpath("//input[@id='edit-date-time']/@value")); + $displayed['subject[0][value]'] = current($this->xpath("//input[@id='edit-subject-0-value']"))->getValue(); + $displayed['comment_body[0][value]'] = current($this->xpath("//textarea[@id='edit-comment-body-0-value']"))->getValue(); + $displayed['uid'] = current($this->xpath("//input[@id='edit-uid']"))->getValue(); + $displayed['date[date]'] = current($this->xpath("//input[@id='edit-date-date']"))->getValue(); + $displayed['date[time]'] = current($this->xpath("//input[@id='edit-date-time']"))->getValue(); $this->drupalPostForm('comment/' . $comment->id() . '/edit', $displayed, t('Save')); // Check that the saved comment is still correct. diff --git a/core/modules/comment/src/Tests/CommentRssTest.php b/core/modules/comment/tests/src/Functional/CommentRssTest.php similarity index 97% rename from core/modules/comment/src/Tests/CommentRssTest.php rename to core/modules/comment/tests/src/Functional/CommentRssTest.php index 35cad71..60708bd 100644 --- a/core/modules/comment/src/Tests/CommentRssTest.php +++ b/core/modules/comment/tests/src/Functional/CommentRssTest.php @@ -1,6 +1,6 @@ xpath('div/h3/a'); - if (empty($comment_title) || ((string) $comment_title[0]) !== $comment->getSubject()) { + $comment_title = $comment_element[0]->find('xpath', 'div/h3/a'); + if (empty($comment_title) || $comment_title->getText() !== $comment->getSubject()) { return FALSE; } - $comment_body = $comment_element[0]->xpath('div/div/p'); - if (empty($comment_body) || ((string) $comment_body[0]) !== $comment->comment_body->value) { + $comment_body = $comment_element[0]->find('xpath', 'div/div/p'); + if (empty($comment_body) || $comment_body->getText() !== $comment->comment_body->value) { return FALSE; } diff --git a/core/modules/comment/src/Tests/CommentThreadingTest.php b/core/modules/comment/tests/src/Functional/CommentThreadingTest.php similarity index 99% rename from core/modules/comment/src/Tests/CommentThreadingTest.php rename to core/modules/comment/tests/src/Functional/CommentThreadingTest.php index 8f412b2..cff22ba 100644 --- a/core/modules/comment/src/Tests/CommentThreadingTest.php +++ b/core/modules/comment/tests/src/Functional/CommentThreadingTest.php @@ -1,6 +1,6 @@ assertPattern('|]*>]*>' . $subject_text . '|', 'Comment title is rendered in h3 when title populated.'); // Tests that the comment's title link is the permalink of the comment. $comment_permalink = $this->cssSelect('.permalink'); - $comment_permalink = (string) $comment_permalink[0]['href']; + $comment_permalink = $comment_permalink[0]->getAttribute('href'); // Tests that the comment's title link contains the url fragment. $this->assertTrue(strpos($comment_permalink, '#comment-' . $comment1->id()), "The comment's title link contains the url fragment."); $this->assertEqual($comment1->permalink()->toString(), $comment_permalink, "The comment's title has the correct link."); diff --git a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php b/core/modules/comment/tests/src/Functional/CommentTokenReplaceTest.php similarity index 99% rename from core/modules/comment/src/Tests/CommentTokenReplaceTest.php rename to core/modules/comment/tests/src/Functional/CommentTokenReplaceTest.php index 6caea17..a7fe6b5 100644 --- a/core/modules/comment/src/Tests/CommentTokenReplaceTest.php +++ b/core/modules/comment/tests/src/Functional/CommentTokenReplaceTest.php @@ -1,6 +1,6 @@ postComment($this->node, $this->randomMachineName(), $this->randomMachineName(), TRUE); $this->drupalGet('admin/content/comment'); $this->assertText($this->adminUser->label()); - $this->drupalGet($node_comment->toUrl('edit-form')->toString()); + $this->drupalGet($node_comment->toUrl('edit-form')); $edit = [ 'comment_body[0][value]' => $this->randomMachineName(), ]; diff --git a/core/modules/comment/src/Tests/Views/CommentFieldFilterTest.php b/core/modules/comment/tests/src/Functional/Views/CommentFieldFilterTest.php similarity index 96% rename from core/modules/comment/src/Tests/Views/CommentFieldFilterTest.php rename to core/modules/comment/tests/src/Functional/Views/CommentFieldFilterTest.php index 48f7d6d..dabacc3 100644 --- a/core/modules/comment/src/Tests/Views/CommentFieldFilterTest.php +++ b/core/modules/comment/tests/src/Functional/Views/CommentFieldFilterTest.php @@ -1,6 +1,6 @@ drupalLogin($this->drupalCreateUser(['access comments'])); // Add two new languages. diff --git a/core/modules/comment/src/Tests/Views/CommentFieldNameTest.php b/core/modules/comment/tests/src/Functional/Views/CommentFieldNameTest.php similarity index 94% rename from core/modules/comment/src/Tests/Views/CommentFieldNameTest.php rename to core/modules/comment/tests/src/Functional/Views/CommentFieldNameTest.php index 870a4f4..a5e25be 100644 --- a/core/modules/comment/src/Tests/Views/CommentFieldNameTest.php +++ b/core/modules/comment/tests/src/Functional/Views/CommentFieldNameTest.php @@ -1,6 +1,6 @@ addDefaultCommentField('node', 'page', $this->fieldName); $this->customComment = Comment::create([ 'entity_id' => $this->nodeUserCommented->id(), diff --git a/core/modules/comment/src/Tests/Views/CommentOperationsTest.php b/core/modules/comment/tests/src/Functional/Views/CommentOperationsTest.php similarity index 94% rename from core/modules/comment/src/Tests/Views/CommentOperationsTest.php rename to core/modules/comment/tests/src/Functional/Views/CommentOperationsTest.php index 89dc364..4bef37e 100644 --- a/core/modules/comment/src/Tests/Views/CommentOperationsTest.php +++ b/core/modules/comment/tests/src/Functional/Views/CommentOperationsTest.php @@ -1,6 +1,6 @@ 0, @@ -51,7 +51,7 @@ protected function setUp() { * Test comment row. */ public function testCommentRestExport() { - $this->drupalGetWithFormat(sprintf('node/%d/comments', $this->nodeUserCommented->id()), 'hal_json'); + $this->drupalGet(sprintf('node/%d/comments', $this->nodeUserCommented->id()), ['query' => ['_format' => 'hal_json']]); $this->assertResponse(200); $contents = Json::decode($this->getRawContent()); $this->assertEqual($contents[0]['subject'], 'How much wood would a woodchuck chuck'); diff --git a/core/modules/comment/src/Tests/Views/CommentRowTest.php b/core/modules/comment/tests/src/Functional/Views/CommentRowTest.php similarity index 91% rename from core/modules/comment/src/Tests/Views/CommentRowTest.php rename to core/modules/comment/tests/src/Functional/Views/CommentRowTest.php index d73811e..7cf3ef3 100644 --- a/core/modules/comment/src/Tests/Views/CommentRowTest.php +++ b/core/modules/comment/tests/src/Functional/Views/CommentRowTest.php @@ -1,6 +1,6 @@ drupalCreateContentType(); diff --git a/core/modules/comment/src/Tests/Views/FilterUserUIDTest.php b/core/modules/comment/tests/src/Functional/Views/FilterUserUIDTest.php similarity index 96% rename from core/modules/comment/src/Tests/Views/FilterUserUIDTest.php rename to core/modules/comment/tests/src/Functional/Views/FilterUserUIDTest.php index 442a0e7..719c597 100644 --- a/core/modules/comment/src/Tests/Views/FilterUserUIDTest.php +++ b/core/modules/comment/tests/src/Functional/Views/FilterUserUIDTest.php @@ -1,6 +1,6 @@ drupalGet('test-comment-rss'); - $result = $this->xpath('//item'); + // Because the response is XML we can't use the page which depends on an + // HTML tag being present. + $result = $this->getSession()->getDriver()->find('//item'); $this->assertEqual(count($result), 1, 'Just one comment was found in the rss output.'); - $this->assertEqual($result[0]->pubdate, gmdate('r', $this->comment->getCreatedTime()), 'The right pubDate appears in the rss output.'); + $this->assertEqual($result[0]->find('xpath', '//pubDate')->getHtml(), gmdate('r', $this->comment->getCreatedTime()), 'The right pubDate appears in the rss output.'); } } diff --git a/core/modules/comment/src/Tests/Views/WizardTest.php b/core/modules/comment/tests/src/Functional/Views/WizardTest.php similarity index 92% rename from core/modules/comment/src/Tests/Views/WizardTest.php rename to core/modules/comment/tests/src/Functional/Views/WizardTest.php index a7f14c8..62fada9 100644 --- a/core/modules/comment/src/Tests/Views/WizardTest.php +++ b/core/modules/comment/tests/src/Functional/Views/WizardTest.php @@ -1,10 +1,10 @@ drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]); // Add comment field to page node type. $this->addDefaultCommentField('node', 'page'); @@ -63,7 +63,7 @@ public function testCommentWizard() { foreach ($fields as $field) { $items = $this->getAllOptions($field); foreach ($items as $item) { - $options[] = $item->attributes()->value; + $options[] = $item->getValue(); } } $expected_options = ['entity:comment', 'fields']; diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php index c755ac4..f8b1756 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationUITestBase.php @@ -227,10 +227,10 @@ protected function doTestTranslationOverview() { $language = new Language(['id' => $langcode]); $view_url = $entity->url('canonical', ['language' => $language]); $elements = $this->xpath('//table//a[@href=:href]', [':href' => $view_url]); - $this->assertEqual($elements[0]->getText(), $entity->getTranslation($langcode)->label(), new FormattableMarkup('Label correctly shown for %language translation.', ['%language' => $langcode])); + $this->assertEqual($elements[0]->getHtml(), $entity->getTranslation($langcode)->label(), new FormattableMarkup('Label correctly shown for %language translation.', ['%language' => $langcode])); $edit_path = $entity->url('edit-form', ['language' => $language]); $elements = $this->xpath('//table//ul[@class="dropbutton"]/li/a[@href=:href]', [':href' => $edit_path]); - $this->assertEqual($elements[0]->getText(), t('Edit'), new FormattableMarkup('Edit link correct for %language translation.', ['%language' => $langcode])); + $this->assertEqual($elements[0]->getHtml(), t('Edit'), new FormattableMarkup('Edit link correct for %language translation.', ['%language' => $langcode])); } } }