You are here

public function MenuTreeStorageTest::testMenuRebuild in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php \Drupal\system\Tests\Menu\MenuTreeStorageTest::testMenuRebuild()

Ensure hierarchy persists after a menu rebuild.

File

core/modules/system/src/Tests/Menu/MenuTreeStorageTest.php, line 325
Contains \Drupal\system\Tests\Menu\MenuTreeStorageTest.

Class

MenuTreeStorageTest
Tests the menu tree storage.

Namespace

Drupal\system\Tests\Menu

Code

public function testMenuRebuild() {

  // root
  // - child1
  // -- child2
  // --- child3
  // ---- child4
  $this
    ->addMenuLink('root');
  $this
    ->addMenuLink('child1', 'root');
  $this
    ->addMenuLink('child2', 'child1');
  $this
    ->addMenuLink('child3', 'child2');
  $this
    ->addMenuLink('child4', 'child3');
  $this
    ->assertEqual($this->treeStorage
    ->getSubtreeHeight('root'), 5);
  $this
    ->assertEqual($this->treeStorage
    ->getSubtreeHeight('child1'), 4);
  $this
    ->assertEqual($this->treeStorage
    ->getSubtreeHeight('child2'), 3);
  $this
    ->assertEqual($this->treeStorage
    ->getSubtreeHeight('child3'), 2);
  $this
    ->assertEqual($this->treeStorage
    ->getSubtreeHeight('child4'), 1);

  // Intentionally leave child3 out to mimic static or external links.
  $definitions = $this->treeStorage
    ->loadMultiple([
    'root',
    'child1',
    'child2',
    'child4',
  ]);
  $this->treeStorage
    ->rebuild($definitions);
  $this
    ->assertEqual($this->treeStorage
    ->getSubtreeHeight('root'), 5);
  $this
    ->assertEqual($this->treeStorage
    ->getSubtreeHeight('child1'), 4);
  $this
    ->assertEqual($this->treeStorage
    ->getSubtreeHeight('child2'), 3);
  $this
    ->assertEqual($this->treeStorage
    ->getSubtreeHeight('child3'), 2);
  $this
    ->assertEqual($this->treeStorage
    ->getSubtreeHeight('child4'), 1);
}