1 field.test FieldCrudTestCase::_testActiveHelper($field_definition, $modules)

Helper function for testActive().

Test dependency between a field and a set of modules.

Parameters

$field_definition: A field definition.

$modules: An array of module names. The field will be tested to be inactive as long as any of those modules is disabled.

File

core/modules/field/tests/field.test, line 2572
Tests for field.module.

Class

FieldCrudTestCase

Code

function _testActiveHelper($field_definition, $modules) {
  $field_name = $field_definition['field_name'];

  // Read the field.
  $field = field_read_field($field_name);
  $this->assertTrue($field_definition <= $field, 'The field was properly read.');

  module_disable($modules, FALSE);

  $fields = field_read_fields(array('field_name' => $field_name), array('include_inactive' => TRUE));
  $this->assertTrue(isset($fields[$field_name]) && $field_definition < $field, 'The field is properly read when explicitly fetching inactive fields.');

  // Re-enable modules one by one, and check that the field is still inactive
  // while some modules remain disabled.
  while ($modules) {
    $field = field_read_field($field_name);
    $this->assertTrue(empty($field), format_string('%modules disabled. The field is marked inactive.', array('%modules' => implode(', ', $modules))));

    $module = array_shift($modules);
    module_enable(array($module), FALSE);
  }

  // Check that the field is active again after all modules have been
  // enabled.
  $field = field_read_field($field_name);
  $this->assertTrue($field_definition <= $field, 'The field was was marked active.');
}