You are here

function ManageFieldsTest::addExistingField in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/field_ui/src/Tests/ManageFieldsTest.php \Drupal\field_ui\Tests\ManageFieldsTest::addExistingField()

Tests adding an existing field in another content type.

1 call to ManageFieldsTest::addExistingField()
ManageFieldsTest::testCRUDFields in core/modules/field_ui/src/Tests/ManageFieldsTest.php
Runs the field CRUD tests.

File

core/modules/field_ui/src/Tests/ManageFieldsTest.php, line 225
Contains \Drupal\field_ui\Tests\ManageFieldsTest.

Class

ManageFieldsTest
Tests the Field UI "Manage fields" screen.

Namespace

Drupal\field_ui\Tests

Code

function addExistingField() {

  // Check "Re-use existing field" appears.
  $this
    ->drupalGet('admin/structure/types/manage/page/fields/add-field');
  $this
    ->assertRaw(t('Re-use an existing field'), '"Re-use existing field" was found.');

  // Check that fields of other entity types (here, the 'comment_body' field)
  // do not show up in the "Re-use existing field" list.
  $this
    ->assertFalse($this
    ->xpath('//select[@id="edit-existing-storage-name"]//option[@value="comment"]'), 'The list of options respects entity type restrictions.');

  // Validate the FALSE assertion above by also testing a valid one.
  $this
    ->assertTrue($this
    ->xpath('//select[@id="edit-existing-storage-name"]//option[@value=:field_name]', array(
    ':field_name' => $this->fieldName,
  )), 'The list of options shows a valid option.');

  // Add a new field based on an existing field.
  $this
    ->fieldUIAddExistingField("admin/structure/types/manage/page", $this->fieldName, $this->fieldLabel . '_2');
}