class PageViewTest
Same name and namespace in other branches
- 11.x core/modules/node/tests/src/Functional/PageViewTest.php \Drupal\Tests\node\Functional\PageViewTest
- 10 core/modules/node/tests/src/Functional/PageViewTest.php \Drupal\Tests\node\Functional\PageViewTest
- 8.9.x core/modules/node/tests/src/Functional/PageViewTest.php \Drupal\Tests\node\Functional\PageViewTest
Create a node and test edit permissions.
@group node
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\node\Functional\NodeTestBase extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\node\Functional\PageViewTest extends \Drupal\Tests\node\Functional\NodeTestBase
- class \Drupal\Tests\node\Functional\NodeTestBase extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of PageViewTest
File
-
core/
modules/ node/ tests/ src/ Functional/ PageViewTest.php, line 12
Namespace
Drupal\Tests\node\FunctionalView source
class PageViewTest extends NodeTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests an anonymous and unpermissioned user attempting to edit the node.
*/
public function testPageView() {
// 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.