public function WorkspaceTest::testUnpublishingWorkspaces in Multiversion 8
Tests unpublishing workspaces.
File
- tests/
src/ Kernel/ WorkspaceTest.php, line 82
Class
- WorkspaceTest
- Tests workspace interactions.
Namespace
Drupal\Tests\multiversion\KernelCode
public function testUnpublishingWorkspaces() {
// Set stage as the active workspace.
\Drupal::service('workspace.manager')
->setActiveWorkspace($this->stage);
// Check both workspaces are published by default.
$this
->assertTrue($this->live
->isPublished());
$this
->assertTrue($this->stage
->isPublished());
// Unpublish the stage workspace.
$this->stage
->setUnpublished();
$violations = $this->live
->validate();
$this
->assertEquals(0, $violations
->count());
$this->stage
->save();
// After unpublishing stage, live should be the active workspace.
$active_workspace = \Drupal::service('workspace.manager')
->getActiveWorkspace();
$this
->assertEquals(1, $active_workspace
->id());
// Check the stage workspace has been unpublished.
$this
->assertFalse($this->stage
->isPublished());
// Expect an exception if the default workspace is unpublished.
$this
->setExpectedException(\Exception::class);
$this->live
->setUnpublished();
$violations = $this->live
->validate();
$this
->assertEquals(1, $violations
->count());
$this
->assertEquals('The default workspace cannot be unpublished or archived.', $violations[0]
->getMessage());
$this->live
->save();
}