function SystemMenuBlockTest::testConfigExpanded
Tests the config expanded option.
Attributes
#[DataProvider('configExpandedTestCases')]
File
-
core/
modules/ system/ tests/ src/ Kernel/ Block/ SystemMenuBlockTest.php, line 344
Class
Namespace
Drupal\Tests\system\Kernel\BlockCode
public function testConfigExpanded($active_route, $menu_block_level, $expected_items) : void {
// Replace the path.matcher service so it always returns FALSE when
// checking whether a route is the front page. Otherwise, the default
// service throws an exception when checking routes because all of these
// are mocked.
$service_definition = $this->container
->getDefinition('path.matcher');
$service_definition->setClass(StubPathMatcher::class);
$block = $this->blockManager
->createInstance('system_menu_block:' . $this->menu
->id(), [
'region' => 'footer',
'id' => 'machine_name',
'theme' => 'stark',
'level' => $menu_block_level,
'depth' => NULL,
'expand_all_items' => TRUE,
]);
$route = $this->container
->get('router.route_provider')
->getRouteByName($active_route);
$request = new Request();
$request->attributes
->set(RouteObjectInterface::ROUTE_NAME, $active_route);
$request->attributes
->set(RouteObjectInterface::ROUTE_OBJECT, $route);
$request->setSession(new Session(new MockArraySessionStorage()));
$this->container
->get('request_stack')
->push($request);
$block_build = $block->build();
$items = $block_build['#items'] ?? [];
$this->assertEquals($expected_items, $this->convertBuiltMenuToIdTree($items));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.