You are here

public function EntityLoadingTest::testLoadingEntities in Multiversion 8

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/EntityLoadingTest.php \Drupal\Tests\multiversion\Kernel\EntityLoadingTest::testLoadingEntities()

Tests loading entities.

File

tests/src/Kernel/EntityLoadingTest.php, line 39

Class

EntityLoadingTest
@group multiversion

Namespace

Drupal\Tests\multiversion\Kernel

Code

public function testLoadingEntities() {
  $un_workspace = Workspace::create([
    'type' => 'test',
    'machine_name' => 'un_workspace',
    'label' => 'Un Workspace',
  ]);
  $un_workspace
    ->save();
  $dau_workspace = Workspace::create([
    'type' => 'test',
    'machine_name' => 'dau_workspace',
    'label' => 'Dau Workspace',
  ]);
  $dau_workspace
    ->save();
  $workspace_manager = \Drupal::service('workspace.manager');
  $this
    ->assertEquals($un_workspace
    ->id(), $workspace_manager
    ->getActiveWorkspaceId());
  $node_type = NodeType::create([
    'type' => 'example',
  ]);
  $node_type
    ->save();
  $node = Node::create([
    'type' => 'example',
    'title' => 'Test title',
  ]);
  $node
    ->save();
  $this
    ->assertEquals($un_workspace
    ->id(), $node->workspace->target_id);
  $node2 = Node::create([
    'type' => 'example',
    'title' => 'Test title',
    'workspace' => $dau_workspace
      ->id(),
  ]);
  $node2
    ->save();
  $this
    ->assertEquals($dau_workspace
    ->id(), $node2->workspace->target_id);
  $storage = \Drupal::entityTypeManager()
    ->getStorage('node');
  $entities = $storage
    ->loadMultiple();
  $this
    ->assertEquals(1, count($entities));
  $this
    ->assertEquals($node
    ->id(), reset($entities)
    ->id());
  $results = $storage
    ->getQuery()
    ->execute();
  $this
    ->assertEquals(1, count($results));
  $this
    ->assertEquals($node
    ->id(), reset($results));
}