You are here

function FieldUIManageFieldsTestCase::testDuplicateFieldName in Drupal 7

Tests that a duplicate field name is caught by validation.

File

modules/field_ui/field_ui.test, line 433
Tests for field_ui.module.

Class

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

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