You are here

protected function VersionNegotiatorTest::setUp in JSON:API 8.2

Initialization tasks for the test.

@inheritdoc

Overrides KernelTestBase::setUp

File

tests/src/Kernel/Revisions/VersionNegotiatorTest.php, line 74

Class

VersionNegotiatorTest
The test class for version negotiators.

Namespace

Drupal\Tests\jsonapi\Kernel\Revisions

Code

protected function setUp() {
  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;
}