function WorkspaceEntityDeleteTest::testEntityDelete
Same name in other branches
- 11.x core/modules/workspaces/tests/src/Functional/WorkspaceEntityDeleteTest.php \Drupal\Tests\workspaces\Functional\WorkspaceEntityDeleteTest::testEntityDelete()
Test entity deletion with workspaces.
File
-
core/
modules/ workspaces/ tests/ src/ Functional/ WorkspaceEntityDeleteTest.php, line 42
Class
- WorkspaceEntityDeleteTest
- Tests entity deletions with workspaces.
Namespace
Drupal\Tests\workspaces\FunctionalCode
public function testEntityDelete() : void {
$assert_session = $this->assertSession();
$permissions = [
'administer workspaces',
'create workspace',
'access content overview',
'administer nodes',
'create article content',
'edit own article content',
'delete own article content',
'view own unpublished content',
];
$editor = $this->drupalCreateUser($permissions);
$this->drupalLogin($editor);
// Create a Dev workspace as a child of Stage.
$stage = Workspace::load('stage');
$dev = $this->createWorkspaceThroughUi('Dev', 'dev', 'stage');
// Create a published and an unpublished node in Live.
$published_live = $this->createNodeThroughUi('Test 1 published - live', 'article');
$unpublished_live = $this->createNodeThroughUi('Test 2 unpublished - live', 'article', FALSE);
// Create a published and an unpublished node in Stage.
$this->switchToWorkspace($stage);
$published_stage = $this->createNodeThroughUi('Test 3 published - stage', 'article');
$unpublished_stage = $this->createNodeThroughUi('Test 4 unpublished - stage', 'article', FALSE);
// Check that the Live nodes (both published and unpublished) can not be
// deleted, while the Stage nodes can be.
$this->drupalGet('admin/content');
$assert_session->linkByHrefNotExists($published_live->toUrl('delete-form')
->toString());
$assert_session->linkByHrefNotExists($unpublished_live->toUrl('delete-form')
->toString());
$assert_session->linkByHrefExists($published_stage->toUrl('delete-form')
->toString());
$assert_session->linkByHrefExists($unpublished_stage->toUrl('delete-form')
->toString());
// Switch to Dev and check which nodes can be deleted.
$this->switchToWorkspace($dev);
$this->drupalGet('admin/content');
// The two Live nodes have the same deletable status as they had in Stage.
$assert_session->linkByHrefNotExists($published_live->toUrl('delete-form')
->toString());
$assert_session->linkByHrefNotExists($unpublished_live->toUrl('delete-form')
->toString());
// The two Stage nodes should not be deletable in a child workspace (Dev).
$assert_session->linkByHrefNotExists($published_stage->toUrl('delete-form')
->toString());
$assert_session->linkByHrefNotExists($unpublished_stage->toUrl('delete-form')
->toString());
// Add a new revision for each node and check that their 'deletable' status
// remains unchanged.
$this->switchToWorkspace($stage);
$this->drupalGet($published_live->toUrl('edit-form')
->toString());
$this->submitForm([], 'Save');
$this->drupalGet($unpublished_live->toUrl('edit-form')
->toString());
$this->submitForm([], 'Save');
$this->drupalGet($published_stage->toUrl('edit-form')
->toString());
$this->submitForm([], 'Save');
$this->drupalGet($unpublished_stage->toUrl('edit-form')
->toString());
$this->submitForm([], 'Save');
$this->drupalGet('admin/content');
$assert_session->linkByHrefNotExists($published_live->toUrl('delete-form')
->toString());
$assert_session->linkByHrefNotExists($unpublished_live->toUrl('delete-form')
->toString());
$assert_session->linkByHrefExists($published_stage->toUrl('delete-form')
->toString());
$assert_session->linkByHrefExists($unpublished_stage->toUrl('delete-form')
->toString());
// Publish the Stage workspace and check that no entity can be deleted
// anymore in Stage nor Dev.
$stage->publish();
$this->drupalGet('admin/content');
$assert_session->linkByHrefNotExists($published_live->toUrl('delete-form')
->toString());
$assert_session->linkByHrefNotExists($unpublished_live->toUrl('delete-form')
->toString());
$assert_session->linkByHrefNotExists($published_stage->toUrl('delete-form')
->toString());
$assert_session->linkByHrefNotExists($unpublished_stage->toUrl('delete-form')
->toString());
$this->switchToWorkspace($dev);
$this->drupalGet('admin/content');
$assert_session->linkByHrefNotExists($published_live->toUrl('delete-form')
->toString());
$assert_session->linkByHrefNotExists($unpublished_live->toUrl('delete-form')
->toString());
$assert_session->linkByHrefNotExists($published_stage->toUrl('delete-form')
->toString());
$assert_session->linkByHrefNotExists($unpublished_stage->toUrl('delete-form')
->toString());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.