You are here

public function ToolbarAdminMenuTest::testLanguageSwitching in Drupal 9

Same name and namespace in other branches
  1. 8 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 384

Class

ToolbarAdminMenuTest
Tests the caching of the admin menu subtree items.

Namespace

Drupal\Tests\toolbar\Functional

Code

public function testLanguageSwitching() {

  // 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.');
}