diff --git a/core/modules/toolbar/src/Controller/ToolbarController.php b/core/modules/toolbar/src/Controller/ToolbarController.php index 88807334aa94856d7029fcc946e250ab2db33058..ecccc1eb5f96b5908717cfcc8b96f84a08e0633a 100644 --- a/core/modules/toolbar/src/Controller/ToolbarController.php +++ b/core/modules/toolbar/src/Controller/ToolbarController.php @@ -22,7 +22,7 @@ class ToolbarController extends ControllerBase { * @return \Symfony\Component\HttpFoundation\JsonResponse */ public function subtreesJsonp() { - $subtrees = toolbar_get_rendered_subtrees(); + list($subtrees, $cacheability) = toolbar_get_rendered_subtrees(); $response = new JsonResponse($subtrees); $response->setCallback('Drupal.toolbar.setSubtrees.resolve'); diff --git a/core/modules/toolbar/src/Tests/ToolbarAdminMenuTest.php b/core/modules/toolbar/src/Tests/ToolbarAdminMenuTest.php index 57636660cd0f4f9db37b49eeecd5db25b0ade1cd..51794b1be7efc8a93c3b636cc4b11776e9275bb3 100644 --- a/core/modules/toolbar/src/Tests/ToolbarAdminMenuTest.php +++ b/core/modules/toolbar/src/Tests/ToolbarAdminMenuTest.php @@ -7,6 +7,7 @@ namespace Drupal\toolbar\Tests; +use Drupal\Component\Serialization\Json; use Drupal\Core\Cache\Cache; use Drupal\Core\Language\LanguageInterface; use Drupal\language\Entity\ConfigurableLanguage; @@ -331,7 +332,7 @@ function testLocaleTranslationSubtreesHashCacheClear() { } /** - * Tests that the 'toolbar/subtrees/{hash}' is reachable. + * Tests that the 'toolbar/subtrees/{hash}' is reachable and correct. */ function testSubtreesJsonRequest() { $admin_user = $this->adminUser; @@ -341,6 +342,12 @@ function testSubtreesJsonRequest() { $this->drupalGetJSON('toolbar/subtrees/' . $subtrees_hash); $this->assertResponse('200'); + $json_callback_start = substr($this->getRawContent(), 0, 39); + $json_callback_end = substr($this->getRawContent(), -2, 2); + $json = substr($this->getRawContent(), 39, strlen($this->getRawContent()) - 41); + $this->assertTrue($json_callback_start === '/**/Drupal.toolbar.setSubtrees.resolve(' && $json_callback_end === ');', 'Subtrees response is wrapped in callback.'); + $subtrees = Json::decode($json); + $this->assertEqual(array_keys($subtrees), ['system-admin_content', 'system-admin_structure', 'system-themes_page', 'system-modules_list', 'system-admin_config', 'entity-user-collection', 'front'], 'Correct subtrees JSON returned.'); } /**