Skip to content
Snippets Groups Projects
Commit c67bf77b authored by catch's avatar catch
Browse files

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

(cherry picked from commit aa39bb31)
parent 4941b3c0
Branches
Tags
5 merge requests!1285Issue #3240655 by elfakhar Aligne the active border,!541Issue #3123070: Fix 'PSR2.Classes.PropertyDeclaration.Underscore' coding standard,!463Resolve #3205025 "Class align center for media",!386Allow multiple vocabularies in the taxonomy filter,!308Issue #3118206: Remote media does not validate provider
......@@ -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');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment