function FieldUiTestBase::fieldUIAddExistingField

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 FieldUiTestBase::fieldUIAddExistingField()
ManageFieldsTest::addExistingField in drupal/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php
Tests adding an existing field in another content type.
ManageFieldsTest::testDeleteField in drupal/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php
Tests that deletion removes fields and instances as expected.

File

drupal/core/modules/field_ui/lib/Drupal/field_ui/Tests/FieldUiTestBase.php, line 102
Definition of Drupal\field_ui\Tests\FieldUiTestBase.

Class

FieldUiTestBase
Provides common functionality for the Field UI test classes.

Namespace

Drupal\field_ui\Tests

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 : 'Re-use 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.');
}