function FieldInfoTest::testFieldPrepare

Test that cached field definitions are ready for current runtime context.

File

drupal/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php, line 126
Definition of Drupal\field\Tests\FieldInfoTest.

Class

FieldInfoTest

Namespace

Drupal\field\Tests

Code

function testFieldPrepare() {
  $field_definition = array(
    'field_name' => 'field',
    'type' => 'test_field',
  );
  field_create_field($field_definition);

  // Simulate a stored field definition missing a field setting (e.g. a
  // third-party module adding a new field setting has been enabled, and
  // existing fields do not know the setting yet).
  $data = db_query('SELECT data FROM {field_config} WHERE field_name = :field_name', array(
    ':field_name' => $field_definition['field_name'],
  ))
    ->fetchField();
  $data = unserialize($data);
  $data['settings'] = array();
  db_update('field_config')
    ->fields(array(
    'data' => serialize($data),
  ))
    ->condition('field_name', $field_definition['field_name'])
    ->execute();
  field_cache_clear();

  // Read the field back.
  $field = field_info_field($field_definition['field_name']);

  // Check that all expected settings are in place.
  $field_type = field_info_field_types($field_definition['type']);
  $this
    ->assertIdentical($field['settings'], $field_type['settings'], 'All expected default field settings are present.');
}