1 field_permission_example.test public GenericFieldTest::runTestGenericFieldInfo()

Verify that all required fields are specified in hook_field_info().

The full list is label, description, settings, instance_settings, default_widget, default_formatter, no_ui.

Some are optional, and we won't check for those.

In a sane world, this would be a unit test, rather than a web test, but module_implements is unavailable to us in unit tests.

See also

hook_field_info()

File

modules/examples/field_permission_example/tests/field_permission_example.test, line 86
Tests for Field Permission Example.

Class

GenericFieldTest
A generic field testing class.

Code

public function runTestGenericFieldInfo() {
  $field_types = $this->getFieldTypes();
  $module = $this->getModule();
  $info_keys = array(
    'label',
    'description',
    'default_widget',
    'default_formatter',
  );
  // We don't want to use field_info_field_types()
  // because there is a hook_field_info_alter().
  // We're testing the module here, not the rest of
  // the system. So invoke hook_field_info() ourselves.
  $modules = module_implements('field_info');
  $this->assertTrue(in_array($module, $modules), 
  'Module ' . $module . ' implements hook_field_info()');

  foreach ($field_types as $field_type) {
    $field_info = module_invoke($module, 'field_info');
    $this->assertTrue(isset($field_info[$field_type]), 
    'Module ' . $module . ' defines field type ' . $field_type);
    $field_info = $field_info[$field_type];
    foreach ($info_keys as $key) {
      $this->assertTrue(
      isset($field_info[$key]), 
      $field_type . "'s " . $key . ' is set.'
      );
    }
  }
}