You are here

function FieldCrudTestCase::testFieldIndexes in Drupal 7

Test creation of indexes on data column.

File

modules/field/tests/field.test, line 2566
Tests for field.module.

Class

FieldCrudTestCase

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']);
  $expected_indexes = array(
    'value' => array(
      'value',
    ),
  );
  $this
    ->assertEqual($field['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']);
  $expected_indexes = array(
    'value' => array(),
  );
  $this
    ->assertEqual($field['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']);
  $expected_indexes = array(
    'value' => array(
      'value',
    ),
    'value_2' => array(
      'value',
    ),
  );
  $this
    ->assertEqual($field['indexes'], $expected_indexes, 'Field definition indexes are merged with field type indexes');
}