You are here

protected function IntegrationTest::checkReferenceFieldsNonBaseFields in Search API 8

Tests if non-base fields of referenced entities can be added.

1 call to IntegrationTest::checkReferenceFieldsNonBaseFields()
IntegrationTest::testFramework in tests/src/Functional/IntegrationTest.php
Tests various operations via the Search API's admin UI.

File

tests/src/Functional/IntegrationTest.php, line 1141

Class

IntegrationTest
Tests the overall functionality of the Search API framework and admin UI.

Namespace

Drupal\Tests\search_api\Functional

Code

protected function checkReferenceFieldsNonBaseFields() {

  // Add a new entity_reference field.
  $field_label = 'reference_field';
  FieldStorageConfig::create([
    'field_name' => 'field__reference_field_',
    'type' => 'entity_reference',
    'entity_type' => 'node',
    'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
    'settings' => [
      'allowed_values' => [
        [
          'target_type' => 'node',
        ],
      ],
    ],
  ])
    ->save();
  FieldConfig::create([
    'field_name' => 'field__reference_field_',
    'entity_type' => 'node',
    'bundle' => 'article',
    'label' => $field_label,
  ])
    ->save();
  EntityFormDisplay::load('node.article.default')
    ->setComponent('field__reference_field_', [
    'type' => 'entity_reference_autocomplete',
  ])
    ->save();
  $node_label = $this
    ->getIndex()
    ->getDatasource('entity:node')
    ->label();
  $field_label = "{$field_label} » {$node_label} » {$field_label}";
  $this
    ->addField('entity:node', 'field__reference_field_:entity:field__reference_field_', $field_label);
  $this
    ->drupalGet($this
    ->getIndexPath('fields'));
  $this
    ->submitForm([], 'Save changes');
  $this
    ->drupalGet('node/2/edit');
  $edit = [
    'field__reference_field_[0][target_id]' => 'Something (2)',
  ];
  $this
    ->drupalGet('node/2/edit');
  $this
    ->submitForm($edit, 'Save');
  $indexed_values = \Drupal::state()
    ->get("search_api_test.backend.indexed.{$this->indexId}", []);
  $this
    ->assertEquals([
    2,
  ], $indexed_values['entity:node/2:en']['field__reference_field_'], 'Correct value indexed for nested non-base field.');
}