function NodeAccessFieldTest::testNodeAccessAdministerField

Tests administering fields when node access is restricted.

File

drupal/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php, line 53
Definition of Drupal\node\Tests\NodeAccessFieldTest.

Class

NodeAccessFieldTest
Tests the interaction of the node access system with fields.

Namespace

Drupal\node\Tests

Code

function testNodeAccessAdministerField() {

  // Create a page node.
  $langcode = LANGUAGE_NOT_SPECIFIED;
  $field_data = array();
  $value = $field_data[$langcode][0]['value'] = $this
    ->randomName();
  $node = $this
    ->drupalCreateNode(array(
    $this->field_name => $field_data,
  ));

  // Log in as the administrator and confirm that the field value is present.
  $this
    ->drupalLogin($this->admin_user);
  $this
    ->drupalGet("node/{$node->nid}");
  $this
    ->assertText($value, 'The saved field value is visible to an administrator.');

  // Log in as the content admin and try to view the node.
  $this
    ->drupalLogin($this->content_admin_user);
  $this
    ->drupalGet("node/{$node->nid}");
  $this
    ->assertText('Access denied', 'Access is denied for the content admin.');

  // Modify the field default as the content admin.
  $edit = array();
  $default = 'Sometimes words have two meanings';
  $edit["{$this->field_name}[{$langcode}][0][value]"] = $default;
  $this
    ->drupalPost("admin/structure/types/manage/page/fields/{$this->field_name}", $edit, t('Save settings'));

  // Log in as the administrator.
  $this
    ->drupalLogin($this->admin_user);

  // Confirm that the existing node still has the correct field value.
  $this
    ->drupalGet("node/{$node->nid}");
  $this
    ->assertText($value, 'The original field value is visible to an administrator.');

  // Confirm that the new default value appears when creating a new node.
  $this
    ->drupalGet('node/add/page');
  $this
    ->assertRaw($default, 'The updated default value is displayed when creating a new node.');
}