function ManageFieldsFunctionalTest::testDuplicateFieldName

Same name and namespace in other branches
  1. 9 core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsFunctionalTest::testDuplicateFieldName()
  2. 10 core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsFunctionalTest::testDuplicateFieldName()
  3. 11.x core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsFunctionalTest::testDuplicateFieldName()

Tests that a duplicate field name is caught by validation.

File

core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php, line 709

Class

ManageFieldsFunctionalTest
Tests the Field UI "Manage fields" screen.

Namespace

Drupal\Tests\field_ui\Functional

Code

public function testDuplicateFieldName() {
    // field_tags already exists, so we're expecting an error when trying to
    // create a new field with the same name.
    $edit = [
        'field_name' => 'tags',
        'label' => $this->randomMachineName(),
        'new_storage_type' => 'entity_reference',
    ];
    $url = 'admin/structure/types/manage/' . $this->contentType . '/fields/add-field';
    $this->drupalPostForm($url, $edit, t('Save and continue'));
    $this->assertText(t('The machine-readable name is already in use. It must be unique.'));
    $this->assertUrl($url, [], 'Stayed on the same page.');
}

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