You are here

public function RoleAccessTest::testDefaultingToLoggedInUser in Search API 8

Tests whether the access check correctly defaults to the logged-in user.

File

tests/src/Kernel/Processor/RoleAccessTest.php, line 163

Class

RoleAccessTest
Tests the "Role-based access" processor.

Namespace

Drupal\Tests\search_api\Kernel\Processor

Code

public function testDefaultingToLoggedInUser() {
  $allowed_foo = $this
    ->createTestNode('allow for foo role');
  \Drupal::currentUser()
    ->setAccount($this->testUsers['foo']);
  $index_storage = \Drupal::entityTypeManager()
    ->getStorage('search_api_index');
  $index_storage
    ->resetCache([
    $this->index
      ->id(),
  ]);
  $this->index = $index_storage
    ->load($this->index
    ->id());
  $this->index
    ->reindex();
  $this
    ->indexItems();
  $query = \Drupal::getContainer()
    ->get('search_api.query_helper')
    ->createQuery($this->index);
  $result = $query
    ->execute();
  $this
    ->assertResults($result, [
    'node' => [
      $allowed_foo,
    ],
  ]);
}