3 namespace Drupal\Tests\menu_link_content\Kernel;
5 use Drupal\menu_link_content\Entity\MenuLinkContent;
6 use Drupal\KernelTests\KernelTestBase;
9 * Tests the menu link content delete function.
11 * @group menu_link_content
13 class MenuLinkContentDeleteTest extends KernelTestBase {
18 public static $modules = ['menu_link_content', 'link', 'system'];
23 protected function setUp() {
25 $this->installEntitySchema('menu_link_content');
29 * Tests the MenuLinkContent::preDelete function.
31 public function testMenuLinkContentDelete() {
32 // Add new menu items in a hierarchy.
33 $parent = MenuLinkContent::create([
34 'title' => $this->randomMachineName(8),
35 'link' => [['uri' => 'internal:/']],
36 'menu_name' => 'main',
39 $child1 = MenuLinkContent::create([
40 'title' => $this->randomMachineName(8),
41 'link' => [['uri' => 'internal:/']],
42 'menu_name' => 'main',
43 'parent' => 'menu_link_content:' . $parent->uuid(),
46 $child2 = MenuLinkContent::create([
47 'title' => $this->randomMachineName(8),
48 'link' => [['uri' => 'internal:/']],
49 'menu_name' => 'main',
50 'parent' => 'menu_link_content:' . $child1->uuid(),
54 // Delete the middle child.
57 $child2 = MenuLinkContent::load($child2->id());
58 // Test the reference in the child.
59 $this->assertSame('menu_link_content:' . $parent->uuid(), $child2->getParentId());