function WorkspaceCRUDTest::testDeletingWorkspaceWithChildren

Same name in other branches
  1. 9 core/modules/workspaces/tests/src/Kernel/WorkspaceCRUDTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceCRUDTest::testDeletingWorkspaceWithChildren()
  2. 8.9.x core/modules/workspaces/tests/src/Kernel/WorkspaceCRUDTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceCRUDTest::testDeletingWorkspaceWithChildren()
  3. 11.x core/modules/workspaces/tests/src/Kernel/WorkspaceCRUDTest.php \Drupal\Tests\workspaces\Kernel\WorkspaceCRUDTest::testDeletingWorkspaceWithChildren()

Tests that a workspace with children can not be deleted.

File

core/modules/workspaces/tests/src/Kernel/WorkspaceCRUDTest.php, line 286

Class

WorkspaceCRUDTest
Tests CRUD operations for workspaces.

Namespace

Drupal\Tests\workspaces\Kernel

Code

public function testDeletingWorkspaceWithChildren() : void {
    $stage = Workspace::create([
        'id' => 'stage',
        'label' => 'Stage',
    ]);
    $stage->save();
    $dev = Workspace::create([
        'id' => 'dev',
        'label' => 'Dev',
        'parent' => 'stage',
    ]);
    $dev->save();
    // Check that a workspace which has children can not be deleted.
    try {
        $stage->delete();
        $this->fail('The Stage workspace has children and should not be deletable.');
    } catch (EntityStorageException $e) {
        $this->assertEquals('The Stage workspace can not be deleted because it has child workspaces.', $e->getMessage());
        $this->assertNotNull(Workspace::load('stage'));
    }
    // Check that if we delete its child first, the parent workspace can also be
    // deleted.
    $dev->delete();
    $stage->delete();
    $this->assertNull(Workspace::load('dev'));
    $this->assertNull(Workspace::load('stage'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.