public function NodeViewPermissionsTest::testViewOwn in Node View Permissions 8
Test users with a "view own content" permission.
Ensure that these users can view nodes of this type that they created.
Throws
\Behat\Mink\Exception\ExpectationException
\Drupal\Core\Entity\EntityStorageException
File
- tests/
src/ Functional/ NodeViewPermissionsTest.php, line 45
Class
- NodeViewPermissionsTest
- Tests for Node View Permissions.
Namespace
Drupal\Tests\node_view_permissions\FunctionalCode
public function testViewOwn() {
$user1 = $this
->drupalCreateUser([
'view own article content',
]);
$user2 = $this
->drupalCreateUser([
'view own article content',
]);
$node = $this
->drupalCreateNode([
'type' => 'article',
'uid' => $user1
->id(),
]);
$lookup = [
[
$user1,
Response::HTTP_OK,
],
[
$user2,
Response::HTTP_FORBIDDEN,
],
];
foreach ($lookup as $i) {
list($user, $expected) = $i;
$this
->drupalLogin($user);
$this
->drupalGet(Url::fromRoute('entity.node.canonical', [
'node' => $node
->id(),
]));
$this
->assertSession()
->statusCodeEquals($expected);
}
}