public function FieldStorageCrudTest::testIndexes in Drupal 8
Same name and namespace in other branches
- 9 core/modules/field/tests/src/Kernel/FieldStorageCrudTest.php \Drupal\Tests\field\Kernel\FieldStorageCrudTest::testIndexes()
Test creation of indexes on data column.
File
- core/
modules/ field/ tests/ src/ Kernel/ FieldStorageCrudTest.php, line 240
Class
- FieldStorageCrudTest
- Tests field storage create, read, update, and delete.
Namespace
Drupal\Tests\field\KernelCode
public function testIndexes() {
// 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
->assertEqual($schema['indexes'], $expected_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
->assertEqual($schema['indexes'], $expected_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
->assertEqual($schema['indexes'], $expected_indexes, 'Field definition indexes are merged with field type indexes');
}