You are here

public function MenuTreeStorageTest::testSubtreeHeight in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php \Drupal\KernelTests\Core\Menu\MenuTreeStorageTest::testSubtreeHeight()

Tests finding the subtree height with content menu links.

File

core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php, line 298

Class

MenuTreeStorageTest
Tests the menu tree storage.

Namespace

Drupal\KernelTests\Core\Menu

Code

public function testSubtreeHeight() {

  // 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
    ->assertEquals(5, $this->treeStorage
    ->getSubtreeHeight('root'));
  $this
    ->assertEquals(4, $this->treeStorage
    ->getSubtreeHeight('child1'));
  $this
    ->assertEquals(3, $this->treeStorage
    ->getSubtreeHeight('child2'));
  $this
    ->assertEquals(2, $this->treeStorage
    ->getSubtreeHeight('child3'));
  $this
    ->assertEquals(1, $this->treeStorage
    ->getSubtreeHeight('child4'));
}