Test that cached instance definitions are ready for current runtime context.
function testInstancePrepare() {
$field_definition = array(
'field_name' => 'field',
'type' => 'test_field',
);
field_create_field($field_definition);
$instance_definition = array(
'field_name' => $field_definition['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
);
$instance = field_create_instance($instance_definition);
// Simulate a stored instance definition missing various settings (e.g. a
// third-party module adding instance or widget settings has been enabled,
// but existing instances do not know the new settings).
\Drupal::config('field.instance.' . $instance
->id())
->set('settings', array())
->set('widget.type', 'unavailable_widget')
->set('widget.settings', array())
->save();
field_info_cache_clear();
// Read the instance back.
$instance = field_info_instance($instance_definition['entity_type'], $instance_definition['field_name'], $instance_definition['bundle']);
// Check that all expected instance settings are in place.
$field_type = field_info_field_types($field_definition['type']);
$this
->assertEqual($instance['settings'], $field_type['instance_settings'], 'All expected instance settings are present.');
}