function WorkspaceInformationTest::testCustomSupportEntityTypes
Same name in other branches
- 11.x core/modules/workspaces/tests/src/Kernel/WorkspaceInformationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceInformationTest::testCustomSupportEntityTypes()
Tests an entity type with a custom workspace handler.
File
-
core/
modules/ workspaces/ tests/ src/ Kernel/ WorkspaceInformationTest.php, line 101
Class
- WorkspaceInformationTest
- Tests the workspace information service.
Namespace
Drupal\Tests\workspaces\KernelCode
public function testCustomSupportEntityTypes() : void {
$entity_type = clone $this->entityTypeManager
->getDefinition('entity_test_revpub');
$entity_type->setHandlerClass('workspace', EntityTestRevPubWorkspaceHandler::class);
$this->state
->set('entity_test_revpub.entity_type', $entity_type);
$this->entityTypeManager
->clearCachedDefinitions();
$entity = $this->entityTypeManager
->getStorage('entity_test_revpub')
->create([
'type' => 'supported_bundle',
]);
$this->assertTrue($this->workspaceInformation
->isEntitySupported($entity));
$this->assertTrue($this->workspaceInformation
->isEntityTypeSupported($entity->getEntityType()));
$this->assertFalse($this->workspaceInformation
->isEntityIgnored($entity));
$this->assertFalse($this->workspaceInformation
->isEntityTypeIgnored($entity->getEntityType()));
// Check that supported entity types are tracked in a workspace. This entity
// is published by default, so the second revision will be tracked.
$entity->save();
$this->assertWorkspaceAssociation([
'stage' => [
2,
],
], 'entity_test_revpub');
$entity = $this->entityTypeManager
->getStorage('entity_test_revpub')
->create([
'type' => 'ignored_bundle',
]);
$this->assertFalse($this->workspaceInformation
->isEntitySupported($entity));
$this->assertTrue($this->workspaceInformation
->isEntityTypeSupported($entity->getEntityType()));
$this->assertTrue($this->workspaceInformation
->isEntityIgnored($entity));
$this->assertFalse($this->workspaceInformation
->isEntityTypeIgnored($entity->getEntityType()));
// Check that an ignored entity can be saved, but won't be tracked.
$entity->save();
$this->assertWorkspaceAssociation([
'stage' => [
2,
],
], 'entity_test_revpub');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.