You are here

public function MenuBlockTest::testMenuBlockDepth in Menu Block 8

Tests the menu_block depth option.

File

tests/src/Functional/MenuBlockTest.php, line 253

Class

MenuBlockTest
Tests for the menu_block module.

Namespace

Drupal\Tests\menu_block\Functional

Code

public function testMenuBlockDepth() {

  // 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,
    'settings[depth]' => 1,
    'settings[expand_all_items]' => TRUE,
    '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[depth]' => 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('parent menu item');
  $this
    ->assertSession()
    ->pageTextContains('child-1 menu item');
  $this
    ->assertSession()
    ->pageTextContains('child-2 menu item');
  $this
    ->assertSession()
    ->pageTextNotContains('child-1-1 menu item');
  $this
    ->drupalGet('admin/structure/block/manage/' . $block_id);
  $this
    ->submitForm([
    'settings[depth]' => 0,
  ], 'Save block');

  // Check if the menu items of level 2 are visible, but not the parent menu
  // item.
  $this
    ->drupalGet('<front>');
  $this
    ->assertSession()
    ->pageTextContains('parent menu item');
  $this
    ->assertSession()
    ->pageTextContains('child-1 menu item');
  $this
    ->assertSession()
    ->pageTextContains('child-2 menu item');
  $this
    ->assertSession()
    ->pageTextContains('child-1-1 menu item');
}