You are here

public function BigMenuUiTest::testBigMenuUi in Big Menu 2.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/BigMenuUiTest.php \Drupal\Tests\bigmenu\Functional\BigMenuUiTest::testBigMenuUi()

Tests the Big Menu interface.

File

tests/src/Functional/BigMenuUiTest.php, line 59

Class

BigMenuUiTest
Tests the Big Menu interface.

Namespace

Drupal\Tests\bigmenu\Functional

Code

public function testBigMenuUi() {
  $assert = $this
    ->assertSession();
  $this
    ->drupalLogin($this->adminUser);

  // Add new menu items in a hierarchy.
  $item1 = $this
    ->createMenuLink('Item 1');
  $item1_1 = $this
    ->createMenuLink('Item 1 - 1', 'internal:/', $item1
    ->uuid());
  $this
    ->createMenuLink('Item 1 - 1 - 1', 'internal:/', $item1_1
    ->uuid());
  $item2 = $this
    ->createMenuLink('Item 2 (with disabled children)');
  $this
    ->createMenuLink('Item 2 - 1 (disabled)', 'internal:/', $item2
    ->uuid(), FALSE);

  // Test visiting a menu with an invalid menu link query param, should show
  // empty table and no error.
  $this
    ->drupalGet('admin/structure/menu/manage/main', [
    'query' => [
      'menu_link' => $this
        ->randomMachineName(),
    ],
  ]);
  $assert
    ->statusCodeEquals(200);
  $assert
    ->pageTextContains('There are no menu links yet');
  $this
    ->drupalGet('admin/structure/menu/manage/main');
  $this
    ->assertLinkExists('#menu-overview', 'Item 1');
  $this
    ->assertLinkNotExists('#menu-overview', 'Item 1 - 1');
  $this
    ->assertLinkNotExists('#menu-overview', 'Item 1 - 1 - 1');
  $assert
    ->elementNotExists('css', '.breadcrumb');

  // Check 'Edit child items' is available for 'Item 1'.
  $href = $this->menu
    ->toUrl('edit-form', [
    'query' => [
      'menu_link' => 'menu_link_content:' . $item1
        ->uuid(),
    ],
  ])
    ->toString();
  $assert
    ->linkByHrefExists($href);

  // Check 'Edit child items' is available when all children are not enabled.
  $href = $this->menu
    ->toUrl('edit-form', [
    'query' => [
      'menu_link' => 'menu_link_content:' . $item2
        ->uuid(),
    ],
  ])
    ->toString();
  $assert
    ->linkByHrefExists($href);
  $this
    ->clickLink('Edit child items');
  $this
    ->assertLinkExists('#menu-overview', 'Item 1');
  $this
    ->assertLinkExists('#menu-overview', 'Item 1 - 1');
  $this
    ->assertLinkNotExists('#menu-overview', 'Item 1 - 1 - 1');
  $this
    ->assertLinkExists('.breadcrumb', 'Back to Main navigation top level');
  $this
    ->clickLink('Edit child items');
  $this
    ->assertLinkNotExists('#menu-overview', 'Item 1');
  $this
    ->assertLinkExists('#menu-overview', 'Item 1 - 1');
  $this
    ->assertLinkExists('#menu-overview', 'Item 1 - 1 - 1');
  $this
    ->assertLinkExists('.breadcrumb', 'Back to Main navigation top level');
  $this
    ->assertLinkExists('.breadcrumb', 'Item 1');

  // Test allowing more than one level of depth to appear.
  $this
    ->config('bigmenu.settings')
    ->set('max_depth', 2)
    ->save();
  $this
    ->drupalGet('admin/structure/menu/manage/main');
  $this
    ->assertLinkExists('#menu-overview', 'Item 1');
  $this
    ->assertLinkExists('#menu-overview', 'Item 1 - 1');
  $this
    ->assertLinkNotExists('#menu-overview', 'Item 1 - 1 - 1');
}