You are here

protected function WorkspaceIntegrationTest::assertEntityLoad in Workspace 8.2

Asserts that default revisions are properly swapped in a workspace.

Parameters

array $expected_values: An array of expected values, as defined in ::testWorkspaces().

string $entity_type_id: The ID of the entity type to check.

1 call to WorkspaceIntegrationTest::assertEntityLoad()
WorkspaceIntegrationTest::assertWorkspaceStatus in tests/src/Kernel/WorkspaceIntegrationTest.php
Checks entity load, entity queries and views results for a test scenario.

File

tests/src/Kernel/WorkspaceIntegrationTest.php, line 510

Class

WorkspaceIntegrationTest
Tests a complete deployment scenario across different workspaces.

Namespace

Drupal\Tests\workspace\Kernel

Code

protected function assertEntityLoad(array $expected_values, $entity_type_id) {

  // Filter the expected values so we can check only the default revisions.
  $expected_default_revisions = array_filter($expected_values, function ($expected_value) {
    return $expected_value['default_revision'] === TRUE;
  });
  $entity_keys = $this->entityTypeManager
    ->getDefinition($entity_type_id)
    ->getKeys();
  $id_key = $entity_keys['id'];
  $revision_key = $entity_keys['revision'];
  $label_key = $entity_keys['label'];
  $published_key = $entity_keys['published'];

  // Check \Drupal\Core\Entity\EntityStorageInterface::loadMultiple().

  /** @var \Drupal\Core\Entity\EntityInterface[]|\Drupal\Core\Entity\RevisionableInterface[]|\Drupal\Core\Entity\EntityPublishedInterface[] $entities */
  $entities = $this->entityTypeManager
    ->getStorage($entity_type_id)
    ->loadMultiple(array_column($expected_default_revisions, $id_key));
  foreach ($expected_default_revisions as $expected_default_revision) {
    $entity_id = $expected_default_revision[$id_key];
    $this
      ->assertEquals($expected_default_revision[$revision_key], $entities[$entity_id]
      ->getRevisionId());
    $this
      ->assertEquals($expected_default_revision[$label_key], $entities[$entity_id]
      ->label());
    $this
      ->assertEquals($expected_default_revision[$published_key], $entities[$entity_id]
      ->isPublished());
  }

  // Check \Drupal\Core\Entity\EntityStorageInterface::loadUnchanged().
  foreach ($expected_default_revisions as $expected_default_revision) {

    /** @var \Drupal\Core\Entity\EntityInterface|\Drupal\Core\Entity\RevisionableInterface|\Drupal\Core\Entity\EntityPublishedInterface $entity */
    $entity = $this->entityTypeManager
      ->getStorage($entity_type_id)
      ->loadUnchanged($expected_default_revision[$id_key]);
    $this
      ->assertEquals($expected_default_revision[$revision_key], $entity
      ->getRevisionId());
    $this
      ->assertEquals($expected_default_revision[$label_key], $entity
      ->label());
    $this
      ->assertEquals($expected_default_revision[$published_key], $entity
      ->isPublished());
  }
}