Commit aa39bb31 authored by catch's avatar catch

Issue #3181508 by tedfordgif, amateescu, larowlan: Can not delete workspace if...

Issue #3181508 by tedfordgif, amateescu, larowlan: Can not delete workspace if it has associated content
parent feb69411
......@@ -91,7 +91,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$tracked_entities = $this->workspaceAssociation->getTrackedEntities($this->entity->id());
$items = [];
foreach (array_keys($tracked_entities) as $entity_type_id => $entity_ids) {
foreach ($tracked_entities as $entity_type_id => $entity_ids) {
$revision_ids = $this->workspaceAssociation->getAssociatedRevisions($this->entity->id(), $entity_type_id, $entity_ids);
$label = $this->entityTypeManager->getDefinition($entity_type_id)->getLabel();
$items[] = $this->formatPlural(count($revision_ids), '1 @label revision.', '@count @label revisions.', ['@label' => $label]);
......
......@@ -3,6 +3,7 @@
namespace Drupal\Tests\workspaces\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
/**
* Test the workspace entity.
......@@ -12,11 +13,12 @@
class WorkspaceTest extends BrowserTestBase {
use WorkspaceTestUtilities;
use ContentTypeCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = ['workspaces', 'toolbar', 'field_ui'];
protected static $modules = ['block', 'field_ui', 'node', 'toolbar', 'user', 'workspaces'];
/**
* {@inheritdoc}
......@@ -185,4 +187,27 @@ public function testWorkspaceFieldUi() {
$this->assertText($field_label);
}
/**
* Verifies that a workspace with existing content may be deleted.
*/
public function testDeleteWorkspaceWithExistingContent() {
$this->createContentType(['type' => 'test', 'label' => 'Test']);
$this->setupWorkspaceSwitcherBlock();
// Login and create a workspace.
$this->drupalLogin($this->rootUser);
$may_4 = $this->createWorkspaceThroughUi('May 4', 'may_4');
$this->switchToWorkspace($may_4);
// Create a node in the workspace.
$node = $this->createNodeThroughUi('A mayfly flies / In May or June', 'test');
// Delete the workspace.
$this->drupalGet('/admin/config/workflow/workspaces/manage/may_4/delete');
$this->assertSession()->statusCodeEquals(200);
$page = $this->getSession()->getPage();
$page->findButton('Delete')->click();
$page->hasContent('The workspace May 4 has been deleted.');
}
}
......@@ -15,6 +15,8 @@ trait WorkspaceTestUtilities {
use BlockCreationTrait;
protected $switcher_block_configured = FALSE;
/**
* Loads a single entity by its label.
*
......@@ -85,6 +87,7 @@ protected function setupWorkspaceSwitcherBlock() {
$page = $this->getSession()->getPage();
$this->assertTrue($page->hasContent('Workspace switcher'));
$this->switcher_block_configured = TRUE;
}
/**
......@@ -97,6 +100,7 @@ protected function setupWorkspaceSwitcherBlock() {
* The workspace to set active.
*/
protected function switchToWorkspace(WorkspaceInterface $workspace) {
$this->assertTrue($this->switcher_block_configured, 'This test was not written correctly: you must call setupWorkspaceSwitcherBlock() before switchToWorkspace()');
/** @var \Drupal\Tests\WebAssert $session */
$session = $this->assertSession();
$session->buttonExists('Activate');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment