function ToolbarAdminMenuTest::testLanguageSwitching

Same name and namespace in other branches
  1. 9 core/modules/toolbar/tests/src/Functional/ToolbarAdminMenuTest.php \Drupal\Tests\toolbar\Functional\ToolbarAdminMenuTest::testLanguageSwitching()
  2. 8.9.x core/modules/toolbar/tests/src/Functional/ToolbarAdminMenuTest.php \Drupal\Tests\toolbar\Functional\ToolbarAdminMenuTest::testLanguageSwitching()
  3. 10 core/modules/toolbar/tests/src/Functional/ToolbarAdminMenuTest.php \Drupal\Tests\toolbar\Functional\ToolbarAdminMenuTest::testLanguageSwitching()

Tests that subtrees hashes vary by the language of the page.

File

core/modules/toolbar/tests/src/Functional/ToolbarAdminMenuTest.php, line 397

Class

ToolbarAdminMenuTest
Tests the caching of the admin menu subtree items.

Namespace

Drupal\Tests\toolbar\Functional

Code

public function testLanguageSwitching() : void {
    // Create a new language with the langcode 'xx'.
    $langcode = 'xx';
    $language = ConfigurableLanguage::createFromLangcode($langcode);
    $language->save();
    // The language path processor is just registered for more than one
    // configured language, so rebuild the container now that we are
    // multilingual.
    $this->rebuildContainer();
    // Get a page with the new language langcode in the URL.
    $this->drupalGet('test-page', [
        'language' => $language,
    ]);
    // Assert different hash.
    $new_subtree_hash = $this->getSubtreesHash();
    // Assert that the old admin menu subtree hash and the new admin menu
    // subtree hash are different.
    $this->assertNotEmpty($new_subtree_hash, 'A valid hash value for the admin menu subtrees was created.');
    $this->assertNotEquals($this->hash, $new_subtree_hash, 'The user-specific subtree menu hash has been updated.');
}

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