public function NodeCommentsTest::testCommentCount in Drupal 8
Same name and namespace in other branches
- 9 core/modules/comment/tests/src/Functional/Views/NodeCommentsTest.php \Drupal\Tests\comment\Functional\Views\NodeCommentsTest::testCommentCount()
Test the comment count field.
File
- core/
modules/ comment/ tests/ src/ Functional/ Views/ NodeCommentsTest.php, line 44
Class
- NodeCommentsTest
- Tests comments on nodes.
Namespace
Drupal\Tests\comment\Functional\ViewsCode
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' => t('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);
}