function ManageFieldsFunctionalTest::testFieldPrefix

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

Tests that the 'field_prefix' setting works on Field UI.

File

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

Class

ManageFieldsFunctionalTest
Tests the Field UI "Manage fields" screen.

Namespace

Drupal\Tests\field_ui\Functional

Code

public function testFieldPrefix() {
    // Change default field prefix.
    $field_prefix = strtolower($this->randomMachineName(10));
    $this->config('field_ui.settings')
        ->set('field_prefix', $field_prefix)
        ->save();
    // Create a field input and label exceeding the new maxlength, which is 22.
    $field_exceed_max_length_label = $this->randomString(23);
    $field_exceed_max_length_input = $this->randomMachineName(23);
    // Try to create the field.
    $edit = [
        'label' => $field_exceed_max_length_label,
        'field_name' => $field_exceed_max_length_input,
    ];
    $this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/add-field');
    $this->submitForm($edit, 'Save and continue');
    $this->assertSession()
        ->pageTextContains('Machine-readable name cannot be longer than 22 characters but is currently 23 characters long.');
    // Create a valid field.
    $this->fieldUIAddNewField('admin/structure/types/manage/' . $this->contentType, $this->fieldNameInput, $this->fieldLabel);
    $this->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/node.' . $this->contentType . '.' . $field_prefix . $this->fieldNameInput);
    $this->assertSession()
        ->pageTextContains($this->fieldLabel . ' settings for ' . $this->contentType);
}

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