You are here

public function ManageFieldsFunctionalTest::testDuplicateFieldName in Drupal 8

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()

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