function MenuLinksTest::assertMenuLinkParents

Same name in other branches
  1. 8.9.x core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php \Drupal\Tests\menu_link_content\Kernel\MenuLinksTest::assertMenuLinkParents()
  2. 10 core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php \Drupal\Tests\menu_link_content\Kernel\MenuLinksTest::assertMenuLinkParents()
  3. 11.x 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 126

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] ?? '';
        $this->assertEquals($expected_parent, $menu_link_plugin->getParent(), new FormattableMarkup('Menu link %id has parent of %parent, expected %expected_parent.', [
            '%id' => $id,
            '%parent' => $menu_link_plugin->getParent(),
            '%expected_parent' => $expected_parent,
        ]));
    }
}

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