Chris@0: adminUser = $this->drupalCreateUser(['access content', 'bypass node access']); Chris@0: $this->contentAdminUser = $this->drupalCreateUser(['access content', 'administer content types', 'administer node fields']); Chris@0: Chris@0: // Add a custom field to the page content type. Chris@17: $this->fieldName = mb_strtolower($this->randomMachineName() . '_field_name'); Chris@0: FieldStorageConfig::create([ Chris@0: 'field_name' => $this->fieldName, Chris@0: 'entity_type' => 'node', Chris@17: 'type' => 'text', Chris@0: ])->save(); Chris@0: FieldConfig::create([ Chris@0: 'field_name' => $this->fieldName, Chris@0: 'entity_type' => 'node', Chris@0: 'bundle' => 'page', Chris@0: ])->save(); Chris@0: entity_get_display('node', 'page', 'default') Chris@0: ->setComponent($this->fieldName) Chris@0: ->save(); Chris@0: entity_get_form_display('node', 'page', 'default') Chris@0: ->setComponent($this->fieldName) Chris@0: ->save(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests administering fields when node access is restricted. Chris@0: */ Chris@0: public function testNodeAccessAdministerField() { Chris@0: // Create a page node. Chris@0: $fieldData = []; Chris@0: $value = $fieldData[0]['value'] = $this->randomMachineName(); Chris@0: $node = $this->drupalCreateNode([$this->fieldName => $fieldData]); Chris@0: Chris@0: // Log in as the administrator and confirm that the field value is present. Chris@0: $this->drupalLogin($this->adminUser); Chris@0: $this->drupalGet('node/' . $node->id()); Chris@0: $this->assertText($value, 'The saved field value is visible to an administrator.'); Chris@0: Chris@0: // Log in as the content admin and try to view the node. Chris@0: $this->drupalLogin($this->contentAdminUser); Chris@0: $this->drupalGet('node/' . $node->id()); Chris@0: $this->assertText('Access denied', 'Access is denied for the content admin.'); Chris@0: Chris@0: // Modify the field default as the content admin. Chris@0: $edit = []; Chris@0: $default = 'Sometimes words have two meanings'; Chris@0: $edit["default_value_input[{$this->fieldName}][0][value]"] = $default; Chris@0: $this->drupalPostForm( Chris@0: "admin/structure/types/manage/page/fields/node.page.{$this->fieldName}", Chris@0: $edit, Chris@0: t('Save settings') Chris@0: ); Chris@0: Chris@0: // Log in as the administrator. Chris@0: $this->drupalLogin($this->adminUser); Chris@0: Chris@0: // Confirm that the existing node still has the correct field value. Chris@0: $this->drupalGet('node/' . $node->id()); Chris@0: $this->assertText($value, 'The original field value is visible to an administrator.'); Chris@0: Chris@0: // Confirm that the new default value appears when creating a new node. Chris@0: $this->drupalGet('node/add/page'); Chris@0: $this->assertRaw($default, 'The updated default value is displayed when creating a new node.'); Chris@0: } Chris@0: Chris@0: }