function WorkspaceSwitcherTest::testQueryParameterNegotiator

Same name in other branches
  1. 9 core/modules/workspaces/tests/src/Functional/WorkspaceSwitcherTest.php \Drupal\Tests\workspaces\Functional\WorkspaceSwitcherTest::testQueryParameterNegotiator()
  2. 8.9.x core/modules/workspaces/tests/src/Functional/WorkspaceSwitcherTest.php \Drupal\Tests\workspaces\Functional\WorkspaceSwitcherTest::testQueryParameterNegotiator()
  3. 10 core/modules/workspaces/tests/src/Functional/WorkspaceSwitcherTest.php \Drupal\Tests\workspaces\Functional\WorkspaceSwitcherTest::testQueryParameterNegotiator()

Tests switching workspace via a query parameter.

File

core/modules/workspaces/tests/src/Functional/WorkspaceSwitcherTest.php, line 84

Class

WorkspaceSwitcherTest
Tests workspace switching functionality.

Namespace

Drupal\Tests\workspaces\Functional

Code

public function testQueryParameterNegotiator() : void {
    $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');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.