class SearchCommentCountToggleTest
Same name and namespace in other branches
- 11.x core/modules/search/tests/src/Functional/SearchCommentCountToggleTest.php \Drupal\Tests\search\Functional\SearchCommentCountToggleTest
- 10 core/modules/search/tests/src/Functional/SearchCommentCountToggleTest.php \Drupal\Tests\search\Functional\SearchCommentCountToggleTest
- 8.9.x core/modules/search/tests/src/Functional/SearchCommentCountToggleTest.php \Drupal\Tests\search\Functional\SearchCommentCountToggleTest
Tests that comment count display toggles properly on comment status of node.
Issue 537278
- Nodes with comment status set to Open should always how comment counts
- Nodes with comment status set to Closed should show comment counts only when there are comments
- Nodes with comment status set to Hidden should never show comment counts
@group search
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\search\Functional\SearchCommentCountToggleTest uses \Drupal\comment\Tests\CommentTestTrait implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of SearchCommentCountToggleTest
File
-
core/
modules/ search/ tests/ src/ Functional/ SearchCommentCountToggleTest.php, line 21
Namespace
Drupal\Tests\search\FunctionalView source
class SearchCommentCountToggleTest extends BrowserTestBase {
use CommentTestTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'node',
'comment',
'search',
'dblog',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* A user with permission to search and post comments.
*
* @var \Drupal\user\UserInterface
*/
protected $searchingUser;
/**
* Array of nodes available to search.
*
* @var \Drupal\node\NodeInterface[]
*/
protected $searchableNodes;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
// Create searching user.
$this->searchingUser = $this->drupalCreateUser([
'search content',
'access content',
'access comments',
'post comments',
'skip comment approval',
]);
// Log in with sufficient privileges.
$this->drupalLogin($this->searchingUser);
// Add a comment field.
$this->addDefaultCommentField('node', 'article');
// Create initial nodes.
$node_params = [
'type' => 'article',
'body' => [
[
'value' => 'SearchCommentToggleTestCase',
],
],
];
$this->searchableNodes['1 comment'] = $this->drupalCreateNode($node_params);
$this->searchableNodes['0 comments'] = $this->drupalCreateNode($node_params);
// Create a comment array
$edit_comment = [];
$edit_comment['subject[0][value]'] = $this->randomMachineName();
$edit_comment['comment_body[0][value]'] = $this->randomMachineName();
// Post comment to the test node with comment
$this->drupalGet('comment/reply/node/' . $this->searchableNodes['1 comment']
->id() . '/comment');
$this->submitForm($edit_comment, 'Save');
// First update the index. This does the initial processing.
$this->container
->get('plugin.manager.search')
->createInstance('node_search')
->updateIndex();
}
/**
* Verify that comment count display toggles properly on comment status of node.
*/
public function testSearchCommentCountToggle() {
// Search for the nodes by string in the node body.
$edit = [
'keys' => "'SearchCommentToggleTestCase'",
];
$this->drupalGet('search/node');
// Test comment count display for nodes with comment status set to Open
$this->submitForm($edit, 'Search');
$this->assertSession()
->pageTextContains('0 comments');
$this->assertSession()
->pageTextContains('1 comment');
// Test comment count display for nodes with comment status set to Closed
$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');
// Test comment count display for nodes with comment status set to Hidden
$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');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.