function ManageFieldsLifecycleTest::addExistingField

Same name in other branches
  1. 11.x core/modules/field_ui/tests/src/Functional/ManageFieldsLifecycleTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsLifecycleTest::addExistingField()

Tests adding an existing field in another content type.

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

File

core/modules/field_ui/tests/src/Functional/ManageFieldsLifecycleTest.php, line 117

Class

ManageFieldsLifecycleTest
Tests the Field UI "Manage fields" screen.

Namespace

Drupal\Tests\field_ui\Functional

Code

protected function addExistingField() {
    // Check "Re-use existing field" appears.
    $this->drupalGet('admin/structure/types/manage/page/fields');
    $this->assertSession()
        ->pageTextContains('Re-use an existing field');
    $this->clickLink('Re-use an existing field');
    // Check that fields of other entity types (here, the 'comment_body' field)
    // do not show up in the "Re-use existing field" list.
    $this->assertSession()
        ->elementNotExists('css', '.js-reuse-table [data-field-id="comment_body"]');
    // Validate the FALSE assertion above by also testing a valid one.
    $this->assertSession()
        ->elementExists('css', ".js-reuse-table [data-field-id='{$this->fieldName}']");
    $new_label = $this->fieldLabel . '_2';
    // Add a new field based on an existing field.
    $this->fieldUIAddExistingField("admin/structure/types/manage/page", $this->fieldName, $new_label);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.