protected function IntegrationTest::addFieldsWithDependenciesToIndex in Search API 8
Tests field dependencies.
1 call to IntegrationTest::addFieldsWithDependenciesToIndex()
- IntegrationTest::testIntegerIndex in tests/
src/ Functional/ IntegrationTest.php - Tests what happens when an index has an integer as id/label.
File
- tests/
src/ Functional/ IntegrationTest.php, line 983
Class
- IntegrationTest
- Tests the overall functionality of the Search API framework and admin UI.
Namespace
Drupal\Tests\search_api\FunctionalCode
protected function addFieldsWithDependenciesToIndex() {
// Add a new link field.
FieldStorageConfig::create([
'field_name' => 'field_link',
'type' => 'link',
'entity_type' => 'node',
])
->save();
FieldConfig::create([
'field_name' => 'field_link',
'entity_type' => 'node',
'bundle' => 'article',
'label' => 'Link',
])
->save();
// Add a new image field, for both articles and basic pages.
FieldStorageConfig::create([
'field_name' => 'field_image',
'type' => 'image',
'entity_type' => 'node',
])
->save();
FieldConfig::create([
'field_name' => 'field_image',
'entity_type' => 'node',
'bundle' => 'article',
'label' => 'Image',
])
->save();
FieldConfig::create([
'field_name' => 'field_image',
'entity_type' => 'node',
'bundle' => 'page',
'label' => 'Image',
])
->save();
$fields = [
'field_link' => 'Link',
'field_image' => 'Image',
];
foreach ($fields as $property_path => $label) {
$this
->addField('entity:node', $property_path, $label);
}
$this
->drupalGet($this
->getIndexPath('fields'));
$this
->submitForm([], 'Save changes');
// Check that index configuration is updated with dependencies.
$field_dependencies = (array) \Drupal::config('search_api.index.' . $this->indexId)
->get('dependencies.config');
$this
->assertTrue(in_array('field.storage.node.field_link', $field_dependencies), 'The link field has been added as a dependency of the index.');
$this
->assertTrue(in_array('field.storage.node.field_image', $field_dependencies), 'The image field has been added as a dependency of the index.');
}