1 system.test MenuBlockTestCase::doMenuBlockTests($menu_name, $menu_title)

Test Menu Block functionality.

File

core/modules/system/tests/system.test, line 2910
Tests for system.module.

Class

MenuBlockTestCase
Test menu block settings.

Code

function doMenuBlockTests($menu_name, $menu_title) {

  // Add nodes to use as links for menu links.
  $node1 = $this->backdropCreateNode(array('type' => 'post'));
  $node2 = $this->backdropCreateNode(array('type' => 'post'));
  $node3 = $this->backdropCreateNode(array('type' => 'post'));
  $node4 = $this->backdropCreateNode(array('type' => 'post'));
  $node5 = $this->backdropCreateNode(array('type' => 'post'));

  // Add menu links.
  $item1 = $this->addMenuLink($menu_name, 0);
  $item2 = $this->addMenuLink($menu_name, $item1['mlid'], 'node/' . $node1->nid);
  $item3 = $this->addMenuLink($menu_name, $item2['mlid'], 'node/' . $node2->nid);
  $item4 = $this->addMenuLink($menu_name, $item3['mlid'], 'node/' . $node3->nid);
  $item5 = $this->addMenuLink($menu_name, $item4['mlid'], 'node/' . $node4->nid);
  $item6 = $this->addMenuLink($menu_name, 0, 'node/' . $node5->nid);

  $this->backdropGet('admin/structure/layouts/manage/default');
  // Remove the default main-menu block to prevent mixed up checks.
  $this->clickLink(t('Remove'), 1);
  // Remove the breadcrumb prevent mixed up checks.
  $this->clickLink(t('Remove'), 1);
  // Add a block to the sidebar (the fourth region).
  $this->clickLink(t('Add block'), 3);
  $this->clickLink($menu_title);
  $edit = array();
  $this->backdropPost(NULL, $edit, t('Add block'));

  // Record the UUID for the newly added block.
  $last_block = $this->xpath('(//*[contains(@class,:region)]//*[@data-block-id])[last()]', array(
    ':region' => 'l-sidebar',
  ));
  $block_uuid = (string) $last_block[0]['data-block-id'];
  $block_edit_url = 'admin/structure/layouts/manage/default/configure-block/editor/' . $block_uuid;

  // Save the layout and return to the home page.
  $this->backdropPost(NULL, array(), t('Save layout'));
  $this->backdropGet('user');

  // Verify menu links. By default the main menu should only show first-level
  // links.
  $this->assertLink($item1['link_title']);
  $this->assertLink($item6['link_title']);
  if ($menu_name == 'main-menu') {
    $this->assertNoLink($item2['link_title']);
  }
  else {
    $this->assertLink($item2['link_title']);
  }

  // Go to the configure page and change the depth to 3.
  $this->backdropGet($block_edit_url);
  $edit = array(
    'block_settings[depth]' => 3,
  );
  $this->backdropPost(NULL, $edit, t('Update block'));

  // Save the layout and return to the home page.
  $this->backdropPost(NULL, array(), t('Save layout'));
  $this->backdropGet('user');

  // Verify level 3 links are shown, but not level 4.
  $this->assertLink($item1['link_title']);
  $this->assertLink($item2['link_title']);
  $this->assertLink($item3['link_title']);
  $this->assertLink($item6['link_title']);
  $this->assertNoLink($item4['link_title']);

  // Go to the configure page and change the depth to unlimited.
  $this->backdropGet($block_edit_url);
  $edit = array(
    'block_settings[depth]' => 0,
  );
  $this->backdropPost(NULL, $edit, t('Update block'));

  // Save the layout and return to the home page.
  $this->backdropPost(NULL, array(), t('Save layout'));
  $this->backdropGet('user');

  // Verify level 5 links are shown.
  $this->assertLink($item5['link_title']);

  // Go to the configure page and change the starting level to 2.
  $this->backdropGet($block_edit_url);
  $edit = array(
    'block_settings[level]' => 2,
  );
  $this->backdropPost(NULL, $edit, t('Update block'));

  // Save the layout and return to the home page.
  $this->backdropPost(NULL, array(), t('Save layout'));
  $this->backdropGet('user');
  $this->assertNoLink($item1['link_title']);

  // Go to the level 2 node and verify the menu links are shown.
  $this->backdropGet('node/' . $node1->nid);

  // Verify level 2 links are shown, but not level 1.
  // We use item 6 here since item 1, although not in the menu, is in the
  // breadcrumb.
  $this->assertNoLink($item6['link_title']);
  $this->assertLink($item2['link_title']);
  $this->assertLink($item3['link_title']);

  // All above tests have been done using the default "hierarchical" style.
  // Switch to the "top-only" style and check available links.
  $edit = array(
    'block_settings[style]' => 'top_only',
  );
  $this->backdropPost($block_edit_url, $edit, t('Update block'));
  $this->backdropPost(NULL, array(), t('Save layout'));

  // Verify only top level links are shown even when on a 3rd-level link.
  $this->backdropGet($item3['link_path']);
  $this->assertLink($item1['link_title']);
  $this->assertLink($item6['link_title']);
  $this->assertNoLink($item2['link_title']);
  $this->assertNoLink($item3['link_title']);
  $this->assertNoLink($item4['link_title']);
  $this->assertNoLink($item5['link_title']);

  // Switch to the "dropdown" style and check that all links are expanded, even
  // though each individual link is not expanded.
  $edit = array(
    'block_settings[style]' => 'dropdown',
  );
  $this->backdropPost($block_edit_url, $edit, t('Update block'));
  $this->backdropPost(NULL, array(), t('Save layout'));

  $this->backdropGet($item2['link_path']);
  $this->assertLink($item1['link_title']);
  $this->assertLink($item2['link_title']);
  $this->assertLink($item3['link_title']);
  $this->assertLink($item4['link_title']);
  $this->assertLink($item5['link_title']);
  $this->assertLink($item6['link_title']);
}