protected function NodeAccessFieldTest::setUp in Drupal 10
Same name and namespace in other branches
- 8 core/modules/node/tests/src/Functional/NodeAccessFieldTest.php \Drupal\Tests\node\Functional\NodeAccessFieldTest::setUp()
- 9 core/modules/node/tests/src/Functional/NodeAccessFieldTest.php \Drupal\Tests\node\Functional\NodeAccessFieldTest::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() : void {
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();
}