You are here

protected function ViewsCacheInvalidationTest::setUp in Search API 8

Overrides KernelTestBase::setUp

File

tests/src/Kernel/Views/ViewsCacheInvalidationTest.php, line 120

Class

ViewsCacheInvalidationTest
Tests that cached Search API views get invalidated at the right occasions.

Namespace

Drupal\Tests\search_api\Kernel\Views

Code

protected function setUp() {
  parent::setUp();
  $this
    ->installSchema('node', [
    'node_access',
  ]);
  $this
    ->installSchema('search_api', [
    'search_api_item',
  ]);
  $this
    ->installSchema('system', [
    'sequences',
  ]);
  $this
    ->installEntitySchema('node');
  $this
    ->installEntitySchema('search_api_task');
  $this
    ->installEntitySchema('user');
  $this
    ->installConfig([
    'node',
    'search_api',
    'search_api_test_node_indexing',
    'search_api_test_views',
  ]);
  $this->entityTypeManager = $this->container
    ->get('entity_type.manager');
  $this->viewExecutableFactory = $this->container
    ->get('views.executable');
  $this->renderer = $this->container
    ->get('renderer');
  $this->cacheTagsInvalidator = $this->container
    ->get('cache_tags.invalidator');
  $this->currentUser = $this->container
    ->get('current_user');

  // Use the test search index from the search_api_test_db module.
  $this->index = Index::load('test_node_index');

  // Create a test content type.
  $this->contentType = NodeType::create([
    'name' => 'Page',
    'type' => 'page',
  ]);
  $this->contentType
    ->save();

  // Create some test content and index it.
  foreach ([
    'Cheery' => TRUE,
    'Carrot' => TRUE,
    'Detritus' => FALSE,
  ] as $title => $status) {
    $this
      ->createNode($title, $status);
  }
  $this->index
    ->indexItems();

  // Create a dummy test user. This user will get UID 1 which is handled as
  // the root user and can bypass all access restrictions. This is not used
  // in the test.
  $this
    ->createUser();

  // Create two test users, one with permission to view unpublished entities,
  // and one without.
  $this->users['no-access'] = $this
    ->createUser([
    'access content',
  ]);
  $this->users['has-access'] = $this
    ->createUser([
    'access content',
    'bypass node access',
  ]);
}