function FieldStorageCrudTest::testIndexes
Same name in other branches
- 9 core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php \Drupal\Tests\field\Kernel\FieldStorageCrudTest::testIndexes()
- 8.9.x core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php \Drupal\Tests\field\Kernel\FieldStorageCrudTest::testIndexes()
- 11.x core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php \Drupal\Tests\field\Kernel\FieldStorageCrudTest::testIndexes()
Tests creation of indexes on data column.
File
-
core/
modules/ field/ tests/ src/ Kernel/ FieldStorageCrudTest.php, line 245
Class
- FieldStorageCrudTest
- Tests field storage create, read, update, and delete.
Namespace
Drupal\Tests\field\KernelCode
public function testIndexes() : void {
// Check that indexes specified by the field type are used by default.
$field_storage = FieldStorageConfig::create([
'field_name' => 'field_1',
'entity_type' => 'entity_test',
'type' => 'test_field',
]);
$field_storage->save();
$field_storage = FieldStorageConfig::load($field_storage->id());
$schema = $field_storage->getSchema();
$expected_indexes = [
'value' => [
'value',
],
];
$this->assertEquals($expected_indexes, $schema['indexes'], 'Field type indexes saved by default');
// Check that indexes specified by the field definition override the field
// type indexes.
$field_storage = FieldStorageConfig::create([
'field_name' => 'field_2',
'entity_type' => 'entity_test',
'type' => 'test_field',
'indexes' => [
'value' => [],
],
]);
$field_storage->save();
$field_storage = FieldStorageConfig::load($field_storage->id());
$schema = $field_storage->getSchema();
$expected_indexes = [
'value' => [],
];
$this->assertEquals($expected_indexes, $schema['indexes'], 'Field definition indexes override field type indexes');
// Check that indexes specified by the field definition add to the field
// type indexes.
$field_storage = FieldStorageConfig::create([
'field_name' => 'field_3',
'entity_type' => 'entity_test',
'type' => 'test_field',
'indexes' => [
'value_2' => [
'value',
],
],
]);
$field_storage->save();
$id = $field_storage->id();
$field_storage = FieldStorageConfig::load($id);
$schema = $field_storage->getSchema();
$expected_indexes = [
'value' => [
'value',
],
'value_2' => [
'value',
],
];
$this->assertEquals($expected_indexes, $schema['indexes'], 'Field definition indexes are merged with field type indexes');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.