function NodeAccessFieldTest::setUp
Same name in other branches
- 9 core/modules/node/tests/src/Functional/NodeAccessFieldTest.php \Drupal\Tests\node\Functional\NodeAccessFieldTest::setUp()
- 10 core/modules/node/tests/src/Functional/NodeAccessFieldTest.php \Drupal\Tests\node\Functional\NodeAccessFieldTest::setUp()
- 11.x core/modules/node/tests/src/Functional/NodeAccessFieldTest.php \Drupal\Tests\node\Functional\NodeAccessFieldTest::setUp()
Overrides NodeTestBase::setUp
File
-
core/
modules/ node/ tests/ src/ Functional/ NodeAccessFieldTest.php, line 48
Class
- NodeAccessFieldTest
- Tests the interaction of the node access system with fields.
Namespace
Drupal\Tests\node\FunctionalCode
protected function setUp() {
parent::setUp();
node_access_rebuild();
// Create some users.
$this->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 = mb_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();
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
$display_repository = \Drupal::service('entity_display.repository');
$display_repository->getViewDisplay('node', 'page')
->setComponent($this->fieldName)
->save();
$display_repository->getFormDisplay('node', 'page')
->setComponent($this->fieldName)
->save();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.