public function MenuBlockTest::testMenuBlockLevel in Menu Block 8
Tests the menu_block level option.
File
- tests/
src/ Functional/ MenuBlockTest.php, line 217
Class
- MenuBlockTest
- Tests for the menu_block module.
Namespace
Drupal\Tests\menu_block\FunctionalCode
public function testMenuBlockLevel() {
// Add new menu block.
$block_id = 'main';
$this
->drupalGet('admin/structure/block/add/menu_block:main');
$this
->submitForm([
'id' => $block_id,
'settings[label]' => 'Main navigation',
'settings[label_display]' => FALSE,
'settings[level]' => 1,
'region' => 'primary_menu',
], 'Save block');
// Check if the parent menu item is visible, but the child menu items not.
$this
->drupalGet('<front>');
$this
->assertSession()
->pageTextContains('parent menu item');
$this
->assertSession()
->pageTextNotContains('child-1 menu item');
$this
->assertSession()
->pageTextNotContains('child-1-1 menu item');
$this
->assertSession()
->pageTextNotContains('child-2 menu item');
$this
->drupalGet('admin/structure/block/manage/' . $block_id);
$this
->submitForm([
'settings[level]' => 2,
], 'Save block');
// Check if the menu items of level 2 are visible, but not the parent menu
// item.
$this
->drupalGet('menu-block-test/hierarchy/parent');
$this
->assertSession()
->pageTextContains('child-1 menu item');
$this
->assertSession()
->pageTextContains('child-2 menu item');
$this
->assertSession()
->pageTextNotContains('parent menu item');
$this
->assertSession()
->pageTextNotContains('child-1-1 menu item');
}