function ManageFieldsTest::testDuplicateFieldName

Tests that a duplicate field name is caught by validation.

File

drupal/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php, line 388
Definition of Drupal\field_ui\Tests\ManageFieldsTest.

Class

ManageFieldsTest
Tests the functionality of the 'Manage fields' screen.

Namespace

Drupal\field_ui\Tests

Code

function testDuplicateFieldName() {

  // field_tags already exists, so we're expecting an error when trying to
  // create a new field with the same name.
  $edit = array(
    'fields[_add_new_field][field_name]' => 'tags',
    'fields[_add_new_field][label]' => $this
      ->randomName(),
    'fields[_add_new_field][type]' => 'taxonomy_term_reference',
    'fields[_add_new_field][widget_type]' => 'options_select',
  );
  $url = 'admin/structure/types/manage/' . $this->type . '/fields';
  $this
    ->drupalPost($url, $edit, t('Save'));
  $this
    ->assertText(t('The machine-readable name is already in use. It must be unique.'));
  $this
    ->assertUrl($url, array(), 'Stayed on the same page.');
}