Commit 519e98b8 authored by catch's avatar catch
Browse files

Issue #2229283 by dawehner, Rajendar Reddy, catch: Menu tree caching is broken.

parent 5e642cfb
......@@ -460,7 +460,7 @@ protected function doBuildTree($menu_name, array $parameters = array()) {
if (!isset($this->menuTree[$tree_cid])) {
$cache = $this->cache->get($tree_cid);
if ($cache && $cache->data) {
$this->menuFullTrees[$tree_cid] = $cache->data;
$this->menuTree[$tree_cid] = $cache->data;
}
}
......
......@@ -7,12 +7,19 @@
namespace Drupal\menu_link\Tests {
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Language\Language;
use Drupal\menu_link\MenuTree;
use Drupal\Tests\UnitTestCase;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
if (!defined('MENU_MAX_DEPTH')) {
define('MENU_MAX_DEPTH', 9);
}
/**
* Tests the menu tree.
*
......@@ -320,6 +327,78 @@ public function testGetActiveTrailIdsWithoutPreferredLink() {
}
/**
* Tests buildTree with simple menu_name and no parameters.
*/
public function testBuildTreeWithoutParameters() {
$language = new Language(array('id' => 'en'));
$this->languageManager->expects($this->any())
->method('getCurrentLanguage')
->will($this->returnValue($language));
// Setup query and the query result.
$query = $this->getMock('Drupal\Core\Entity\Query\QueryInterface');
$this->entityQueryFactory->expects($this->once())
->method('get')
->with('menu_link')
->will($this->returnValue($query));
$query->expects($this->once())
->method('condition')
->with('menu_name', 'test_menu');
$query->expects($this->once())
->method('execute')
->will($this->returnValue(array(1, 2, 3)));
$storage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
$base = array(
'access' => TRUE,
'weight' => 0,
'title' => 'title',
);
$menu_link = $base + array(
'mlid' => 1,
'p1' => 3,
'p2' => 2,
'p3' => 1,
);
$links[1] = $menu_link;
$menu_link = $base + array(
'mlid' => 3,
'p1' => 3,
'depth' => 1,
);
$links[3] = $menu_link;
$menu_link = $base + array(
'mlid' => 2,
'p1' => 3,
'p2' => 2,
'depth' => 2,
);
$links[2] = $menu_link;
$storage->expects($this->once())
->method('loadMultiple')
->with(array(1, 2, 3))
->will($this->returnValue($links));
$this->menuTree->setStorage($storage);
// Ensure that static/non static caching works.
// First setup no working caching.
$this->cacheBackend->expects($this->at(0))
->method('get')
->with('links:test_menu:tree-data:en:35786c7117b4e38d0f169239752ce71158266ae2f6e4aa230fbbb87bd699c0e3')
->will($this->returnValue(FALSE));
$this->cacheBackend->expects($this->at(1))
->method('set')
->with('links:test_menu:tree-data:en:35786c7117b4e38d0f169239752ce71158266ae2f6e4aa230fbbb87bd699c0e3', $this->anything(), Cache::PERMANENT, array('menu' => 'test_menu'));
// Ensure that the static caching triggered.
$this->cacheBackend->expects($this->exactly(1))
->method('get');
$this->menuTree->buildTree('test_menu');
$this->menuTree->buildTree('test_menu');
}
/**
* Tests the output with a single level.
*
......@@ -440,6 +519,16 @@ protected function menuLinkGetPreferred($menu_name, $active_path) {
return isset($this->preferredMenuLink[$menu_name][$active_path]) ? $this->preferredMenuLink[$menu_name][$active_path] : NULL;
}
/**
* Set the storage.
*
* @param \Drupal\Core\Entity\EntityStorageInterface $storage
* The menu link storage.
*/
public function setStorage(EntityStorageInterface $storage) {
$this->menuLinkStorage = $storage;
}
/**
* Sets the preferred menu link.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment