X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fmenu_link_content%2Ftests%2Fsrc%2FFunctional%2FMenuLinkContentFormTest.php;fp=web%2Fcore%2Fmodules%2Fmenu_link_content%2Ftests%2Fsrc%2FFunctional%2FMenuLinkContentFormTest.php;h=464b86c3972d4d66cbcc770b9cd5d23e7a297119;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentFormTest.php b/web/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentFormTest.php new file mode 100644 index 000000000..464b86c39 --- /dev/null +++ b/web/core/modules/menu_link_content/tests/src/Functional/MenuLinkContentFormTest.php @@ -0,0 +1,109 @@ +adminUser = $this->drupalCreateUser(['administer menu', 'link to any page']); + $this->basicUser = $this->drupalCreateUser(['administer menu']); + $this->drupalLogin($this->adminUser); + } + + /** + * Tests the 'link to any page' permission for a restricted page. + */ + public function testMenuLinkContentFormLinkToAnyPage() { + $menu_link = MenuLinkContent::create([ + 'title' => 'Menu link test', + 'provider' => 'menu_link_content', + 'menu_name' => 'admin', + 'link' => ['uri' => 'internal:/user/login'], + ]); + $menu_link->save(); + + // The user should be able to edit a menu link to the page, even though + // the user cannot access the page itself. + $this->drupalGet('/admin/structure/menu/item/' . $menu_link->id() . '/edit'); + $this->assertResponse(200); + + $this->drupalLogin($this->basicUser); + + $this->drupalGet('/admin/structure/menu/item/' . $menu_link->id() . '/edit'); + $this->assertResponse(403); + } + + /** + * Tests the MenuLinkContentForm class. + */ + public function testMenuLinkContentForm() { + $this->drupalGet('admin/structure/menu/manage/admin/add'); + $element = $this->xpath('//select[@id = :id]/option[@selected]', [':id' => 'edit-menu-parent']); + $this->assertTrue($element, 'A default menu parent was found.'); + $this->assertEqual('admin:', $element[0]->getValue(), ' menu is the parent.'); + + $this->drupalPostForm( + NULL, + [ + 'title[0][value]' => t('Front page'), + 'link[0][uri]' => '', + ], + t('Save') + ); + $this->assertText(t('The menu link has been saved.')); + } + + /** + * Tests validation for the MenuLinkContentForm class. + */ + public function testMenuLinkContentFormValidation() { + $this->drupalGet('admin/structure/menu/manage/admin/add'); + $this->drupalPostForm( + NULL, + [ + 'title[0][value]' => t('Test page'), + 'link[0][uri]' => '', + ], + t('Save') + ); + $this->assertText(t('Manually entered paths should start with /, ? or #.')); + } + +}