You are here

public function MenuBlockTest::testMenuBlockExpand in Menu Block 8

Tests the menu_block expand option.

File

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

Class

MenuBlockTest
Tests for the menu_block module.

Namespace

Drupal\Tests\menu_block\Functional

Code

public function testMenuBlockExpand() {
  $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[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()
    ->pageTextContains('child-1 menu item');
  $this
    ->assertSession()
    ->pageTextContains('child-1-1 menu item');
  $this
    ->assertSession()
    ->pageTextContains('child-2 menu item');
  $this
    ->drupalGet('admin/structure/block/manage/' . $block_id);
  $this
    ->submitForm([
    'settings[expand_all_items]' => FALSE,
  ], 'Save block');
  $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');
}