You are here

protected function NodeAccessFieldTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 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\Functional

Code

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();
}