Unverified Commit 73bba855 authored by larowlan's avatar larowlan

Issue #2866513 by michielnugter, jonathan1055, mpdonadio, Jo Fitzgerald,...

Issue #2866513 by michielnugter, jonathan1055, mpdonadio, Jo Fitzgerald, Lendude, dawehner, Wim Leers: Convert web tests to browser tests for comment module
parent 5c503f4a
......@@ -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 {
......
......@@ -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 {
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\Entity\Comment;
use Drupal\system\Entity\Action;
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Html;
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\user\RoleInterface;
......@@ -43,7 +43,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.');
......@@ -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']);
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\user\RoleInterface;
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\CommentInterface;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\node\Entity\Node;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\comment\Entity\Comment;
/**
......@@ -12,7 +13,7 @@
*
* @group comment
*/
class CommentBookTest extends WebTestBase {
class CommentBookTest extends BrowserTestBase {
use CommentTestTrait;
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\Core\Language\LanguageInterface;
use Drupal\comment\CommentInterface;
use Drupal\user\RoleInterface;
use Drupal\comment\Entity\Comment;
use Drupal\Tests\Traits\Core\GeneratePermutationsTrait;
/**
* Tests CSS classes on comments.
......@@ -14,6 +15,8 @@
*/
class CommentCSSTest extends CommentTestBase {
use GeneratePermutationsTrait;
protected function setUp() {
parent::setUp();
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\field\Entity\FieldStorageConfig;
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\CommentManagerInterface;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Tests for comment language.
*
* @group comment
*/
class CommentLanguageTest extends WebTestBase {
class CommentLanguageTest extends BrowserTestBase {
use CommentTestTrait;
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
/**
* Tests comment links altering.
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Language\LanguageInterface;
......@@ -108,8 +108,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(), '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')
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\CommentManagerInterface;
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\Entity\Comment;
use Drupal\field\Entity\FieldConfig;
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\CommentInterface;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Entity\CommentType;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field_ui\Tests\FieldUiTestTrait;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\user\RoleInterface;
......@@ -19,7 +20,7 @@
*
* @group comment
*/
class CommentNonNodeTest extends WebTestBase {
class CommentNonNodeTest extends BrowserTestBase {
use FieldUiTestTrait;
use CommentTestTrait;
......@@ -273,7 +274,7 @@ public function testCommentFunctionality() {
// Test breadcrumb on comment add page.
$this->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');
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\CommentManagerInterface;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\comment\Entity\Comment;
use Drupal\Tests\TestFileCreationTrait;
/**
* Tests comment preview.
......@@ -14,6 +15,10 @@
*/
class CommentPreviewTest extends CommentTestBase {
use TestFileCreationTrait {
getTestFiles as drupalGetTestFiles;
}
/**
* The profile to install as a basis for testing.
*
......@@ -105,16 +110,13 @@ public function testCommentPreviewDuplicateSubmission() {
$this->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.
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Core\Cache\Cache;
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\CommentManagerInterface;
use Drupal\comment\Entity\Comment;
......
This diff is collapsed.
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\CommentManagerInterface;
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
/**
* Tests to ensure that appropriate and accessible markup is created for comment
......@@ -73,7 +73,7 @@ public function testCommentPopulatedTitles() {
$this->assertPattern('|<h3[^>]*><a[^>]*>' . $subject_text . '</a></h3>|', '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.");
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Component\Render\FormattableMarkup;
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\content_translation\Tests\ContentTranslationUITestBase;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
/**
* Tests the Comment Translation UI.
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Entity\CommentType;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
......
<?php
namespace Drupal\comment\Tests;
namespace Drupal\Tests\comment\Functional;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Core\Extension\ModuleUninstallValidatorException;
use Drupal\simpletest\WebTestBase;
use Drupal\Tests\BrowserTestBase;
/**
* Tests comment module uninstallation.
*
* @group comment
*/
class CommentUninstallTest extends WebTestBase {
class CommentUninstallTest extends BrowserTestBase {
use CommentTestTrait;
......
<?php
namespace Drupal\comment\Tests\Views;
namespace Drupal\Tests\comment\Functional\Views;
use Drupal\comment\Entity\Comment;
use Drupal\user\Entity\User;
......
<?php
namespace Drupal\comment\Tests\Views;
namespace Drupal\Tests\comment\Functional\Views;
use Drupal\block_content\Entity\BlockContent;
use Drupal\block_content\Entity\BlockContentType;
use Drupal\comment\Entity\Comment;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\comment\Tests\CommentTestBase as CommentWebTestBase;
use Drupal\Tests\comment\Functional\CommentTestBase as CommentBrowserTestBase;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\Unicode;
use Drupal\user\RoleInterface;
......@@ -18,7 +18,7 @@
*
* @group comment
*/
class CommentAdminTest extends CommentWebTestBase {
class CommentAdminTest extends CommentBrowserTestBase {
/**
* {@inheritdoc}
......
<?php
namespace Drupal\comment\Tests\Views;
namespace Drupal\Tests\comment\Functional\Views;
use Drupal\comment\Tests\CommentTestBase as CommentWebTestBase;
use Drupal\Tests\comment\Functional\CommentTestBase as CommentBrowserTestBase;
/**
* Tests comment edit functionality.
*
* @group comment
*/
class CommentEditTest extends CommentWebTestBase {
class CommentEditTest extends CommentBrowserTestBase {
/**
* {@inheritdoc}
......@@ -25,7 +25,7 @@ public function testCommentEdit() {
$node_comment = $this->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(),
];
......
<?php
namespace Drupal\comment\Tests\Views;
namespace Drupal\Tests\comment\Functional\Views;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\comment\Entity\Comment;
......@@ -31,8 +31,8 @@ class CommentFieldFilterTest extends CommentTestBase {
*/
public $commentTitles = [];
public function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->drupalLogin($this->drupalCreateUser(['access comments']));
// Add two new languages.
......
<?php
namespace Drupal\comment\Tests\Views;
namespace Drupal\Tests\comment\Functional\Views;
use Drupal\comment\Entity\Comment;
use Drupal\Core\Render\RenderContext;
......@@ -39,8 +39,8 @@ class CommentFieldNameTest extends CommentTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->addDefaultCommentField('node', 'page', $this->fieldName);
$this->customComment = Comment::create([
'entity_id' => $this->nodeUserCommented->id(),
......
<?php
namespace Drupal\comment\Tests\Views;
namespace Drupal\Tests\comment\Functional\Views;
/**
* Tests comment operations.
......
<?php
namespace Drupal\comment\Tests\Views;
namespace Drupal\Tests\comment\Functional\Views;
use Drupal\Component\Serialization\Json;
use Drupal\comment\Entity\Comment;
......@@ -24,8 +24,8 @@ class CommentRestExportTest extends CommentTestBase {
*/
public static $modules = ['node', 'comment', 'comment_test_views', 'rest', 'hal'];
protected function setUp() {
parent::setUp();
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
// Add another anonymous comment.
$comment = [
'uid' => 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');
......
<?php
namespace Drupal\comment\Tests\Views;
namespace Drupal\Tests\comment\Functional\Views;
/**
* Tests the comment row plugin.
......
<?php
namespace Drupal\Tests\comment\Functional\Views;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Tests\views\Functional\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
use Drupal\comment\Entity\Comment;
/**
* Provides setup and helper methods for comment views tests.
*/
abstract class CommentTestBase extends ViewTestBase {
use CommentTestTrait;
/**
* Modules to install.
*
* @var array
*/
public static $modules = ['node', 'comment', 'comment_test_views'];
/**
* A normal user with permission to post comments (without approval).
*
* @var \Drupal\user\UserInterface
*/
protected $account;
/**
* A second normal user that will author a node for $account to comment on.
*
* @var \Drupal\user\UserInterface
*/
protected $account2;
/**
* Stores a node posted by the user created as $account.
*
* @var \Drupal\node\NodeInterface
*/
protected $nodeUserPosted;
/**
* Stores a node posted by the user created as $account2.
*
* @var \Drupal\node\NodeInterface
*/
protected $nodeUserCommented;
/**
* Stores a comment used by the tests.
*
* @var \Drupal\comment\Entity\Comment
*/
protected $comment;
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
ViewTestData::createTestViews(get_class($this), ['comment_test_views']);
// Add two users, create a node with the user1 as author and another node
// with user2 as author. For the second node add a comment from user1.
$this->account = $this->drupalCreateUser(['skip comment approval']);
$this->account2 = $this->drupalCreateUser();
$this->drupalLogin($this->account);
$this->drupalCreateContentType(['type' => 'page', 'name' => t('Basic page')]);
$this->addDefaultCommentField('node', 'page');
$this->nodeUserPosted = $this->drupalCreateNode();
$this->nodeUserCommented = $this->drupalCreateNode(['uid' => $this->account2->id()]);
$comment = [
'uid' => $this->loggedInUser->id(),
'entity_id' => $this->nodeUserCommented->id(),
'entity_type' => 'node',
'field_name' => 'comment',
'subject' => 'How much wood would a woodchuck chuck',
'cid' => '',
'pid' => '',
'mail' => 'someone@example.com',
];
$this->comment = Comment::create($comment);
$this->comment->save();
}