function ManageFieldsFunctionalTest::testFieldNameValidation
Same name in other branches
- 11.x core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsFunctionalTest::testFieldNameValidation()
Tests validation of duplicate and disallowed field names.
File
-
core/
modules/ field_ui/ tests/ src/ Functional/ ManageFieldsFunctionalTest.php, line 215
Class
- ManageFieldsFunctionalTest
- Tests the Field UI "Manage fields" screen.
Namespace
Drupal\Tests\field_ui\FunctionalCode
public function testFieldNameValidation() : void {
// field_tags already exists, so we're expecting an error when trying to
// create a new field with the same name.
$url = 'admin/structure/types/manage/' . $this->contentType . '/fields/add-field';
$this->drupalGet($url);
$edit = [
'new_storage_type' => 'boolean',
];
$this->submitForm($edit, 'Continue');
$edit = [
'label' => $this->randomMachineName(),
'field_name' => 'tags',
];
$this->submitForm($edit, 'Continue');
$this->assertSession()
->pageTextContains('The machine-readable name is already in use. It must be unique.');
// Reset the field prefix so we can test properly.
$this->config('field_ui.settings')
->set('field_prefix', '')
->save();
$label = 'Disallowed field';
$edit1 = [
'new_storage_type' => 'test_field',
];
$edit2 = [
'label' => $label,
];
// Try with an entity key.
$edit2['field_name'] = 'title';
$bundle_path = 'admin/structure/types/manage/' . $this->contentType;
$this->drupalGet("{$bundle_path}/fields/add-field");
$this->submitForm($edit1, 'Continue');
$this->submitForm($edit2, 'Continue');
$this->assertSession()
->pageTextContains('The machine-readable name is already in use. It must be unique.');
// Try with a base field.
$edit2['field_name'] = 'sticky';
$bundle_path = 'admin/structure/types/manage/' . $this->contentType;
$this->drupalGet("{$bundle_path}/fields/add-field");
$this->submitForm($edit1, 'Continue');
$this->submitForm($edit2, 'Continue');
$this->assertSession()
->pageTextContains('The machine-readable name is already in use. It must be unique.');
$this->assertSession()
->addressEquals($url);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.