View source
<?php
namespace Drupal\Tests\node\Kernel;
class NodeAccessTest extends NodeAccessTestBase {
public function testNodeAccess() {
$web_user1 = $this
->drupalCreateUser([
'create page content',
'edit any page content',
'delete any page content',
]);
$node1 = $this
->drupalCreateNode([
'type' => 'page',
]);
$this
->assertNodeCreateAccess($node1
->bundle(), FALSE, $web_user1);
$this
->assertNodeAccess([
'view' => FALSE,
'update' => FALSE,
'delete' => FALSE,
], $node1, $web_user1);
$web_user2 = $this
->drupalCreateUser([
'bypass node access',
]);
$node2 = $this
->drupalCreateNode([
'type' => 'page',
]);
$this
->assertNodeCreateAccess($node2
->bundle(), TRUE, $web_user2);
$this
->assertNodeAccess([
'view' => TRUE,
'update' => TRUE,
'delete' => TRUE,
], $node2, $web_user2);
$web_user3 = $this
->drupalCreateUser([
'access content',
]);
$node3 = $this
->drupalCreateNode([
'status' => 0,
'uid' => $web_user3
->id(),
]);
$this
->assertNodeAccess([
'view' => FALSE,
], $node3, $web_user3);
$this
->assertNodeCreateAccess($node3
->bundle(), FALSE, $web_user3);
$web_user4 = $this
->drupalCreateUser([
'access content',
'view own unpublished content',
]);
$web_user5 = $this
->drupalCreateUser([
'access content',
'view own unpublished content',
]);
$node4 = $this
->drupalCreateNode([
'status' => 0,
'uid' => $web_user4
->id(),
]);
$this
->assertNodeAccess([
'view' => TRUE,
'update' => FALSE,
], $node4, $web_user4);
$this
->assertNodeAccess([
'view' => FALSE,
], $node4, $web_user5);
$node5 = $this
->drupalCreateNode();
$this
->assertNodeAccess([
'view' => TRUE,
'update' => FALSE,
'delete' => FALSE,
], $node5, $web_user3);
$web_user6 = $this
->drupalCreateUser([
'access content',
'edit any page content',
'delete any page content',
]);
$node6 = $this
->drupalCreateNode([
'type' => 'page',
]);
$this
->assertNodeAccess([
'view' => TRUE,
'update' => TRUE,
'delete' => TRUE,
], $node6, $web_user6);
$web_user7 = $this
->drupalCreateUser([
'access content',
'edit own page content',
'delete own page content',
]);
$this
->assertNodeAccess([
'view' => TRUE,
'update' => FALSE,
'delete' => FALSE,
], $node6, $web_user7);
$node7 = $this
->drupalCreateNode([
'type' => 'page',
'uid' => $web_user7
->id(),
]);
$this
->assertNodeAccess([
'view' => TRUE,
'update' => TRUE,
'delete' => TRUE,
], $node7, $web_user7);
}
public function testUnsupportedOperation() {
$this
->enableModules([
'node_access_test_empty',
]);
$web_user = $this
->drupalCreateUser([
'access content',
]);
$node = $this
->drupalCreateNode();
$this
->assertNodeAccess([
'random_operation' => FALSE,
], $node, $web_user);
}
}