You are here

public function ContentAccessTest::testQueryAccessAll in Search API 8

Tests searching when content is accessible to all.

File

tests/src/Kernel/Processor/ContentAccessTest.php, line 138

Class

ContentAccessTest
Tests the "Content access" processor.

Namespace

Drupal\Tests\search_api\Kernel\Processor

Code

public function testQueryAccessAll() {
  $permissions = [
    'access content',
    'access comments',
  ];
  user_role_grant_permissions('anonymous', $permissions);
  $this->index
    ->reindex();
  $this
    ->indexItems();
  $this
    ->assertEquals(5, $this->index
    ->getTrackerInstance()
    ->getIndexedItemsCount(), '5 items indexed, as expected.');
  $query = \Drupal::getContainer()
    ->get('search_api.query_helper')
    ->createQuery($this->index);
  $result = $query
    ->execute();
  $expected = [
    'user' => [
      0,
    ],
    'comment' => [
      0,
    ],
    'node' => [
      0,
      1,
    ],
  ];
  $this
    ->assertResults($result, $expected);
}