You are here

function FieldStorageCrudTest::testIndexes in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field/src/Tests/FieldStorageCrudTest.php \Drupal\field\Tests\FieldStorageCrudTest::testIndexes()

Test creation of indexes on data column.

File

core/modules/field/src/Tests/FieldStorageCrudTest.php, line 241
Contains \Drupal\field\Tests\FieldStorageCrudTest.

Class

FieldStorageCrudTest
Tests field storage create, read, update, and delete.

Namespace

Drupal\field\Tests

Code

function testIndexes() {

  // Check that indexes specified by the field type are used by default.
  $field_storage = entity_create('field_storage_config', array(
    '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 = array(
    'value' => array(
      '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 = entity_create('field_storage_config', array(
    'field_name' => 'field_2',
    'entity_type' => 'entity_test',
    'type' => 'test_field',
    'indexes' => array(
      'value' => array(),
    ),
  ));
  $field_storage
    ->save();
  $field_storage = FieldStorageConfig::load($field_storage
    ->id());
  $schema = $field_storage
    ->getSchema();
  $expected_indexes = array(
    'value' => array(),
  );
  $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 = entity_create('field_storage_config', array(
    'field_name' => 'field_3',
    'entity_type' => 'entity_test',
    'type' => 'test_field',
    'indexes' => array(
      'value_2' => array(
        'value',
      ),
    ),
  ));
  $field_storage
    ->save();
  $id = $field_storage
    ->id();
  $field_storage = FieldStorageConfig::load($id);
  $schema = $field_storage
    ->getSchema();
  $expected_indexes = array(
    'value' => array(
      'value',
    ),
    'value_2' => array(
      'value',
    ),
  );
  $this
    ->assertEqual($schema['indexes'], $expected_indexes, 'Field definition indexes are merged with field type indexes');
}