You are here

function FieldUITestCase::fieldUIAddExistingField in Drupal 7

Adds an existing field through the Field UI.

Parameters

$bundle_path: Admin path of the bundle that the field is to be attached to.

$initial_edit: $edit parameter for drupalPost() on the first step ('Manage fields' screen).

$instance_edit: $edit parameter for drupalPost() on the second step ('Instance settings' form).

2 calls to FieldUITestCase::fieldUIAddExistingField()
FieldUIManageFieldsTestCase::addExistingField in modules/field_ui/field_ui.test
Tests adding an existing field in another content type.
FieldUIManageFieldsTestCase::testDeleteField in modules/field_ui/field_ui.test
Tests that deletion removes fields and instances as expected.

File

modules/field_ui/field_ui.test, line 88
Tests for field_ui.module.

Class

FieldUITestCase
Provides common functionality for the Field UI test classes.

Code

function fieldUIAddExistingField($bundle_path, $initial_edit, $instance_edit = array()) {

  // Use 'test_field_widget' by default.
  $initial_edit += array(
    'fields[_add_existing_field][widget_type]' => 'test_field_widget',
  );
  $label = $initial_edit['fields[_add_existing_field][label]'];
  $field_name = $initial_edit['fields[_add_existing_field][field_name]'];

  // First step : 'Add existing field' on the 'Manage fields' page.
  $this
    ->drupalPost("{$bundle_path}/fields", $initial_edit, t('Save'));

  // Second step : 'Instance settings' form.
  $this
    ->drupalPost(NULL, $instance_edit, t('Save settings'));
  $this
    ->assertRaw(t('Saved %label configuration.', array(
    '%label' => $label,
  )), 'Redirected to "Manage fields" page.');

  // Check that the field appears in the overview form.
  $this
    ->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $label, 'Field was created and appears in the overview page.');
}