You are here

function PageViewTest::testPageView in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/node/src/Tests/PageViewTest.php \Drupal\node\Tests\PageViewTest::testPageView()

Tests an anonymous and unpermissioned user attempting to edit the node.

File

core/modules/node/src/Tests/PageViewTest.php, line 21
Contains \Drupal\node\Tests\PageViewTest.

Class

PageViewTest
Create a node and test edit permissions.

Namespace

Drupal\node\Tests

Code

function testPageView() {

  // Create a node to view.
  $node = $this
    ->drupalCreateNode();
  $this
    ->assertTrue(Node::load($node
    ->id()), 'Node created.');

  // Try to edit with anonymous user.
  $this
    ->drupalGet("node/" . $node
    ->id() . "/edit");
  $this
    ->assertResponse(403);

  // Create a user without permission to edit node.
  $web_user = $this
    ->drupalCreateUser(array(
    'access content',
  ));
  $this
    ->drupalLogin($web_user);

  // Attempt to access edit page.
  $this
    ->drupalGet("node/" . $node
    ->id() . "/edit");
  $this
    ->assertResponse(403);

  // Create user with permission to edit node.
  $web_user = $this
    ->drupalCreateUser(array(
    'bypass node access',
  ));
  $this
    ->drupalLogin($web_user);

  // Attempt to access edit page.
  $this
    ->drupalGet("node/" . $node
    ->id() . "/edit");
  $this
    ->assertResponse(200);
}