function ToolbarAdminMenuTest::testSubtreesJsonRequest

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

Tests that the 'toolbar/subtrees/{hash}' is reachable and correct.

File

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

Class

ToolbarAdminMenuTest
Tests the caching of the admin menu subtree items.

Namespace

Drupal\Tests\toolbar\Functional

Code

public function testSubtreesJsonRequest() : void {
  $admin_user = $this->adminUser;
  $this->drupalLogin($admin_user);
  // Request a new page to refresh the drupalSettings object.
  $subtrees_hash = $this->getSubtreesHash();
  $this->drupalGet('toolbar/subtrees/' . $subtrees_hash, [
    'query' => [
      MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax',
    ],
  ], [
    'X-Requested-With' => 'XMLHttpRequest',
  ]);
  $ajax_result = json_decode($this->getSession()
    ->getPage()
    ->getContent(), TRUE);
  $this->assertEquals('setToolbarSubtrees', $ajax_result[0]['command'], 'Subtrees response uses the correct command.');
  $this->assertEquals([
    'system-admin_content',
    'system-admin_structure',
    'system-themes_page',
    'system-modules_list',
    'system-admin_config',
    'entity-user-collection',
    'front',
  ], array_keys($ajax_result[0]['subtrees']), 'Correct subtrees returned.');
}

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