Commit f41ff929 authored by catch's avatar catch

Issue #3006719 by tetranz, dhirendra.mishra, scott_euser, Eli-T, amateescu:...

Issue #3006719 by tetranz, dhirendra.mishra, scott_euser, Eli-T, amateescu: Workspace indicator does not update after workspace label edited

(cherry picked from commit 03fdd37d)
parent f8b5d5af
......@@ -16,7 +16,7 @@ class WorkspaceTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['workspaces'];
public static $modules = ['workspaces', 'toolbar'];
/**
* A test user.
......@@ -43,6 +43,8 @@ public function setUp() {
'create workspace',
'edit own workspace',
'edit any workspace',
'view own workspace',
'access toolbar',
];
$this->editor1 = $this->drupalCreateUser($permissions);
......@@ -69,6 +71,36 @@ public function testSpecialCharacters() {
$page->hasContent("This value is not valid");
}
/**
* Test that the toolbar correctly shows the active workspace.
*/
public function testWorkspaceToolbar() {
$this->drupalLogin($this->editor1);
$this->drupalPostForm('/admin/config/workflow/workspaces/add', [
'id' => 'test_workspace',
'label' => 'Test workspace',
], 'Save');
// Activate the test workspace.
$this->drupalPostForm('/admin/config/workflow/workspaces/manage/test_workspace/activate', [], 'Confirm');
$this->drupalGet('<front>');
$page = $this->getSession()->getPage();
// Toolbar should show the correct label.
$this->assertTrue($page->hasLink('Test workspace'));
// Change the workspace label.
$this->drupalPostForm('/admin/config/workflow/workspaces/manage/test_workspace/edit', [
'label' => 'New name',
], 'Save');
$this->drupalGet('<front>');
$page = $this->getSession()->getPage();
// Toolbar should show the new label.
$this->assertTrue($page->hasLink('New name'));
}
/**
* Test changing the owner of a workspace.
*/
......
......@@ -163,15 +163,15 @@ function workspaces_toolbar() {
$current_user = \Drupal::currentUser();
if (!$current_user->hasPermission('administer workspaces')
|| !$current_user->hasPermission('view own workspace')
|| !$current_user->hasPermission('view any workspace')) {
&& !$current_user->hasPermission('view own workspace')
&& !$current_user->hasPermission('view any workspace')) {
return $items;
}
/** @var \Drupal\workspaces\WorkspaceInterface $active_workspace */
$active_workspace = \Drupal::service('workspaces.manager')->getActiveWorkspace();
$items['workspace'] = [
$items['workspace'] += [
'#type' => 'toolbar_item',
'tab' => [
'#type' => 'link',
......@@ -189,6 +189,7 @@ function workspaces_toolbar() {
],
]),
],
'#cache' => ['tags' => $active_workspace->getCacheTags()],
],
'#wrapper_attributes' => [
'class' => ['workspaces-toolbar-tab'],
......
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