View source
<?php
namespace Drupal\Tests\search\Functional;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
use Drupal\comment\Tests\CommentTestTrait;
use Drupal\Tests\BrowserTestBase;
class SearchCommentCountToggleTest extends BrowserTestBase {
use CommentTestTrait;
protected static $modules = [
'node',
'comment',
'search',
'dblog',
];
protected $defaultTheme = 'stark';
protected $searchingUser;
protected $searchableNodes;
protected function setUp() : void {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$this->searchingUser = $this
->drupalCreateUser([
'search content',
'access content',
'access comments',
'post comments',
'skip comment approval',
]);
$this
->drupalLogin($this->searchingUser);
$this
->addDefaultCommentField('node', 'article');
$node_params = [
'type' => 'article',
'body' => [
[
'value' => 'SearchCommentToggleTestCase',
],
],
];
$this->searchableNodes['1 comment'] = $this
->drupalCreateNode($node_params);
$this->searchableNodes['0 comments'] = $this
->drupalCreateNode($node_params);
$edit_comment = [];
$edit_comment['subject[0][value]'] = $this
->randomMachineName();
$edit_comment['comment_body[0][value]'] = $this
->randomMachineName();
$this
->drupalGet('comment/reply/node/' . $this->searchableNodes['1 comment']
->id() . '/comment');
$this
->submitForm($edit_comment, 'Save');
$this->container
->get('plugin.manager.search')
->createInstance('node_search')
->updateIndex();
}
public function testSearchCommentCountToggle() {
$edit = [
'keys' => "'SearchCommentToggleTestCase'",
];
$this
->drupalGet('search/node');
$this
->submitForm($edit, 'Search');
$this
->assertSession()
->pageTextContains('0 comments');
$this
->assertSession()
->pageTextContains('1 comment');
$this->searchableNodes['0 comments']
->set('comment', CommentItemInterface::CLOSED);
$this->searchableNodes['0 comments']
->save();
$this->searchableNodes['1 comment']
->set('comment', CommentItemInterface::CLOSED);
$this->searchableNodes['1 comment']
->save();
$this
->submitForm($edit, 'Search');
$this
->assertSession()
->pageTextNotContains('0 comments');
$this
->assertSession()
->pageTextContains('1 comment');
$this->searchableNodes['0 comments']
->set('comment', CommentItemInterface::HIDDEN);
$this->searchableNodes['0 comments']
->save();
$this->searchableNodes['1 comment']
->set('comment', CommentItemInterface::HIDDEN);
$this->searchableNodes['1 comment']
->save();
$this
->submitForm($edit, 'Search');
$this
->assertSession()
->pageTextNotContains('0 comments');
$this
->assertSession()
->pageTextNotContains('1 comment');
}
}