You are here

protected function VersionNegotiatorTest::setUp in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/tests/src/Kernel/Revisions/VersionNegotiatorTest.php \Drupal\Tests\jsonapi\Kernel\Revisions\VersionNegotiatorTest::setUp()
  2. 9 core/modules/jsonapi/tests/src/Kernel/Revisions/VersionNegotiatorTest.php \Drupal\Tests\jsonapi\Kernel\Revisions\VersionNegotiatorTest::setUp()

Overrides KernelTestBase::setUp

File

core/modules/jsonapi/tests/src/Kernel/Revisions/VersionNegotiatorTest.php, line 72

Class

VersionNegotiatorTest
The test class for version negotiators.

Namespace

Drupal\Tests\jsonapi\Kernel\Revisions

Code

protected function setUp() : void {
  parent::setUp();

  // Add the entity schemas.
  $this
    ->installEntitySchema('node');
  $this
    ->installEntitySchema('user');

  // Add the additional table schemas.
  $this
    ->installSchema('system', [
    'sequences',
  ]);
  $this
    ->installSchema('node', [
    'node_access',
  ]);
  $this
    ->installSchema('user', [
    'users_data',
  ]);
  $type = NodeType::create([
    'type' => 'dummy',
    'new_revision' => TRUE,
  ]);
  $type
    ->save();
  $this->user = User::create([
    'name' => 'user1',
    'mail' => 'user@localhost',
    'status' => 1,
  ]);
  $this->user
    ->save();
  $this->node = Node::create([
    'title' => 'dummy_title',
    'type' => 'dummy',
    'uid' => $this->user
      ->id(),
  ]);
  $this->node
    ->save();
  $this->nodePreviousRevisionId = $this->node
    ->getRevisionId();
  $this->node
    ->setNewRevision();
  $this->node
    ->setTitle('revised_dummy_title');
  $this->node
    ->save();
  $this->node2 = Node::create([
    'type' => 'dummy',
    'title' => 'Another test node',
    'uid' => $this->user
      ->id(),
  ]);
  $this->node2
    ->save();
  $entity_type_manager = \Drupal::entityTypeManager();
  $version_negotiator = new VersionNegotiator();
  $version_negotiator
    ->addVersionNegotiator(new VersionById($entity_type_manager), 'id');
  $version_negotiator
    ->addVersionNegotiator(new VersionByRel($entity_type_manager), 'rel');
  $this->versionNegotiator = $version_negotiator;
}