X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fnode%2Ftests%2Fsrc%2FFunctional%2FNodeAccessFieldTest.php;fp=web%2Fcore%2Fmodules%2Fnode%2Ftests%2Fsrc%2FFunctional%2FNodeAccessFieldTest.php;h=082f288c688947f9381e3a82846792fc4b63a5a5;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/node/tests/src/Functional/NodeAccessFieldTest.php b/web/core/modules/node/tests/src/Functional/NodeAccessFieldTest.php new file mode 100644 index 000000000..082f288c6 --- /dev/null +++ b/web/core/modules/node/tests/src/Functional/NodeAccessFieldTest.php @@ -0,0 +1,113 @@ +adminUser = $this->drupalCreateUser(['access content', 'bypass node access']); + $this->contentAdminUser = $this->drupalCreateUser(['access content', 'administer content types', 'administer node fields']); + + // Add a custom field to the page content type. + $this->fieldName = Unicode::strtolower($this->randomMachineName() . '_field_name'); + FieldStorageConfig::create([ + 'field_name' => $this->fieldName, + 'entity_type' => 'node', + 'type' => 'text' + ])->save(); + FieldConfig::create([ + 'field_name' => $this->fieldName, + 'entity_type' => 'node', + 'bundle' => 'page', + ])->save(); + entity_get_display('node', 'page', 'default') + ->setComponent($this->fieldName) + ->save(); + entity_get_form_display('node', 'page', 'default') + ->setComponent($this->fieldName) + ->save(); + } + + /** + * Tests administering fields when node access is restricted. + */ + public function testNodeAccessAdministerField() { + // Create a page node. + $fieldData = []; + $value = $fieldData[0]['value'] = $this->randomMachineName(); + $node = $this->drupalCreateNode([$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 = []; + $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.'); + } + +}