function WorkspaceTrackerTest::testMoveTrackedEntitiesOfSpecificType
Same name and namespace in other branches
- main core/modules/workspaces/tests/src/Kernel/WorkspaceTrackerTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceTrackerTest::testMoveTrackedEntitiesOfSpecificType()
Tests moving all entities of a specific type while leaving others.
File
-
core/
modules/ workspaces/ tests/ src/ Kernel/ WorkspaceTrackerTest.php, line 305
Class
- WorkspaceTrackerTest
- Tests workspace tracker.
Namespace
Drupal\Tests\workspaces\KernelCode
public function testMoveTrackedEntitiesOfSpecificType() : void {
$entity_type_id = 'entity_test_mulrevpub';
$entity_type_id_string = 'entity_test_mulrevpub_string_id';
/** @var \Drupal\workspaces\WorkspaceTrackerInterface $workspace_tracker */
$workspace_tracker = \Drupal::service('workspaces.tracker');
// Get the workspace field name for later assertions.
$entity_type_string_id = $this->entityTypeManager
->getDefinition($entity_type_id_string);
$workspace_field_string_id = $entity_type_string_id->getRevisionMetadataKey('workspace');
$storage_string_id = $this->entityTypeManager
->getStorage($entity_type_id_string);
// Create entities of different types in 'preview'.
$this->switchToWorkspace('preview');
$this->createEntity($entity_type_id, [
'name' => 'Integer entity 1',
]);
$this->createEntity($entity_type_id, [
'name' => 'Integer entity 2',
]);
$entity_string_1 = $this->createEntity($entity_type_id_string, [
'id' => 'str_1',
'name' => 'String entity 1',
]);
$entity_string_2 = $this->createEntity($entity_type_id_string, [
'id' => 'str_2',
'name' => 'String entity 2',
]);
// Move only the integer ID entities to 'qa'.
$workspace_tracker->moveTrackedEntities('preview', 'qa', $entity_type_id);
// Verify integer ID entities were moved.
$this->assertEmpty($workspace_tracker->getTrackedEntities('preview', $entity_type_id)[$entity_type_id] ?? []);
$this->assertCount(2, $workspace_tracker->getTrackedEntities('qa', $entity_type_id)[$entity_type_id]);
// Verify string ID entities remain in 'preview'.
$this->assertCount(2, $workspace_tracker->getTrackedEntities('preview', $entity_type_id_string)[$entity_type_id_string]);
$this->assertEmpty($workspace_tracker->getTrackedEntities('qa', $entity_type_id_string)[$entity_type_id_string] ?? []);
$preview_string_entities = $workspace_tracker->getTrackedEntities('preview', $entity_type_id_string);
$this->assertContains($entity_string_1->id(), $preview_string_entities[$entity_type_id_string] ?? []);
$this->assertContains($entity_string_2->id(), $preview_string_entities[$entity_type_id_string] ?? []);
// Verify string entities workspace field is still 'preview'.
$string_revision = $storage_string_id->loadRevision($entity_string_1->getRevisionId());
$this->assertEquals('preview', $string_revision->{$workspace_field_string_id}->target_id);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.