function WorkspaceAssociationTest::testMoveTrackedEntitiesWithMultipleRevisions
Tests moving an entity with multiple revisions between workspaces.
@legacy-covers ::moveTrackedEntities
File
-
core/
modules/ workspaces/ tests/ src/ Kernel/ WorkspaceAssociationTest.php, line 267
Class
- WorkspaceAssociationTest
- Tests workspace associations.
Namespace
Drupal\Tests\workspaces\KernelCode
public function testMoveTrackedEntitiesWithMultipleRevisions() : void {
$entity_type_id = 'entity_test_mulrevpub';
$workspace_association = \Drupal::service('workspaces.association');
// Get the workspace field name for later assertions.
$entity_type = $this->entityTypeManager
->getDefinition($entity_type_id);
assert($entity_type instanceof ContentEntityTypeInterface);
$workspace_field = $entity_type->getRevisionMetadataKey('workspace');
$storage = $this->entityTypeManager
->getStorage($entity_type_id);
// Create an entity with multiple revisions in 'preview'.
$this->switchToWorkspace('preview');
$entity = $this->createEntity($entity_type_id, [
'name' => 'Entity with revisions',
]);
$entity->setName('Updated name 1');
$entity->save();
$entity->setName('Updated name 2');
$entity->save();
$preview_revisions = $workspace_association->getAssociatedRevisions('preview', $entity_type_id);
// Move the entity to 'qa'.
$workspace_association->moveTrackedEntities('preview', 'qa', $entity_type_id, [
$entity->id(),
]);
// Verify all revisions have been moved.
$this->assertEmpty($workspace_association->getAssociatedRevisions('preview', $entity_type_id));
$qa_revisions = $workspace_association->getAssociatedRevisions('qa', $entity_type_id);
$this->assertEquals($preview_revisions, $qa_revisions);
// Verify the workspace field was updated on all revisions.
foreach ($storage->loadMultipleRevisions(array_keys($qa_revisions)) as $revision) {
$this->assertEquals('qa', $revision->{$workspace_field}->target_id);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.