You are here

public function MenuBlockTest::testMenuBlockFollow in Menu Block 8

Tests the menu_block follow and follow_parent option.

File

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

Class

MenuBlockTest
Tests for the menu_block module.

Namespace

Drupal\Tests\menu_block\Functional

Code

public function testMenuBlockFollow() {
  $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[follow]' => TRUE,
    'settings[follow_parent]' => 'child',
    'region' => 'primary_menu',
  ], '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
    ->drupalGet('menu-block-test/hierarchy/parent');
  $this
    ->assertSession()
    ->pageTextNotContains('parent menu item');
  $this
    ->assertSession()
    ->pageTextContains('child-1 menu item');
  $this
    ->assertSession()
    ->pageTextContains('child-2 menu item');
  $this
    ->drupalGet('menu-block-test/hierarchy/parent/child-1');
  $this
    ->assertSession()
    ->pageTextNotContains('parent menu item');
  $this
    ->assertSession()
    ->pageTextNotContains('child-1 menu item');
  $this
    ->assertSession()
    ->pageTextContains('child-1-1 menu item');
  $this
    ->assertSession()
    ->pageTextContains('child-1-2 menu item');
  $this
    ->assertSession()
    ->pageTextNotContains('child-2 menu item');
  $this
    ->drupalGet('admin/structure/block/manage/' . $block_id);
  $this
    ->submitForm([
    'settings[follow_parent]' => 'active',
  ], '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
    ->drupalGet('menu-block-test/hierarchy/parent');
  $this
    ->assertSession()
    ->pageTextContains('parent menu item');
  $this
    ->assertSession()
    ->pageTextContains('child-1 menu item');
  $this
    ->assertSession()
    ->pageTextNotContains('child-1-1 menu item');
}