Drupal 8  8.0.2
MenuLinkTreeTest Class Reference
Inheritance diagram for MenuLinkTreeTest:

Public Member Functions

 testBuildCacheability ($description, $tree, $expected_build, $access, array $access_cache_contexts=[])
 providerTestBuildCacheability ()
- Public Member Functions inherited from UnitTestCase
 randomMachineName ($length=8)
 getConfigFactoryStub (array $configs=array())
 getConfigStorageStub (array $configs)
 getStringTranslationStub ()

Protected Member Functions

 setUp ()
- Protected Member Functions inherited from UnitTestCase
 setUp ()
 getRandomGenerator ()
 assertArrayEquals (array $expected, array $actual, $message=NULL)
 getBlockMockWithMachineName ($machine_name)
 getContainerWithCacheTagsInvalidator (CacheTagsInvalidatorInterface $cache_tags_validator)
 getClassResolverStub ()

Protected Attributes

- Protected Attributes inherited from UnitTestCase

Detailed Description


Member Function Documentation

providerTestBuildCacheability ( )

Provides the test cases to test for ::testBuildCacheability().

As explained in the documentation for ::testBuildCacheability(), this generates 1 + (3 * 2 * 3) = 19 test cases.

See Also

References AccessResult\allowed(), MenuLinkMock\create(), AccessResult\neutral(), and Cache\PERMANENT.

Here is the call graph for this function:

setUp ( )


References Drupal\setContainer().

Here is the call graph for this function:

testBuildCacheability (   $description,
array  $access_cache_contexts = [] 


MenuLinkTree::build() gathers both:

  1. the tree's access cacheability: the cacheability of the access result of checking a link in a menu tree's access. Callers can opt out of this by MenuLinkTreeElement::access to NULL (the default) value, in which case the menu link is always visible. Only when an AccessResultInterface object is specified, we gather this cacheability metadata. This means there are three cases: a. no access result (NULL): menu link is visible b. AccessResultInterface object that is allowed: menu link is visible c. AccessResultInterface object that is not allowed: menu link is invisible, but cacheability metadata is still applicable
  2. the tree's menu links' cacheability: the cacheability of a menu link itself, because it may be dynamic. For this reason, MenuLinkInterface extends CacheableDependencyInterface. It allows any menu link plugin to mark itself as uncacheable (max-age=0) or dynamic (by specifying cache tags and/or contexts), to indicate the extent of dynamism. This means there are two cases: a. permanently cacheable, no cache tags, no cache contexts b. anything else: non-permanently cacheable, and/or cache tags, and/or cache contexts.

Finally, there are four important shapes of trees, all of which we want to test:

  1. the empty tree
  2. a single-element tree
  3. a single-level tree (>1 element; just 1 element is case 2)
  4. a multi-level tree

The associated data provider aims to test the handling of both of these types of cacheability, and for all four tree shapes, for each of the types of values for the two types of cacheability.

There is another level of cacheability involved when actually rendering built menu trees (i.e. when invoking RendererInterface::render() on the return value of MenuLinkTreeInterface::build()): the cacheability of the generated URLs. Fortunately, that doesn't need additional test coverage here because that cacheability is handled at the level of the Renderer (i.e. menu.html.twig template's link() function invocation). It also has its own test coverage.

See Also


The documentation for this class was generated from the following file: