function MenuTreeStorageTest::testSimpleHierarchy

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php \Drupal\KernelTests\Core\Menu\MenuTreeStorageTest::testSimpleHierarchy()
  2. 10 core/tests/Drupal/KernelTests/Core/Menu/MenuTreeStorageTest.php \Drupal\KernelTests\Core\Menu\MenuTreeStorageTest::testSimpleHierarchy()
  3. 11.x 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',
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.