5d987b36a17d7a957b239d0bf4999bb5cb015a82
[yaffs-website] / web / core / modules / node / tests / src / Functional / NodeAccessMenuLinkTest.php
1 <?php
2
3 namespace Drupal\Tests\node\Functional;
4
5 use Drupal\user\RoleInterface;
6
7 /**
8  * Tests the interaction of the node access system with menu links.
9  *
10  * @group node
11  */
12 class NodeAccessMenuLinkTest extends NodeTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['menu_ui', 'block'];
20
21   /**
22    * A user with permission to manage menu links and create nodes.
23    *
24    * @var \Drupal\user\UserInterface
25    */
26   protected $contentAdminUser;
27
28   protected function setUp() {
29     parent::setUp();
30
31     $this->drupalPlaceBlock('system_menu_block:main');
32
33     $this->contentAdminUser = $this->drupalCreateUser([
34       'access content',
35       'administer content types',
36       'administer menu',
37     ]);
38
39     $this->config('user.role.' . RoleInterface::ANONYMOUS_ID)->set('permissions', [])->save();
40   }
41
42   /**
43    * SA-CORE-2015-003: Tests menu links to nodes when node access is restricted.
44    */
45   public function testNodeAccessMenuLink() {
46
47     $menu_link_title = $this->randomString();
48
49     $this->drupalLogin($this->contentAdminUser);
50     $edit = [
51       'title[0][value]' => $this->randomString(),
52       'body[0][value]' => $this->randomString(),
53       'menu[enabled]' => 1,
54       'menu[title]' => $menu_link_title,
55     ];
56     $this->drupalPostForm('node/add/page', $edit, t('Save'));
57     $this->assertLink($menu_link_title);
58
59     // Ensure anonymous users without "access content" permission do not see
60     // this menu link.
61     $this->drupalLogout();
62     $this->drupalGet('');
63     $this->assertNoLink($menu_link_title);
64
65     // Ensure anonymous users with "access content" permission see this menu
66     // link.
67     $this->config('user.role.' . RoleInterface::ANONYMOUS_ID)->set('permissions', ['access content'])->save();
68     $this->drupalGet('');
69     $this->assertLink($menu_link_title);
70   }
71
72 }