public function MenuLinkCloneTest::testMenuLinkClone in Menu Link Clone 8.3
Same name and namespace in other branches
- 8.2 tests/src/Functional/MenuLinkCloneTest.php \Drupal\Tests\menu_link_clone\Functional\MenuLinkCloneTest::testMenuLinkClone()
Test menu link clone.
File
- tests/
src/ Functional/ MenuLinkCloneTest.php, line 57
Class
- MenuLinkCloneTest
- Create a menu and test a link clone.
Namespace
Drupal\Tests\menu_link_clone\FunctionalCode
public function testMenuLinkClone() {
$entityTypeManager = $this->container
->get('entity_type.manager');
$menus = $entityTypeManager
->getStorage('menu')
->loadByProperties([
'id' => 'account',
]);
$menu = reset($menus);
// Custom menu link.
$menu_link = MenuLinkContent::create([
'title' => 'Test',
'link' => [
'uri' => 'internal:/',
],
'menu_name' => 'account',
'expanded' => TRUE,
'weight' => 0,
]);
$menu_link
->save();
$edit = [
'label' => 'Test menu cloned',
'id' => 'test_menu_cloned',
'clone_links' => TRUE,
];
$this
->drupalPostForm('entity_clone/menu/' . $menu
->id(), $edit, t('Clone'));
$menus = $entityTypeManager
->getStorage('menu')
->loadByProperties([
'id' => $edit['id'],
]);
$menu = reset($menus);
$this
->assertNotEmpty($menu, 'Test menu cloned found in database.');
$menuLink = $entityTypeManager
->getStorage('menu_link_content')
->loadByProperties([
'menu_name' => $edit['id'],
]);
$menuLink = reset($menuLink);
$this
->assertNotEmpty($menuLink, "Menu link found in database for Test menu cloned");
}