98dead915cda29973e115e44952d6eea4796ef7f
[yaffs-website] / web / core / modules / menu_link_content / tests / src / Kernel / MenuLinkContentDeleteTest.php
1 <?php
2
3 namespace Drupal\Tests\menu_link_content\Kernel;
4
5 use Drupal\menu_link_content\Entity\MenuLinkContent;
6 use Drupal\KernelTests\KernelTestBase;
7
8 /**
9  * Tests the menu link content delete function.
10  *
11  * @group menu_link_content
12  */
13 class MenuLinkContentDeleteTest extends KernelTestBase {
14
15   /**
16    * {@inheritdoc}
17    */
18   public static $modules = ['menu_link_content', 'link', 'system'];
19
20   /**
21    * {@inheritdoc}
22    */
23   protected function setUp() {
24     parent::setUp();
25     $this->installEntitySchema('menu_link_content');
26   }
27
28   /**
29    * Tests the MenuLinkContent::preDelete function.
30    */
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',
37     ]);
38     $parent->save();
39     $child1 = MenuLinkContent::create([
40       'title' => $this->randomMachineName(8),
41       'link' => [['uri' => 'internal:/']],
42       'menu_name' => 'main',
43       'parent' => 'menu_link_content:' . $parent->uuid(),
44     ]);
45     $child1->save();
46     $child2 = MenuLinkContent::create([
47       'title' => $this->randomMachineName(8),
48       'link' => [['uri' => 'internal:/']],
49       'menu_name' => 'main',
50       'parent' => 'menu_link_content:' . $child1->uuid(),
51     ]);
52     $child2->save();
53
54     // Delete the middle child.
55     $child1->delete();
56     // Refresh $child2.
57     $child2 = MenuLinkContent::load($child2->id());
58     // Test the reference in the child.
59     $this->assertSame('menu_link_content:' . $parent->uuid(), $child2->getParentId());
60   }
61
62 }