function SearchCommentTest::assertCommentAccess

Same name in other branches
  1. 8.9.x core/modules/search/tests/src/Functional/SearchCommentTest.php \Drupal\Tests\search\Functional\SearchCommentTest::assertCommentAccess()
  2. 10 core/modules/search/tests/src/Functional/SearchCommentTest.php \Drupal\Tests\search\Functional\SearchCommentTest::assertCommentAccess()
  3. 11.x core/modules/search/tests/src/Functional/SearchCommentTest.php \Drupal\Tests\search\Functional\SearchCommentTest::assertCommentAccess()

Update search index and search for comment.

@internal

1 call to SearchCommentTest::assertCommentAccess()
SearchCommentTest::testSearchResultsCommentAccess in core/modules/search/tests/src/Functional/SearchCommentTest.php
Verify access rules for comment indexing with different permissions.

File

core/modules/search/tests/src/Functional/SearchCommentTest.php, line 316

Class

SearchCommentTest
Tests integration searching comments.

Namespace

Drupal\Tests\search\Functional

Code

public function assertCommentAccess(bool $assume_access, string $message) : void {
    // Invoke search index update.
    \Drupal::service('search.index')->markForReindex('node_search', $this->node
        ->id());
    $this->cronRun();
    // Search for the comment subject.
    $edit = [
        'keys' => "'" . $this->commentSubject . "'",
    ];
    $this->drupalGet('search/node');
    $this->submitForm($edit, 'Search');
    try {
        if ($assume_access) {
            $this->assertSession()
                ->pageTextContains($this->node
                ->label());
            $this->assertSession()
                ->pageTextContains($this->commentSubject);
        }
        else {
            $this->assertSession()
                ->pageTextContains('Your search yielded no results.');
        }
    } catch (ResponseTextException $exception) {
        $this->fail($message);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.