function WorkspaceIntegrationTest::testWorkspaceHierarchy
Same name in other branches
- 8.9.x core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::testWorkspaceHierarchy()
- 10 core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::testWorkspaceHierarchy()
- 11.x core/modules/workspaces/tests/src/Kernel/WorkspaceIntegrationTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceIntegrationTest::testWorkspaceHierarchy()
Tests entity tracking in workspace descendants.
File
-
core/
modules/ workspaces/ tests/ src/ Kernel/ WorkspaceIntegrationTest.php, line 373
Class
- WorkspaceIntegrationTest
- Tests a complete publishing scenario across different workspaces.
Namespace
Drupal\Tests\workspaces\KernelCode
public function testWorkspaceHierarchy() {
$this->initializeWorkspacesModule();
$this->createWorkspaceHierarchy();
// The two pre-existing nodes are not overridden in any non-default
// workspace.
$expected_workspace_association = [
'stage' => [],
'dev' => [],
'local_1' => [],
'local_2' => [],
'qa' => [],
];
$this->assertWorkspaceAssociation($expected_workspace_association, 'node');
// Create a new revision for a node in 'stage' and check that it's tracked
// in all descendants.
$this->switchToWorkspace('stage');
$node = $this->entityTypeManager
->getStorage('node')
->load(1);
$node->setTitle('stage - 1 - r3');
$node->save();
$expected_workspace_association = [
'stage' => [
3,
],
'dev' => [
3,
],
'local_1' => [
3,
],
'local_2' => [
3,
],
'qa' => [],
];
$this->assertWorkspaceAssociation($expected_workspace_association, 'node');
// Create a new published node in 'stage' (which creates two revisions), and
// check that it's tracked in all its descendants.
$this->switchToWorkspace('stage');
$this->createNode([
'title' => 'stage - 3 - r5 - published',
'created' => $this->createdTimestamp++,
'status' => TRUE,
]);
$expected_workspace_association = [
'stage' => [
3,
5,
],
'dev' => [
3,
5,
],
'local_1' => [
3,
5,
],
'local_2' => [
3,
5,
],
'qa' => [],
];
$this->assertWorkspaceAssociation($expected_workspace_association, 'node');
// Create a new revision in `dev` and check that it's also tracked in
// 'local_1' and 'local_2'.
$this->switchToWorkspace('dev');
$node = $this->entityTypeManager
->getStorage('node')
->load(1);
$node->setTitle('dev - 1 - r6');
$node->save();
$expected_workspace_association = [
'stage' => [
3,
5,
],
'dev' => [
5,
6,
],
'local_1' => [
5,
6,
],
'local_2' => [
5,
6,
],
'qa' => [],
];
$this->assertWorkspaceAssociation($expected_workspace_association, 'node');
// Create a new revision in 'local_1', then a different one in 'dev', which
// should only be tracked in `dev` and 'local_2', because 'local_1' is no
// longer inheriting from 'dev'.
$this->switchToWorkspace('local_1');
$node = $this->entityTypeManager
->getStorage('node')
->load(1);
$node->setTitle('local_1 - 1 - r7');
$node->save();
$expected_workspace_association = [
'stage' => [
3,
5,
],
'dev' => [
5,
6,
],
'local_1' => [
5,
7,
],
'local_2' => [
5,
6,
],
'qa' => [],
];
$this->assertWorkspaceAssociation($expected_workspace_association, 'node');
$this->switchToWorkspace('dev');
$node = $this->entityTypeManager
->getStorage('node')
->load(1);
$node->setTitle('dev - 1 - r8');
$node->save();
$expected_workspace_association = [
'stage' => [
3,
5,
],
'dev' => [
5,
8,
],
'local_1' => [
5,
7,
],
'local_2' => [
5,
8,
],
'qa' => [],
];
$this->assertWorkspaceAssociation($expected_workspace_association, 'node');
// Add a child workspace for 'dev' and check that it inherits all the parent
// associations by default.
$this->workspaces['local_3'] = Workspace::create([
'id' => 'local_3',
'parent' => 'dev',
]);
$this->workspaces['local_3']
->save();
$expected_workspace_association = [
'stage' => [
3,
5,
],
'dev' => [
5,
8,
],
'local_1' => [
5,
7,
],
'local_2' => [
5,
8,
],
'local_3' => [
5,
8,
],
'qa' => [],
];
$this->assertWorkspaceAssociation($expected_workspace_association, 'node');
// Check that a workspace that is not at the top level can not be published.
$this->expectException(WorkspaceAccessException::class);
$this->expectExceptionMessage('Only top-level workspaces can be published.');
$this->workspaces['dev']
->publish();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.