You are here

public function FieldValuesExtractionTest::setUp in Search API 8

Overrides KernelTestBase::setUp

File

tests/src/Kernel/System/FieldValuesExtractionTest.php, line 61

Class

FieldValuesExtractionTest
Tests extraction of field values, as used during indexing.

Namespace

Drupal\Tests\search_api\Kernel\System

Code

public function setUp() {
  parent::setUp();
  $this
    ->installSchema('system', [
    'sequences',
  ]);
  $this
    ->installEntitySchema('entity_test_mulrev_changed');
  $this
    ->installEntitySchema('user');
  $this
    ->installConfig([
    'search_api_test_extraction',
    'user',
  ]);
  $entity_storage = \Drupal::entityTypeManager()
    ->getStorage('entity_test_mulrev_changed');
  $this->entities[0] = $entity_storage
    ->create([
    'type' => 'article',
    'name' => 'Article 1',
    'links' => [],
  ]);
  $this->entities[0]
    ->save();
  $this->entities[1] = $entity_storage
    ->create([
    'type' => 'article',
    'name' => 'Article 2',
    'links' => [],
  ]);
  $this->entities[1]
    ->save();
  $this->entities[2] = $entity_storage
    ->create([
    'type' => 'article',
    'name' => 'Article 3',
    'links' => [
      [
        'target_id' => $this->entities[0]
          ->id(),
      ],
      [
        'target_id' => $this->entities[1]
          ->id(),
      ],
    ],
  ]);
  $this->entities[2]
    ->save();
  $this->entities[3] = $entity_storage
    ->create([
    'type' => 'article',
    'name' => 'Article 4',
    'links' => [
      [
        'target_id' => $this->entities[0]
          ->id(),
      ],
      [
        'target_id' => $this->entities[2]
          ->id(),
      ],
    ],
  ]);
  $this->entities[2]
    ->save();
  user_role_grant_permissions('anonymous', [
    'view test entity',
  ]);
  User::create([
    'id' => $this->entities[0],
    'name' => 'Test user',
  ])
    ->save();
  $this->index = Index::create([
    'field_settings' => [
      'foo' => [
        'type' => 'text',
        'datasource_id' => 'entity:entity_test_mulrev_changed',
        'property_path' => 'name',
      ],
      'bar' => [
        'type' => 'text',
        'property_path' => 'rendered_item',
        'configuration' => [
          'roles' => [
            'anonymous' => 'anonymous',
          ],
          'view_mode' => [
            'entity:entity_test_mulrev_changed' => [
              'article' => 'default',
            ],
          ],
        ],
      ],
    ],
    'datasource_settings' => [
      'entity:entity_test_mulrev_changed' => [],
    ],
  ]);
  $this->fieldsHelper = $this->container
    ->get('search_api.fields_helper');
}