You are here

public function ManageFieldsFunctionalTest::testLockedField in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsFunctionalTest::testLockedField()
  2. 10 core/modules/field_ui/tests/src/Functional/ManageFieldsFunctionalTest.php \Drupal\Tests\field_ui\Functional\ManageFieldsFunctionalTest::testLockedField()

Tests that Field UI respects locked fields.

File

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

Class

ManageFieldsFunctionalTest
Tests the Field UI "Manage fields" screen.

Namespace

Drupal\Tests\field_ui\Functional

Code

public function testLockedField() {

  // Create a locked field and attach it to a bundle. We need to do this
  // programmatically as there's no way to create a locked field through UI.
  $field_name = strtolower($this
    ->randomMachineName(8));
  $field_storage = FieldStorageConfig::create([
    'field_name' => $field_name,
    'entity_type' => 'node',
    'type' => 'test_field',
    'cardinality' => 1,
    'locked' => TRUE,
  ]);
  $field_storage
    ->save();
  FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => $this->contentType,
  ])
    ->save();
  \Drupal::service('entity_display.repository')
    ->getFormDisplay('node', $this->contentType)
    ->setComponent($field_name, [
    'type' => 'test_field_widget',
  ])
    ->save();

  // Check that the links for edit and delete are not present.
  $this
    ->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields');
  $locked = $this
    ->xpath('//tr[@id=:field_name]/td[4]', [
    ':field_name' => $field_name,
  ]);
  $this
    ->assertSame('Locked', $locked[0]
    ->getHtml(), 'Field is marked as Locked in the UI');
  $this
    ->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/node.' . $this->contentType . '.' . $field_name . '/delete');
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}