function MenuLinksTest::assertMenuLinkParents

Same name in other branches
  1. 9 core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php \Drupal\Tests\menu_link_content\Kernel\MenuLinksTest::assertMenuLinkParents()
  2. 8.9.x core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php \Drupal\Tests\menu_link_content\Kernel\MenuLinksTest::assertMenuLinkParents()
  3. 10 core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php \Drupal\Tests\menu_link_content\Kernel\MenuLinksTest::assertMenuLinkParents()

Assert that at set of links is properly parented.

@internal

1 call to MenuLinksTest::assertMenuLinkParents()
MenuLinksTest::testMenuLinkReparenting in core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php
Tests automatic reparenting of menu links.

File

core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php, line 127

Class

MenuLinksTest
Tests handling of menu links hierarchies.

Namespace

Drupal\Tests\menu_link_content\Kernel

Code

public function assertMenuLinkParents(array $links, array $expected_hierarchy) : void {
    foreach ($expected_hierarchy as $id => $parent) {
        
        /** @var \Drupal\Core\Menu\MenuLinkInterface $menu_link_plugin  */
        $menu_link_plugin = $this->menuLinkManager
            ->createInstance($links[$id]);
        $expected_parent = $links[$parent] ?? '';
        $link_parent = $menu_link_plugin->getParent();
        $this->assertEquals($expected_parent, $link_parent, "Menu link {$id} has parent of {$link_parent}, expected {$expected_parent}.");
    }
}

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