You are here

function ManageFieldsTest::testLockedField in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/field_ui/src/Tests/ManageFieldsTest.php \Drupal\field_ui\Tests\ManageFieldsTest::testLockedField()

Tests that Field UI respects locked fields.

File

core/modules/field_ui/src/Tests/ManageFieldsTest.php, line 508
Contains \Drupal\field_ui\Tests\ManageFieldsTest.

Class

ManageFieldsTest
Tests the Field UI "Manage fields" screen.

Namespace

Drupal\field_ui\Tests

Code

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(array(
    'field_name' => $field_name,
    'entity_type' => 'node',
    'type' => 'test_field',
    'cardinality' => 1,
    'locked' => TRUE,
  ));
  $field_storage
    ->save();
  FieldConfig::create(array(
    'field_storage' => $field_storage,
    'bundle' => $this->contentType,
  ))
    ->save();
  entity_get_form_display('node', $this->contentType, 'default')
    ->setComponent($field_name, array(
    '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]', array(
    ':field_name' => $field_name,
  ));
  $this
    ->assertTrue(in_array('Locked', $locked), 'Field is marked as Locked in the UI');
  $edit_link = $this
    ->xpath('//tr[@id=:field_name]/td[4]', array(
    ':field_name' => $field_name,
  ));
  $this
    ->assertFalse(in_array('edit', $edit_link), 'Edit option for locked field is not present the UI');
  $delete_link = $this
    ->xpath('//tr[@id=:field_name]/td[4]', array(
    ':field_name' => $field_name,
  ));
  $this
    ->assertFalse(in_array('delete', $delete_link), 'Delete option for locked field is not present the UI');
  $this
    ->drupalGet('admin/structure/types/manage/' . $this->contentType . '/fields/node.' . $this->contentType . '.' . $field_name . '/delete');
  $this
    ->assertResponse(403);
}