You are here

public function MenuLinksOriginTest::assertMenuLinkParents in Menu Item Extras 8.2

Assert that at set of links is properly parented.

1 call to MenuLinksOriginTest::assertMenuLinkParents()
MenuLinksOriginTest::testMenuLinkReparenting in tests/src/Kernel/MenuLinksOriginTest.php
Test automatic reparenting of menu links.

File

tests/src/Kernel/MenuLinksOriginTest.php, line 134

Class

MenuLinksOriginTest
Tests handling of menu links hierarchies.

Namespace

Drupal\Tests\menu_item_extras\Kernel

Code

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