class NodeCommentsTest
Same name and namespace in other branches
- 11.x core/modules/comment/tests/src/Functional/Views/NodeCommentsTest.php \Drupal\Tests\comment\Functional\Views\NodeCommentsTest
Tests comments on nodes.
@group comment
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\comment\Functional\Views\CommentTestBase uses \Drupal\comment\Tests\CommentTestTrait implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\comment\Functional\Views\NodeCommentsTest implements \Drupal\Tests\comment\Functional\Views\CommentTestBase
- class \Drupal\Tests\comment\Functional\Views\CommentTestBase uses \Drupal\comment\Tests\CommentTestTrait implements \Drupal\Tests\views\Functional\ViewTestBase
- class \Drupal\Tests\views\Functional\ViewTestBase uses \Drupal\views\Tests\ViewResultAssertionTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of NodeCommentsTest
File
-
core/
modules/ comment/ tests/ src/ Functional/ Views/ NodeCommentsTest.php, line 10
Namespace
Drupal\Tests\comment\Functional\ViewsView source
class NodeCommentsTest extends CommentTestBase {
/**
* Modules to install.
*
* @var array
*/
protected static $modules = [
'history',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = [
'test_new_comments',
'test_comment_count',
];
/**
* Tests the new comments field plugin.
*/
public function testNewComments() {
$this->drupalGet('test-new-comments');
$this->assertSession()
->statusCodeEquals(200);
$new_comments = $this->cssSelect(".views-field-new-comments a:contains('1')");
$this->assertCount(1, $new_comments, 'Found the number of new comments for a certain node.');
}
/**
* Test the comment count field.
*/
public function testCommentCount() {
$this->drupalGet('test-comment-count');
$this->assertSession()
->statusCodeEquals(200);
$this->assertCount(2, $this->cssSelect('.views-row'));
$comment_count_with_comment = $this->cssSelect(".views-field-comment-count span:contains('1')");
$this->assertCount(1, $comment_count_with_comment);
$comment_count_without_comment = $this->cssSelect(".views-field-comment-count span:contains('0')");
$this->assertCount(1, $comment_count_without_comment);
// Create a content type with no comment field, and add a node.
$this->drupalCreateContentType([
'type' => 'no_comment',
'name' => 'No comment page',
]);
$this->nodeUserPosted = $this->drupalCreateNode([
'type' => 'no_comment',
]);
$this->drupalGet('test-comment-count');
// Test that the node with no comment field is also shown.
$this->assertSession()
->statusCodeEquals(200);
$this->assertCount(3, $this->cssSelect('.views-row'));
$comment_count_with_comment = $this->cssSelect(".views-field-comment-count span:contains('1')");
$this->assertCount(1, $comment_count_with_comment);
$comment_count_without_comment = $this->cssSelect(".views-field-comment-count span:contains('0')");
$this->assertCount(2, $comment_count_without_comment);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.