function PageViewTest::testPageView

Same name in other branches
  1. 9 core/modules/node/tests/src/Functional/PageViewTest.php \Drupal\Tests\node\Functional\PageViewTest::testPageView()
  2. 8.9.x core/modules/node/tests/src/Functional/PageViewTest.php \Drupal\Tests\node\Functional\PageViewTest::testPageView()
  3. 10 core/modules/node/tests/src/Functional/PageViewTest.php \Drupal\Tests\node\Functional\PageViewTest::testPageView()

Tests editing a node by users with various access permissions.

File

core/modules/node/tests/src/Functional/PageViewTest.php, line 24

Class

PageViewTest
Create a node and test edit permissions.

Namespace

Drupal\Tests\node\Functional

Code

public function testPageView() : void {
    // Create a node to view.
    $node = $this->drupalCreateNode();
    $this->assertNotEmpty(Node::load($node->id()), 'Node created.');
    // Try to edit with anonymous user.
    $this->drupalGet("node/" . $node->id() . "/edit");
    $this->assertSession()
        ->statusCodeEquals(403);
    // Create a user without permission to edit node.
    $web_user = $this->drupalCreateUser([
        'access content',
    ]);
    $this->drupalLogin($web_user);
    // Attempt to access edit page.
    $this->drupalGet("node/" . $node->id() . "/edit");
    $this->assertSession()
        ->statusCodeEquals(403);
    // Create user with permission to edit node.
    $web_user = $this->drupalCreateUser([
        'bypass node access',
    ]);
    $this->drupalLogin($web_user);
    // Attempt to access edit page.
    $this->drupalGet("node/" . $node->id() . "/edit");
    $this->assertSession()
        ->statusCodeEquals(200);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.