public function SearchCommentTest::testAddNewComment in Drupal 10
Same name and namespace in other branches
- 8 core/modules/search/tests/src/Functional/SearchCommentTest.php \Drupal\Tests\search\Functional\SearchCommentTest::testAddNewComment()
- 9 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 342
Class
- SearchCommentTest
- Tests integration searching comments.
Namespace
Drupal\Tests\search\FunctionalCode
public function testAddNewComment() {
// 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');
}