function SystemMenuBlockTest::testConfigExpanded

Same name in other branches
  1. 8.9.x core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php \Drupal\Tests\system\Kernel\Block\SystemMenuBlockTest::testConfigExpanded()
  2. 10 core/modules/system/tests/src/Kernel/Block/SystemMenuBlockTest.php \Drupal\Tests\system\Kernel\Block\SystemMenuBlockTest::testConfigExpanded()
  3. 11.x 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));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.