FieldInfoTestCase::testFieldPrepare

  1. drupal
    1. 8
    2. 7
Versions
8 FieldInfoTestCase::testFieldPrepare()

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

Code

modules/field/tests/field.test, line 1126

<?php
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'], t('All expected default field settings are present.'));
}
?>