1.20.x 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 backdropPost() on the first step ('Manage fields' screen).

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

File

modules/field_ui/tests/field_ui.test, line 99
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->backdropPost("$bundle_path/fields", $initial_edit, t('Save'));

  // Second step : 'Instance settings' form.
  $this->backdropPost(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->assertLinkByHref("$bundle_path/fields/$field_name", 0, 'Field was created and appears in the overview page.');
}