function CrudTest::testFieldIndexes

Test creation of indexes on data column.

File

drupal/core/modules/field/lib/Drupal/field/Tests/CrudTest.php, line 227
Definition of Drupal\field\Tests\CrudTest.

Class

CrudTest

Namespace

Drupal\field\Tests

Code

function testFieldIndexes() {

  // Check that indexes specified by the field type are used by default.
  $field_definition = array(
    'field_name' => 'field_1',
    'type' => 'test_field',
  );
  field_create_field($field_definition);
  $field = field_read_field($field_definition['field_name']);
  $schema = $field
    ->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_definition = array(
    'field_name' => 'field_2',
    'type' => 'test_field',
    'indexes' => array(
      'value' => array(),
    ),
  );
  field_create_field($field_definition);
  $field = field_read_field($field_definition['field_name']);
  $schema = $field
    ->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_definition = array(
    'field_name' => 'field_3',
    'type' => 'test_field',
    'indexes' => array(
      'value_2' => array(
        'value',
      ),
    ),
  );
  field_create_field($field_definition);
  $field = field_read_field($field_definition['field_name']);
  $schema = $field
    ->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');
}