public function TreeDataUnitTest::testMenuTreeData

Validate the generation of a proper menu tree hierarchy.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Menu/TreeDataUnitTest.php, line 33
Definition of Drupal\system\Tests\Menu\TreeDataUnitTest.

Class

TreeDataUnitTest
Menu tree data related tests.

Namespace

Drupal\system\Tests\Menu

Code

public function testMenuTreeData() {
  $this->links = array(
    1 => new MenuLink(array(
      'mlid' => 1,
      'depth' => 1,
    ), 'menu_link'),
    2 => new MenuLink(array(
      'mlid' => 2,
      'depth' => 1,
    ), 'menu_link'),
    3 => new MenuLink(array(
      'mlid' => 3,
      'depth' => 2,
    ), 'menu_link'),
    4 => new MenuLink(array(
      'mlid' => 4,
      'depth' => 3,
    ), 'menu_link'),
    5 => new MenuLink(array(
      'mlid' => 5,
      'depth' => 1,
    ), 'menu_link'),
  );
  $tree = menu_tree_data($this->links);

  // Validate that parent items #1, #2, and #5 exist on the root level.
  $this
    ->assertSameLink($this->links[1], $tree[1]['link'], 'Parent item #1 exists.');
  $this
    ->assertSameLink($this->links[2], $tree[2]['link'], 'Parent item #2 exists.');
  $this
    ->assertSameLink($this->links[5], $tree[5]['link'], 'Parent item #5 exists.');

  // Validate that child item #4 exists at the correct location in the hierarchy.
  $this
    ->assertSameLink($this->links[4], $tree[2]['below'][3]['below'][4]['link'], 'Child item #4 exists in the hierarchy.');
}