You are here

public function MenuTreeStorageTest::testSimpleHierarchy in Drupal 8

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

Tests with a simple linear hierarchy.

File

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

Class

MenuTreeStorageTest
Tests the menu tree storage.

Namespace

Drupal\KernelTests\Core\Menu

Code

public function testSimpleHierarchy() {

  // Add some links with parent on the previous one and test some values.
  // <tools>
  // - test1
  // -- test2
  // --- test3
  $this
    ->addMenuLink('test1', '');
  $this
    ->assertMenuLink('test1', [
    'has_children' => 0,
    'depth' => 1,
  ]);
  $this
    ->addMenuLink('test2', 'test1');
  $this
    ->assertMenuLink('test1', [
    'has_children' => 1,
    'depth' => 1,
  ], [], [
    'test2',
  ]);
  $this
    ->assertMenuLink('test2', [
    'has_children' => 0,
    'depth' => 2,
  ], [
    'test1',
  ]);
  $this
    ->addMenuLink('test3', 'test2');
  $this
    ->assertMenuLink('test1', [
    'has_children' => 1,
    'depth' => 1,
  ], [], [
    'test2',
    'test3',
  ]);
  $this
    ->assertMenuLink('test2', [
    'has_children' => 1,
    'depth' => 2,
  ], [
    'test1',
  ], [
    'test3',
  ]);
  $this
    ->assertMenuLink('test3', [
    'has_children' => 0,
    'depth' => 3,
  ], [
    'test2',
    'test1',
  ]);
}