function WorkspaceAssociationTest::assertWorkspaceAssociations

Same name in other branches
  1. 11.x core/modules/workspaces/tests/src/Kernel/WorkspaceAssociationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceAssociationTest::assertWorkspaceAssociations()

Checks the workspace associations for a test scenario.

Parameters

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

array $expected_latest_revisions: An array of expected values for the latest tracked revisions.

array $expected_all_revisions: An array of expected values for all the tracked revisions.

array $expected_initial_revisions: An array of expected values for the initial revisions, i.e. for the entities that were created in the specified workspace.

1 call to WorkspaceAssociationTest::assertWorkspaceAssociations()
WorkspaceAssociationTest::testWorkspaceAssociation in core/modules/workspaces/tests/src/Kernel/WorkspaceAssociationTest.php
Tests the revisions tracked by a workspace.

File

core/modules/workspaces/tests/src/Kernel/WorkspaceAssociationTest.php, line 182

Class

WorkspaceAssociationTest
Tests workspace associations.

Namespace

Drupal\Tests\workspaces\Kernel

Code

protected function assertWorkspaceAssociations($entity_type_id, array $expected_latest_revisions, array $expected_all_revisions, array $expected_initial_revisions) {
    $workspace_association = \Drupal::service('workspaces.association');
    foreach ($expected_latest_revisions as $workspace_id => $expected_tracked_revision_ids) {
        $tracked_entities = $workspace_association->getTrackedEntities($workspace_id, $entity_type_id);
        $tracked_revision_ids = $tracked_entities[$entity_type_id] ?? [];
        $this->assertEquals($expected_tracked_revision_ids, array_keys($tracked_revision_ids));
    }
    foreach ($expected_all_revisions as $workspace_id => $expected_all_revision_ids) {
        $all_associated_revisions = $workspace_association->getAssociatedRevisions($workspace_id, $entity_type_id);
        $this->assertEquals($expected_all_revision_ids, array_keys($all_associated_revisions));
    }
    foreach ($expected_initial_revisions as $workspace_id => $expected_initial_revision_ids) {
        $initial_revisions = $workspace_association->getAssociatedInitialRevisions($workspace_id, $entity_type_id);
        $this->assertEquals($expected_initial_revision_ids, array_keys($initial_revisions));
    }
}

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