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 125
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 = 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).
  \Drupal::config('field.field.' . $field
    ->id())
    ->set('settings', array())
    ->save();
  field_info_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
    ->assertEqual($field['settings'], $field_type['settings'], 'All expected default field settings are present.');
}