FieldUITestCase::fieldUIAddExistingField

7 field_ui.test FieldUITestCase::fieldUIAddExistingField($bundle_path, $initial_edit, $instance_edit = array())
8 field_ui.test FieldUITestCase::fieldUIAddExistingField($bundle_path, $initial_edit, $instance_edit = array())

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).

File

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

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)), t('Redirected to "Manage fields" page.'));

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