You are here

public function SystemMenuBlockTest::testConfigExpanded in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php \Drupal\Tests\system\Kernel\Block\SystemMenuBlockTest::testConfigExpanded()
  2. 9 core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php \Drupal\Tests\system\Kernel\Block\SystemMenuBlockTest::testConfigExpanded()

Tests the config expanded option.

@dataProvider configExpandedTestCases

File

core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php, line 291

Class

SystemMenuBlockTest
Tests \Drupal\system\Plugin\Block\SystemMenuBlock.

Namespace

Drupal\Tests\system\Kernel\Block

Code

public function testConfigExpanded($active_route, $menu_block_level, $expected_items) {
  $block = $this->blockManager
    ->createInstance('system_menu_block:' . $this->menu
    ->id(), [
    'region' => 'footer',
    'id' => 'machinename',
    'theme' => 'stark',
    'level' => $menu_block_level,
    'depth' => 0,
    '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);
  $this->container
    ->get('request_stack')
    ->push($request);
  $block_build = $block
    ->build();
  $items = $block_build['#items'] ?? [];
  $this
    ->assertEquals($expected_items, $this
    ->convertBuiltMenuToIdTree($items));
}