PageViewTest.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace Drupal\Tests\node\Functional;
  3. use Drupal\node\Entity\Node;
  4. /**
  5. * Create a node and test edit permissions.
  6. *
  7. * @group node
  8. */
  9. class PageViewTest extends NodeTestBase {
  10. /**
  11. * Tests an anonymous and unpermissioned user attempting to edit the node.
  12. */
  13. public function testPageView() {
  14. // Create a node to view.
  15. $node = $this->drupalCreateNode();
  16. $this->assertTrue(Node::load($node->id()), 'Node created.');
  17. // Try to edit with anonymous user.
  18. $this->drupalGet("node/" . $node->id() . "/edit");
  19. $this->assertResponse(403);
  20. // Create a user without permission to edit node.
  21. $web_user = $this->drupalCreateUser(['access content']);
  22. $this->drupalLogin($web_user);
  23. // Attempt to access edit page.
  24. $this->drupalGet("node/" . $node->id() . "/edit");
  25. $this->assertResponse(403);
  26. // Create user with permission to edit node.
  27. $web_user = $this->drupalCreateUser(['bypass node access']);
  28. $this->drupalLogin($web_user);
  29. // Attempt to access edit page.
  30. $this->drupalGet("node/" . $node->id() . "/edit");
  31. $this->assertResponse(200);
  32. }
  33. }