Version 1
[yaffs-website] / web / core / modules / menu_link_content / tests / src / Functional / MenuLinkContentDeleteFormTest.php
1 <?php
2
3 namespace Drupal\Tests\menu_link_content\Functional;
4
5 use Drupal\menu_link_content\Entity\MenuLinkContent;
6 use Drupal\system\Entity\Menu;
7 use Drupal\Tests\BrowserTestBase;
8
9 /**
10  * Tests the menu link content delete UI.
11  *
12  * @group Menu
13  */
14 class MenuLinkContentDeleteFormTest extends BrowserTestBase {
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = ['menu_link_content'];
22
23   /**
24    * {@inheritdoc}
25    */
26   protected function setUp() {
27     parent::setUp();
28     $web_user = $this->drupalCreateUser(['administer menu']);
29     $this->drupalLogin($web_user);
30   }
31
32   /**
33    * Tests the MenuLinkContentDeleteForm class.
34    */
35   public function testMenuLinkContentDeleteForm() {
36     // Add new menu item.
37     $this->drupalPostForm(
38       'admin/structure/menu/manage/admin/add',
39       [
40         'title[0][value]' => t('Front page'),
41         'link[0][uri]' => '<front>',
42       ],
43       t('Save')
44     );
45     $this->assertText(t('The menu link has been saved.'));
46
47     $menu_link = MenuLinkContent::load(1);
48     $this->drupalGet($menu_link->urlInfo('delete-form'));
49     $this->assertRaw(t('Are you sure you want to delete the custom menu link %name?', ['%name' => $menu_link->label()]));
50     $this->assertLink(t('Cancel'));
51     // Make sure cancel link points to link edit
52     $this->assertLinkByHref($menu_link->url('edit-form'));
53
54     \Drupal::service('module_installer')->install(['menu_ui']);
55     \Drupal::service('router.builder')->rebuild();
56
57     // Make sure cancel URL points to menu_ui route now.
58     $this->drupalGet($menu_link->urlInfo('delete-form'));
59     $menu = Menu::load($menu_link->getMenuName());
60     $this->assertLinkByHref($menu->url('edit-form'));
61     $this->drupalPostForm(NULL, [], t('Delete'));
62     $this->assertRaw(t('The menu link %title has been deleted.', ['%title' => $menu_link->label()]));
63   }
64
65 }