WorkspaceSwitcherTest.php in Drupal 10
File
core/modules/workspaces/tests/src/Functional/WorkspaceSwitcherTest.php
View source
<?php
namespace Drupal\Tests\workspaces\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait;
class WorkspaceSwitcherTest extends BrowserTestBase {
use AssertPageCacheContextsAndTagsTrait;
use WorkspaceTestUtilities;
protected static $modules = [
'block',
'workspaces',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$permissions = [
'create workspace',
'edit own workspace',
'view own workspace',
'bypass entity access own workspace',
];
$this
->setupWorkspaceSwitcherBlock();
$mayer = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($mayer);
}
public function testSwitchingWorkspaces() {
$vultures = $this
->createWorkspaceThroughUi('Vultures', 'vultures');
$this
->switchToWorkspace($vultures);
$gravity = $this
->createWorkspaceThroughUi('Gravity', 'gravity');
$this
->drupalGet('/admin/config/workflow/workspaces/manage/' . $gravity
->id() . '/activate');
$this
->assertSession()
->statusCodeEquals(200);
$page = $this
->getSession()
->getPage();
$page
->findButton('Confirm')
->click();
$this
->assertCacheContext('session');
$page
->findLink($gravity
->label());
}
public function testQueryParameterNegotiator() {
$web_assert = $this
->assertSession();
$web_assert
->elementContains('css', '#block-workspaceswitcher', 'None');
$current_user_url = \Drupal::currentUser()
->getAccount()
->toUrl();
$this
->drupalGet($current_user_url, [
'query' => [
'workspace' => 'stage',
],
]);
$web_assert
->elementContains('css', '#block-workspaceswitcher', 'Stage');
$this
->drupalGet($current_user_url);
$web_assert
->elementContains('css', '#block-workspaceswitcher', 'Stage');
$this
->assertCacheContext('session');
}
}