function NodeAccessFieldTest::testNodeAccessAdministerField in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/node/src/Tests/NodeAccessFieldTest.php \Drupal\node\Tests\NodeAccessFieldTest::testNodeAccessAdministerField()
Tests administering fields when node access is restricted.
File
- core/
modules/ node/ src/ Tests/ NodeAccessFieldTest.php, line 78 - Contains \Drupal\node\Tests\NodeAccessFieldTest.
Class
- NodeAccessFieldTest
- Tests the interaction of the node access system with fields.
Namespace
Drupal\node\TestsCode
function testNodeAccessAdministerField() {
// Create a page node.
$fieldData = array();
$value = $fieldData[0]['value'] = $this
->randomMachineName();
$node = $this
->drupalCreateNode(array(
$this->fieldName => $fieldData,
));
// Log in as the administrator and confirm that the field value is present.
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('node/' . $node
->id());
$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->contentAdminUser);
$this
->drupalGet('node/' . $node
->id());
$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["default_value_input[{$this->fieldName}][0][value]"] = $default;
$this
->drupalPostForm("admin/structure/types/manage/page/fields/node.page.{$this->fieldName}", $edit, t('Save settings'));
// Log in as the administrator.
$this
->drupalLogin($this->adminUser);
// Confirm that the existing node still has the correct field value.
$this
->drupalGet('node/' . $node
->id());
$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.');
}