Commit 86513445 authored by catch's avatar catch

Issue #3016960 by amateescu: Convert...

Issue #3016960 by amateescu: Convert Drupal\Tests\menu_link_content\Functional\LinksTest to a kernel test
parent 8471aac3
<?php
namespace Drupal\Tests\menu_link_content\Kernel;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests the menu link content delete function.
*
* @group menu_link_content
*/
class MenuLinkContentDeleteTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['menu_link_content', 'link', 'system'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('menu_link_content');
}
/**
* Tests the MenuLinkContent::preDelete function.
*/
public function testMenuLinkContentDelete() {
// 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());
}
}
<?php
namespace Drupal\Tests\menu_link_content\Functional;
namespace Drupal\Tests\menu_link_content\Kernel;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Menu\MenuTreeParameters;
use Drupal\KernelTests\KernelTestBase;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\system\Entity\Menu;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\Entity\User;
/**
......@@ -14,14 +14,14 @@
*
* @group Menu
*/
class LinksTest extends BrowserTestBase {
class MenuLinksTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['router_test', 'menu_link_content'];
public static $modules = ['link', 'menu_link_content', 'router_test', 'system', 'user'];
/**
* The menu link plugin manager.
......@@ -38,6 +38,11 @@ protected function setUp() {
$this->menuLinkManager = \Drupal::service('plugin.manager.menu.link');
$this->installSchema('system', ['sequences']);
$this->installSchema('user', ['users_data']);
$this->installEntitySchema('menu_link_content');
$this->installEntitySchema('user');
Menu::create([
'id' => 'menu_test',
'label' => 'Test menu',
......@@ -252,6 +257,40 @@ public function testMenuLinkReparenting($module = 'menu_test') {
// re-parenting. https://www.drupal.org/node/2309531
}
/**
* Tests the MenuLinkContent::preDelete function.
*/
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());
}
/**
* Tests uninstalling a module providing default links.
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment