function SearchCommentTest::testAddNewComment
Same name in other branches
- 9 core/modules/search/tests/src/Functional/SearchCommentTest.php \Drupal\Tests\search\Functional\SearchCommentTest::testAddNewComment()
- 8.9.x core/modules/search/tests/src/Functional/SearchCommentTest.php \Drupal\Tests\search\Functional\SearchCommentTest::testAddNewComment()
- 10 core/modules/search/tests/src/Functional/SearchCommentTest.php \Drupal\Tests\search\Functional\SearchCommentTest::testAddNewComment()
Verify that 'add new comment' does not appear in search results or index.
File
-
core/
modules/ search/ tests/ src/ Functional/ SearchCommentTest.php, line 347
Class
- SearchCommentTest
- Tests integration searching comments.
Namespace
Drupal\Tests\search\FunctionalCode
public function testAddNewComment() : void {
// Create a node with a short body.
$settings = [
'type' => 'article',
'title' => 'short title',
'body' => [
[
'value' => 'short body text',
],
],
];
$user = $this->drupalCreateUser([
'search content',
'create article content',
'access content',
'post comments',
'access comments',
]);
$this->drupalLogin($user);
$node = $this->drupalCreateNode($settings);
// Verify that if you view the node on its own page, 'add new comment'
// is there.
$this->drupalGet('node/' . $node->id());
$this->assertSession()
->pageTextContains('Add new comment');
// Run cron to index this page.
$this->drupalLogout();
$this->cronRun();
// Search for 'comment'. Should be no results.
$this->drupalLogin($user);
$this->drupalGet('search/node');
$this->submitForm([
'keys' => 'comment',
], 'Search');
$this->assertSession()
->pageTextContains('Your search yielded no results');
// Search for the node title. Should be found, and 'Add new comment' should
// not be part of the search snippet.
$this->drupalGet('search/node');
$this->submitForm([
'keys' => 'short',
], 'Search');
$this->assertSession()
->pageTextContains($node->label());
$this->assertSession()
->pageTextNotContains('Add new comment');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.