function ManageFieldsFunctionalTest::testDisallowedFieldNames

Same name in other branches
  1. 8.9.x core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsFunctionalTest::testDisallowedFieldNames()

Tests that Field UI respects disallowed field names.

File

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

Class

ManageFieldsFunctionalTest
Tests the Field UI "Manage fields" screen.

Namespace

Drupal\Tests\field_ui\Functional

Code

public function testDisallowedFieldNames() {
    // Reset the field prefix so we can test properly.
    $this->config('field_ui.settings')
        ->set('field_prefix', '')
        ->save();
    $label = 'Disallowed field';
    $edit = [
        'label' => $label,
        'new_storage_type' => 'test_field',
    ];
    // Try with an entity key.
    $edit['field_name'] = 'title';
    $bundle_path = 'admin/structure/types/manage/' . $this->contentType;
    $this->drupalGet("{$bundle_path}/fields/add-field");
    $this->submitForm($edit, 'Save and continue');
    $this->assertSession()
        ->pageTextContains('The machine-readable name is already in use. It must be unique.');
    // Try with a base field.
    $edit['field_name'] = 'sticky';
    $bundle_path = 'admin/structure/types/manage/' . $this->contentType;
    $this->drupalGet("{$bundle_path}/fields/add-field");
    $this->submitForm($edit, 'Save and continue');
    $this->assertSession()
        ->pageTextContains('The machine-readable name is already in use. It must be unique.');
}

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