class WorkspaceSwitcherTest
Same name and namespace in other branches
- 11.x core/modules/workspaces/tests/src/Functional/WorkspaceSwitcherTest.php \Drupal\Tests\workspaces\Functional\WorkspaceSwitcherTest
- 10 core/modules/workspaces/tests/src/Functional/WorkspaceSwitcherTest.php \Drupal\Tests\workspaces\Functional\WorkspaceSwitcherTest
- 8.9.x core/modules/workspaces/tests/src/Functional/WorkspaceSwitcherTest.php \Drupal\Tests\workspaces\Functional\WorkspaceSwitcherTest
Tests workspace switching functionality.
@group workspaces
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\workspaces\Functional\WorkspaceSwitcherTest uses \Drupal\Tests\system\Functional\Cache\AssertPageCacheContextsAndTagsTrait, \Drupal\Tests\workspaces\Functional\WorkspaceTestUtilities implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of WorkspaceSwitcherTest
File
-
core/
modules/ workspaces/ tests/ src/ Functional/ WorkspaceSwitcherTest.php, line 13
Namespace
Drupal\Tests\workspaces\FunctionalView source
class WorkspaceSwitcherTest extends BrowserTestBase {
use AssertPageCacheContextsAndTagsTrait;
use WorkspaceTestUtilities;
/**
* {@inheritdoc}
*/
protected static $modules = [
'block',
'workspaces',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
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);
}
/**
* Tests switching workspace via the switcher block and admin page.
*/
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();
// Check that WorkspaceCacheContext provides the cache context used to
// support its functionality.
$this->assertCacheContext('session');
$page->findLink($gravity->label());
}
/**
* Tests switching workspace via a query parameter.
*/
public function testQueryParameterNegotiator() {
$web_assert = $this->assertSession();
// Initially the default workspace should be active.
$web_assert->elementContains('css', '#block-workspaceswitcher', 'None');
// When adding a query parameter the workspace will be switched.
$current_user_url = \Drupal::currentUser()->getAccount()
->toUrl();
$this->drupalGet($current_user_url, [
'query' => [
'workspace' => 'stage',
],
]);
$web_assert->elementContains('css', '#block-workspaceswitcher', 'Stage');
// The workspace switching via query parameter should persist.
$this->drupalGet($current_user_url);
$web_assert->elementContains('css', '#block-workspaceswitcher', 'Stage');
// Check that WorkspaceCacheContext provides the cache context used to
// support its functionality.
$this->assertCacheContext('session');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.