function MenuLinksTest::testMenuLinkContentReparenting
Same name in other branches
- 8.9.x core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php \Drupal\Tests\menu_link_content\Kernel\MenuLinksTest::testMenuLinkContentReparenting()
- 10 core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php \Drupal\Tests\menu_link_content\Kernel\MenuLinksTest::testMenuLinkContentReparenting()
- 11.x core/modules/menu_link_content/tests/src/Kernel/MenuLinksTest.php \Drupal\Tests\menu_link_content\Kernel\MenuLinksTest::testMenuLinkContentReparenting()
Tests the MenuLinkContent::preDelete function.
File
-
core/
modules/ menu_link_content/ tests/ src/ Kernel/ MenuLinksTest.php, line 278
Class
- MenuLinksTest
- Tests handling of menu links hierarchies.
Namespace
Drupal\Tests\menu_link_content\KernelCode
public function testMenuLinkContentReparenting() {
// Add new menu items in a hierarchy.
$parent = MenuLinkContent::create([
'title' => $this->randomMachineName(8),
'link' => [
[
'uri' => 'internal:/',
],
],
'menu_name' => 'main',
]);
$parent->save();
$child1 = MenuLinkContent::create([
'title' => $this->randomMachineName(8),
'link' => [
[
'uri' => 'internal:/',
],
],
'menu_name' => 'main',
'parent' => 'menu_link_content:' . $parent->uuid(),
]);
$child1->save();
$child2 = MenuLinkContent::create([
'title' => $this->randomMachineName(8),
'link' => [
[
'uri' => 'internal:/',
],
],
'menu_name' => 'main',
'parent' => 'menu_link_content:' . $child1->uuid(),
]);
$child2->save();
// Delete the middle child.
$child1->delete();
// Refresh $child2.
$child2 = MenuLinkContent::load($child2->id());
// Test the reference in the child.
$this->assertSame('menu_link_content:' . $parent->uuid(), $child2->getParentId());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.