function WorkspaceIntegrationTest::flattenExpectedValues

Same name and namespace in other branches
  1. 11.x core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::flattenExpectedValues()
  2. 10 core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::flattenExpectedValues()
  3. 8.9.x core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::flattenExpectedValues()

Flattens the expectations array defined by testWorkspaces().

Parameters

array $expected: An array as defined by testWorkspaces().

string $entity_type_id: The ID of the entity type that is being tested.

Return value

array An array where all the entity IDs and revision IDs are merged inside each expected values array.

File

core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php, line 976

Class

WorkspaceIntegrationTest
Tests a complete publishing scenario across different workspaces.

Namespace

Drupal\Tests\workspaces\Kernel

Code

protected function flattenExpectedValues(array $expected, $entity_type_id) {
  $flattened = [];
  $entity_keys = $this->entityTypeManager
    ->getDefinition($entity_type_id)
    ->getKeys();
  foreach ($expected as $workspace_id => $workspace_values) {
    foreach ($workspace_values as $entity_id => $entity_revisions) {
      foreach ($entity_revisions as $revision_id => $revision_values) {
        $flattened[$workspace_id][] = [
          $entity_keys['id'] => $entity_id,
          $entity_keys['revision'] => $revision_id,
        ] + $revision_values;
      }
    }
  }
  return $flattened;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.