1.20.x field_ui.test FieldUIManageFieldsTestCase::testHiddenFields()

Tests that Field UI respects the 'no_ui' option in hook_field_info().

File

modules/field_ui/tests/field_ui.test, line 468
Tests for field_ui.module.

Class

FieldUIManageFieldsTestCase
Tests the functionality of the 'Manage fields' screen.

Code

function testHiddenFields() {
  $bundle_path = 'admin/structure/types/manage/' . $this->hyphen_type . '/fields';

  // Check that the field type is not available in the 'add new field' row.
  $this->backdropGet($bundle_path);
  $this->assertFalse($this->xpath('//select[@id="edit-add-new-field-type"]//option[@value="hidden_test_field"]'), "The 'add new field' select respects field types 'no_ui' property.");

  // Create a field and an instance programmatically.
  $field_name = 'hidden_test_field';
  field_create_field(array('field_name' => $field_name, 'type' => $field_name));
  $instance = array(
    'field_name' => $field_name,
    'bundle' => $this->type,
    'entity_type' => 'node',
    'label' => t('Hidden field'),
    'widget' => array('type' => 'test_field_widget'),
  );
  field_create_instance($instance);
  $this->assertTrue(field_read_instance('node', $field_name, $this->type), format_string('An instance of the field %field was created programmatically.', array('%field' => $field_name)));

  // Check that the newly added instance appears on the 'Manage Fields'
  // screen.
  $this->backdropGet($bundle_path);
  $this->assertLinkByHref("$bundle_path/$field_name", 0, 'Field was created and appears in the overview page.');

  // Check that the instance does not appear in the 'add existing field' row
  // on other bundles.
  $bundle_path = 'admin/structure/types/manage/post/fields';
  $this->backdropGet($bundle_path);
  $this->assertFalse($this->xpath('//select[@id="edit-add-existing-field-field-name"]//option[@value=:field_name]', array(':field_name' => $field_name)), "The 'add existing field' select respects field types 'no_ui' property.");
}