You are here

protected function DeleteActionTest::setUp in Entity Reference Integrity 8

Overrides KernelTestBase::setUp

File

modules/entity_reference_integrity_enforce/tests/src/Kernel/DeleteActionTest.php, line 74

Class

DeleteActionTest
Test behavior of the DeleteAction plugin.

Namespace

Drupal\Tests\entity_reference_integrity_enforce\Kernel

Code

protected function setUp() : void {
  parent::setUp();
  $this
    ->installEntitySchema('node');
  $this
    ->installEntitySchema('user');
  $this
    ->installSchema('system', [
    'sequences',
  ]);
  $this
    ->installSchema('node', [
    'node_access',
  ]);
  $this->actionManager = $this->container
    ->get('plugin.manager.action');
  $this->dependencyManager = $this->container
    ->get('entity_reference_integrity.dependency_manager');

  // Create a new node-type.
  NodeType::create([
    'type' => $node_type = mb_strtolower($this
      ->randomMachineName()),
    'name' => $this
      ->randomString(),
  ])
    ->save();

  // Create an entity reference field to test with.
  $this
    ->createEntityReferenceField('node', $node_type, 'test_reference_field', 'Test reference field', 'node');

  // Create testing nodes.
  $this->referencedNode = Node::create([
    'title' => 'Node to delete',
    'type' => $node_type,
  ]);
  $this->referencedNode
    ->save();
  $this->testNode = Node::create([
    'title' => 'Referenced node',
    'type' => $node_type,
    'test_reference_field' => [
      'entity' => $this->referencedNode,
    ],
  ]);
  $this->testNode
    ->save();

  // Enable reference integrity for nodes.
  \Drupal::configFactory()
    ->getEditable('entity_reference_integrity_enforce.settings')
    ->set('enabled_entity_type_ids', [
    'node' => 'node',
  ])
    ->save();

  // A test user is required for testing access.
  $this->testUser = User::create([
    'name' => 'Gerald',
  ]);
  $this->testUser
    ->save();
  \Drupal::service('current_user')
    ->setAccount($this->testUser);
}