You are here

public function CommandHelperTest::setUp in Search API 8

Overrides KernelTestBase::setUp

File

tests/src/Kernel/System/CommandHelperTest.php, line 46

Class

CommandHelperTest
Tests Search API functionality that gets executed by console utilities.

Namespace

Drupal\Tests\search_api\Kernel\System

Code

public function setUp() {
  parent::setUp();
  $this
    ->installSchema('search_api', [
    'search_api_item',
  ]);
  $this
    ->installSchema('system', [
    'key_value_expire',
    'sequences',
  ]);
  $this
    ->installEntitySchema('entity_test_mulrev_changed');
  $this
    ->installEntitySchema('search_api_task');
  $this
    ->installConfig('search_api');

  // Disable the use of batches for item tracking to simulate a CLI
  // environment.
  if (!Utility::isRunningInCli()) {
    \Drupal::state()
      ->set('search_api_use_tracking_batch', FALSE);
  }

  // Create a test server.
  Server::create([
    'name' => 'Pink pony server',
    'id' => 'test_server',
    'status' => TRUE,
    'backend' => 'search_api_test',
  ])
    ->save();
  Role::create([
    'id' => 'anonymous',
    'label' => 'anonymous',
  ])
    ->save();
  user_role_grant_permissions('anonymous', [
    'view test entity',
  ]);
  Index::create([
    'name' => 'Test Index',
    'id' => 'test_index',
    'status' => TRUE,
    'datasource_settings' => [
      'entity:entity_test_mulrev_changed' => [],
    ],
    'tracker_settings' => [
      'default' => [],
    ],
    'server' => 'test_server',
    'options' => [
      'index_directly' => FALSE,
    ],
  ])
    ->save();
  Index::create([
    'name' => 'Secondary index.',
    'id' => 'second_index',
    'status' => FALSE,
    'datasource_settings' => [
      'entity:entity_test_mulrev_changed' => [],
    ],
    'tracker_settings' => [
      'default' => [],
    ],
    'server' => 'test_server',
    'options' => [
      'index_directly' => FALSE,
    ],
  ])
    ->save();
  $this
    ->setUpExampleStructure();
  $this
    ->insertExampleContent();
  $this
    ->indexItems('test_index');
  $this->systemUnderTest = new CommandHelper(\Drupal::entityTypeManager(), \Drupal::moduleHandler(), \Drupal::getContainer()
    ->get('event_dispatcher'), 't');
  $this->systemUnderTest
    ->setLogger(new NullLogger());
}