You are here

public function FieldUiTestTrait::fieldUIAddExistingField in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field_ui/src/Tests/FieldUiTestTrait.php \Drupal\field_ui\Tests\FieldUiTestTrait::fieldUIAddExistingField()

Adds an existing field through the Field UI.

Parameters

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

string $existing_storage_name: The name of the existing field storage for which we want to add a new field.

string $label: (optional) The label of the new field. Defaults to a random string.

array $field_edit: (optional) $edit parameter for drupalPostForm() on the second step ('Field settings' form).

4 calls to FieldUiTestTrait::fieldUIAddExistingField()
FieldUIDeleteTest::testDeleteField in core/modules/field_ui/src/Tests/FieldUIDeleteTest.php
Tests that deletion removes field storages and fields as expected.
ManageFieldsTest::addExistingField in core/modules/field_ui/src/Tests/ManageFieldsTest.php
Tests adding an existing field in another content type.
ManageFieldsTest::addPersistentFieldStorage in core/modules/field_ui/src/Tests/ManageFieldsTest.php
Tests that persistent field storage appears in the field UI.
ManageFieldsTest::testDeleteField in core/modules/field_ui/src/Tests/ManageFieldsTest.php
Tests that deletion removes field storages and fields as expected.

File

core/modules/field_ui/src/Tests/FieldUiTestTrait.php, line 80
Contains \Drupal\field_ui\Tests\FieldUiTestTrait.

Class

FieldUiTestTrait
Provides common functionality for the Field UI test classes.

Namespace

Drupal\field_ui\Tests

Code

public function fieldUIAddExistingField($bundle_path, $existing_storage_name, $label = NULL, array $field_edit = array()) {
  $label = $label ?: $this
    ->randomString();
  $initial_edit = array(
    'existing_storage_name' => $existing_storage_name,
    'existing_storage_label' => $label,
  );

  // First step: 'Re-use existing field' on the 'Add field' page.
  $this
    ->drupalPostForm("{$bundle_path}/fields/add-field", $initial_edit, t('Save and continue'));

  // Set the main content to only the content region because the label can
  // contain HTML which will be auto-escaped by Twig.
  $main_content = $this
    ->cssSelect('.region-content');
  $this
    ->setRawContent(reset($main_content)
    ->asXml());
  $this
    ->assertRaw('field-config-edit-form', 'The field config edit form is present.');
  $this
    ->assertNoRaw('<', 'The page does not have double escaped HTML tags.');

  // Second step: 'Field settings' form.
  $this
    ->drupalPostForm(NULL, $field_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"]//tr/td[1]', $label, 'Field was created and appears in the overview page.');
}