You are here

public function ToolbarAdminMenuTest::testSubtreesJsonRequest in Drupal 8

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

Class

ToolbarAdminMenuTest
Tests the caching of the admin menu subtree items.

Namespace

Drupal\Tests\toolbar\Functional

Code

public function testSubtreesJsonRequest() {
  $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
    ->assertEqual($ajax_result[0]['command'], 'setToolbarSubtrees', 'Subtrees response uses the correct command.');
  $this
    ->assertEqual(array_keys($ajax_result[0]['subtrees']), [
    'system-admin_content',
    'system-admin_structure',
    'system-themes_page',
    'system-modules_list',
    'system-admin_config',
    'entity-user-collection',
    'front',
  ], 'Correct subtrees returned.');
}