Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
519e98b8
Commit
519e98b8
authored
Apr 16, 2014
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2229283
by dawehner, Rajendar Reddy, catch: Menu tree caching is broken.
parent
5e642cfb
No related branches found
No related tags found
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/modules/menu_link/lib/Drupal/menu_link/MenuTree.php
+1
-1
1 addition, 1 deletion
core/modules/menu_link/lib/Drupal/menu_link/MenuTree.php
core/modules/menu_link/tests/Drupal/menu_link/Tests/MenuTreeTest.php
+89
-0
89 additions, 0 deletions
...s/menu_link/tests/Drupal/menu_link/Tests/MenuTreeTest.php
with
90 additions
and
1 deletion
core/modules/menu_link/lib/Drupal/menu_link/MenuTree.php
+
1
−
1
View file @
519e98b8
...
@@ -460,7 +460,7 @@ protected function doBuildTree($menu_name, array $parameters = array()) {
...
@@ -460,7 +460,7 @@ protected function doBuildTree($menu_name, array $parameters = array()) {
if
(
!
isset
(
$this
->
menuTree
[
$tree_cid
]))
{
if
(
!
isset
(
$this
->
menuTree
[
$tree_cid
]))
{
$cache
=
$this
->
cache
->
get
(
$tree_cid
);
$cache
=
$this
->
cache
->
get
(
$tree_cid
);
if
(
$cache
&&
$cache
->
data
)
{
if
(
$cache
&&
$cache
->
data
)
{
$this
->
menu
Full
Tree
s
[
$tree_cid
]
=
$cache
->
data
;
$this
->
menuTree
[
$tree_cid
]
=
$cache
->
data
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
core/modules/menu_link/tests/Drupal/menu_link/Tests/MenuTreeTest.php
+
89
−
0
View file @
519e98b8
...
@@ -7,12 +7,19 @@
...
@@ -7,12 +7,19 @@
namespace
Drupal\menu_link\Tests
{
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\menu_link
\MenuTree
;
use
Drupal\Tests\UnitTestCase
;
use
Drupal\Tests\UnitTestCase
;
use
Symfony\Cmf\Component\Routing\RouteObjectInterface
;
use
Symfony\Cmf\Component\Routing\RouteObjectInterface
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\RequestStack
;
use
Symfony\Component\HttpFoundation\RequestStack
;
if
(
!
defined
(
'MENU_MAX_DEPTH'
))
{
define
(
'MENU_MAX_DEPTH'
,
9
);
}
/**
/**
* Tests the menu tree.
* Tests the menu tree.
*
*
...
@@ -320,6 +327,78 @@ public function testGetActiveTrailIdsWithoutPreferredLink() {
...
@@ -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.
* Tests the output with a single level.
*
*
...
@@ -440,6 +519,16 @@ protected function menuLinkGetPreferred($menu_name, $active_path) {
...
@@ -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
;
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.
* Sets the preferred menu link.
*
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment