NodeAccessMenuLinkTest.php 1.8 KB

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