From 0feb1b692e4fecb8d91a50ffbf39f47f7e3324db Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Fri, 17 Jul 2015 09:46:05 +0100 Subject: [PATCH] Issue #2534830 by Wim Leers: Toolbar subtrees not working --- .../modules/toolbar/src/Controller/ToolbarController.php | 2 +- core/modules/toolbar/src/Tests/ToolbarAdminMenuTest.php | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/core/modules/toolbar/src/Controller/ToolbarController.php b/core/modules/toolbar/src/Controller/ToolbarController.php index 88807334aa94..ecccc1eb5f96 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 57636660cd0f..51794b1be7ef 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.'); } /** -- GitLab