Same name and namespace in other branches
- 8.9.x core/modules/workspaces/tests/src/Functional/WorkspaceSwitcherTest.php \Drupal\Tests\workspaces\Functional\WorkspaceSwitcherTest
- 9 core/modules/workspaces/tests/src/Functional/WorkspaceSwitcherTest.php \Drupal\Tests\workspaces\Functional\WorkspaceSwitcherTest
Tests workspace switching functionality.
@group workspaces
Hierarchy
- class \Drupal\Tests\workspaces\Functional\WorkspaceSwitcherTest extends \Drupal\Tests\BrowserTestBase uses AssertPageCacheContextsAndTagsTrait, WorkspaceTestUtilities
Expanded class hierarchy of WorkspaceSwitcherTest
File
- core/
modules/ workspaces/ tests/ src/ Functional/ WorkspaceSwitcherTest.php, line 17
Namespace
Drupal\Tests\workspaces\FunctionalView source
class WorkspaceSwitcherTest extends BrowserTestBase {
use AssertPageCacheContextsAndTagsTrait;
use WorkspaceTestUtilities;
/**
* {@inheritdoc}
*/
protected static $modules = [
'block',
'dynamic_page_cache',
'toolbar',
'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() {
$this
->createAndActivateWorkspaceThroughUi('Vultures', 'vultures');
$gravity = $this
->createWorkspaceThroughUi('Gravity', 'gravity');
// Confirm the block shows on the front page.
$this
->drupalGet('<front>');
$page = $this
->getSession()
->getPage();
$this
->assertTrue($page
->hasContent('Workspace switcher'));
$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-workspace-switcher', '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-workspace-switcher', 'Stage');
// The workspace switching via query parameter should persist.
$this
->drupalGet($current_user_url);
$web_assert
->elementContains('css', '#block-workspace-switcher', 'Stage');
// Check that WorkspaceCacheContext provides the cache context used to
// support its functionality.
$this
->assertCacheContext('session');
}
/**
* Tests that the toolbar workspace switcher doesn't disable the page cache.
*/
public function testToolbarSwitcherDynamicPageCache() {
$this
->drupalLogin($this
->drupalCreateUser([
'access toolbar',
'view any workspace',
]));
// Front-page is visited right after login.
$this
->assertSession()
->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'MISS');
// Reload the page, it should be cached now.
$this
->drupalGet(Url::fromRoute('<front>'));
$this
->assertSession()
->elementExists('css', '.workspaces-toolbar-tab');
$this
->assertSession()
->responseHeaderEquals(DynamicPageCacheSubscriber::HEADER, 'HIT');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssertPageCacheContextsAndTagsTrait:: |
protected | function | Asserts whether an expected cache context was present in the last response. | |
AssertPageCacheContextsAndTagsTrait:: |
protected | function | Ensures that some cache contexts are present in the current response. | |
AssertPageCacheContextsAndTagsTrait:: |
protected | function | Asserts the max age header. | |
AssertPageCacheContextsAndTagsTrait:: |
protected | function | Ensures that some cache tags are present in the current response. | |
AssertPageCacheContextsAndTagsTrait:: |
protected | function | Asserts that a cache context was not present in the last response. | |
AssertPageCacheContextsAndTagsTrait:: |
protected | function | Asserts page cache miss, then hit for the given URL; checks cache headers. | |
AssertPageCacheContextsAndTagsTrait:: |
protected | function | Enables page caching. | |
AssertPageCacheContextsAndTagsTrait:: |
protected | function | Gets a specific header value as array. | |
BlockCreationTrait:: |
protected | function | Creates a block instance based on default settings. | |
WorkspaceSwitcherTest:: |
protected | property | ||
WorkspaceSwitcherTest:: |
protected static | property | ||
WorkspaceSwitcherTest:: |
protected | function | ||
WorkspaceSwitcherTest:: |
public | function | Tests switching workspace via a query parameter. | |
WorkspaceSwitcherTest:: |
public | function | Tests switching workspace via the switcher block and admin page. | |
WorkspaceSwitcherTest:: |
public | function | Tests that the toolbar workspace switcher doesn't disable the page cache. | |
WorkspaceTestUtilities:: |
protected | property | ||
WorkspaceTestUtilities:: |
protected | function | Creates and activates a new Workspace through the UI. | |
WorkspaceTestUtilities:: |
protected | function | Creates a node by "clicking" buttons. | |
WorkspaceTestUtilities:: |
protected | function | Creates a new Workspace through the UI. | |
WorkspaceTestUtilities:: |
protected | function | Loads a single entity by its label. | |
WorkspaceTestUtilities:: |
protected | function | Determine if the content list has an entity's label. | |
WorkspaceTestUtilities:: |
protected | function | Adds the workspace switcher block to the site. | |
WorkspaceTestUtilities:: |
protected | function | Switches to the live version of the site for subsequent requests. | |
WorkspaceTestUtilities:: |
protected | function | Sets a given workspace as "active" for subsequent requests. |