NodeCommentsTest.php in Drupal 9
File
core/modules/comment/tests/src/Functional/Views/NodeCommentsTest.php
View source
<?php
namespace Drupal\Tests\comment\Functional\Views;
class NodeCommentsTest extends CommentTestBase {
protected static $modules = [
'history',
];
protected $defaultTheme = 'stark';
public static $testViews = [
'test_new_comments',
'test_comment_count',
];
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.');
}
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);
$this
->drupalCreateContentType([
'type' => 'no_comment',
'name' => t('No comment page'),
]);
$this->nodeUserPosted = $this
->drupalCreateNode([
'type' => 'no_comment',
]);
$this
->drupalGet('test-comment-count');
$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);
}
}