Tests that Field UI respects the 'no_ui' option in hook_field_info().
function testHiddenFields() {
$bundle_path = 'admin/structure/types/manage/' . $this->type . '/fields/';
// Check that the field type is not available in the 'add new field' row.
$this
->drupalGet($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'),
);
field_create_instance($instance);
entity_get_form_display('node', $this->type, 'default')
->setComponent($field_name)
->save();
$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
->drupalGet($bundle_path);
$this
->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $instance['label'], 'Field was created and appears in the overview page.');
// Check that the instance does not appear in the 're-use existing field' row
// on other bundles.
$bundle_path = 'admin/structure/types/manage/article/fields/';
$this
->drupalGet($bundle_path);
$this
->assertFalse($this
->xpath('//select[@id="edit-add-existing-field-field-name"]//option[@value=:field_name]', array(
':field_name' => $field_name,
)), "The 're-use existing field' select respects field types 'no_ui' property.");
// Remove the form display component to check the fallback label.
entity_get_form_display('node', $this->type, 'default')
->removeComponent($field_name)
->save();
$this
->drupalGet('admin/structure/types/manage/' . $this->type . '/fields/');
$this
->assertLinkByHref(url('admin/structure/types/manage/' . $this->type . '/fields/node.' . $this->type . '.' . $field_name . '/widget-type'));
$this
->assertLink('- Hidden -');
}