You are here

public function ProcessorIntegrationTest::setUp in Search API 8

Overrides SearchApiBrowserTestBase::setUp

File

tests/src/Functional/ProcessorIntegrationTest.php, line 38

Class

ProcessorIntegrationTest
Tests the admin UI for processors.

Namespace

Drupal\Tests\search_api\Functional

Code

public function setUp() {
  parent::setUp();
  $this
    ->drupalLogin($this->adminUser);
  $this->indexId = 'test_index';
  $index = Index::create([
    'name' => 'Test index',
    'id' => $this->indexId,
    'status' => 1,
    'datasource_settings' => [
      'entity:node' => [],
      'entity:user' => [],
    ],
  ]);

  // Add a node and a taxonomy term reference, both of which could be used to
  // create a hierarchy.
  $this
    ->createEntityReferenceField('node', 'page', 'term_field', NULL, 'taxonomy_term', 'default', [], FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  $this
    ->createEntityReferenceField('node', 'page', 'parent_reference', NULL, 'node', 'default', [
    'target_bundles' => [
      'page' => 'page',
    ],
  ]);

  // Index the taxonomy and entity reference fields.
  $term_field = new Field($index, 'term_field');
  $term_field
    ->setType('integer');
  $term_field
    ->setPropertyPath('term_field');
  $term_field
    ->setDatasourceId('entity:node');
  $term_field
    ->setLabel('Terms');
  $index
    ->addField($term_field);
  $parent_reference = new Field($index, 'parent_reference');
  $parent_reference
    ->setType('integer');
  $parent_reference
    ->setPropertyPath('parent_reference');
  $parent_reference
    ->setDatasourceId('entity:node');
  $parent_reference
    ->setLabel('Terms');
  $index
    ->addField($parent_reference);
  $index
    ->save();
}