You are here

public function ContentAccessTest::testQueryAccessBypass in Search API 8

Tests whether the "search_api_bypass_access" query option is respected.

File

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

Class

ContentAccessTest
Tests the "Content access" processor.

Namespace

Drupal\Tests\search_api\Kernel\Processor

Code

public function testQueryAccessBypass() {
  $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, [
    'search_api_bypass_access' => TRUE,
  ]);
  $result = $query
    ->execute();
  $expected = [
    'user' => [
      0,
    ],
    'comment' => [
      0,
    ],
    'node' => [
      0,
      1,
      2,
    ],
  ];
  $this
    ->assertResults($result, $expected);
}