3 namespace Drupal\Tests\menu_link_content\Functional;
5 use Drupal\menu_link_content\Entity\MenuLinkContent;
6 use Drupal\Tests\BrowserTestBase;
9 * Tests the menu link content UI.
13 class MenuLinkContentFormTest extends BrowserTestBase {
20 public static $modules = [
25 * User with 'administer menu' and 'link to any page' permission.
27 * @var \Drupal\user\Entity\User
33 * User with only 'administer menu' permission.
35 * @var \Drupal\user\Entity\User
43 protected function setUp() {
45 $this->adminUser = $this->drupalCreateUser(['administer menu', 'link to any page']);
46 $this->basicUser = $this->drupalCreateUser(['administer menu']);
47 $this->drupalLogin($this->adminUser);
51 * Tests the 'link to any page' permission for a restricted page.
53 public function testMenuLinkContentFormLinkToAnyPage() {
54 $menu_link = MenuLinkContent::create([
55 'title' => 'Menu link test',
56 'provider' => 'menu_link_content',
57 'menu_name' => 'admin',
58 'link' => ['uri' => 'internal:/user/login'],
62 // The user should be able to edit a menu link to the page, even though
63 // the user cannot access the page itself.
64 $this->drupalGet('/admin/structure/menu/item/' . $menu_link->id() . '/edit');
65 $this->assertResponse(200);
67 $this->drupalLogin($this->basicUser);
69 $this->drupalGet('/admin/structure/menu/item/' . $menu_link->id() . '/edit');
70 $this->assertResponse(403);
74 * Tests the MenuLinkContentForm class.
76 public function testMenuLinkContentForm() {
77 $this->drupalGet('admin/structure/menu/manage/admin/add');
78 $element = $this->xpath('//select[@id = :id]/option[@selected]', [':id' => 'edit-menu-parent']);
79 $this->assertTrue($element, 'A default menu parent was found.');
80 $this->assertEqual('admin:', $element[0]->getValue(), '<Administration> menu is the parent.');
82 $this->drupalPostForm(
85 'title[0][value]' => t('Front page'),
86 'link[0][uri]' => '<front>',
90 $this->assertText(t('The menu link has been saved.'));
94 * Tests validation for the MenuLinkContentForm class.
96 public function testMenuLinkContentFormValidation() {
97 $this->drupalGet('admin/structure/menu/manage/admin/add');
98 $this->drupalPostForm(
101 'title[0][value]' => t('Test page'),
102 'link[0][uri]' => '<test>',
106 $this->assertText(t('Manually entered paths should start with /, ? or #.'));