You are here

public function RoleAccessTest::setUp in Search API 8

Performs setup tasks before each individual test method is run.

Installs commonly used schemas and sets up a search server and an index, with the specified processor enabled.

Parameters

string|null $processor: (optional) The plugin ID of the processor that should be set up for testing.

Overrides ProcessorTestBase::setUp

File

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

Class

RoleAccessTest
Tests the "Role-based access" processor.

Namespace

Drupal\Tests\search_api\Kernel\Processor

Code

public function setUp($processor = NULL) {
  parent::setUp('role_access');
  $this
    ->installSchema('system', [
    'sequences',
  ]);
  NodeType::create([
    'type' => 'page',
    'name' => 'page',
  ])
    ->save();

  // Enable the programmable role-based access controls found in the
  // search_api_test module.
  // @see search_api_test_entity_access()
  \Drupal::state()
    ->set('search_api_test_add_role_access_control', TRUE);

  // Create three test roles and the anonymous user role, all of which can
  // access content. Since the test adds its own test access hook for each
  // role, we do not want to test existing core access mechanisms.
  foreach ([
    'foo',
    'bar',
    'baz',
    'anonymous',
    'authenticated',
  ] as $role_id) {
    Role::create([
      'id' => $role_id,
      'name' => $role_id,
    ])
      ->grantPermission('access content')
      ->save();
  }

  // Create a test user for each of the (non-anonymous) test roles.
  foreach ([
    'foo',
    'bar',
    'baz',
  ] as $role_id) {
    $test_user = User::create([
      'name' => $role_id,
    ]);
    $test_user
      ->addRole($role_id);
    $test_user
      ->save();
    $this->testUsers[$role_id] = $test_user;
  }

  // Insert the special-case anonymous user.
  $anonymous_user = User::create([
    'uid' => 0,
    'name' => '',
  ]);
  $anonymous_user
    ->save();
  $this->testUsers['anonymous'] = $anonymous_user;

  // Insert the special case authenticated user.
  $authenticated_user = User::create([
    'name' => 'Authenticated',
  ]);
  $authenticated_user
    ->save();
  $this->testUsers['authenticated'] = $authenticated_user;
}