public function EntityMetadataNodeAccessTestCase::testNodeMetadataAccess in Entity API 7
Runs basic tests for entity_access() function.
File
- ./
entity.test, line 1163 - Entity CRUD API tests.
Class
- EntityMetadataNodeAccessTestCase
- Tests basic entity_access() functionality for nodes.
Code
public function testNodeMetadataAccess() {
// Author user.
$node_author_account = $this
->drupalCreateUser(array());
// Make a node object.
$settings = array(
'uid' => $node_author_account->uid,
'type' => 'page',
'title' => 'Node ' . $this
->randomName(32),
);
$node = $this
->drupalCreateNode($settings);
// Ensures user without 'access content' permission can do nothing.
$web_user1 = $this
->drupalCreateUser(array(
'create page content',
'edit any page content',
'delete any page content',
));
$this
->assertNodeMetadataAccess(array(
'create' => FALSE,
'view' => FALSE,
'update' => FALSE,
'delete' => FALSE,
), $node, $web_user1);
// Ensures user with 'bypass node access' permission can do everything.
$web_user2 = $this
->drupalCreateUser(array(
'bypass node access',
));
$this
->assertNodeMetadataAccess(array(
'create' => TRUE,
'view' => TRUE,
'update' => TRUE,
'delete' => TRUE,
), $node, $web_user2);
// User cannot 'view own unpublished content'.
$web_user3 = $this
->drupalCreateUser(array(
'access content',
));
// Create an unpublished node.
$settings = array(
'type' => 'page',
'status' => 0,
'uid' => $web_user3->uid,
);
$node_unpublished = $this
->drupalCreateNode($settings);
$this
->assertNodeMetadataAccess(array(
'view' => FALSE,
), $node_unpublished, $web_user3);
// User cannot create content without permission.
$this
->assertNodeMetadataAccess(array(
'create' => FALSE,
), $node, $web_user3);
// User can 'view own unpublished content', but another user cannot.
$web_user4 = $this
->drupalCreateUser(array(
'access content',
'view own unpublished content',
));
$web_user5 = $this
->drupalCreateUser(array(
'access content',
'view own unpublished content',
));
$node4 = $this
->drupalCreateNode(array(
'status' => 0,
'uid' => $web_user4->uid,
));
$this
->assertNodeMetadataAccess(array(
'view' => TRUE,
'update' => FALSE,
), $node4, $web_user4);
$this
->assertNodeMetadataAccess(array(
'view' => FALSE,
), $node4, $web_user5);
// Tests the default access provided for a published node.
$node5 = $this
->drupalCreateNode();
$this
->assertNodeMetadataAccess(array(
'view' => TRUE,
'update' => FALSE,
'delete' => FALSE,
'create' => FALSE,
), $node5, $web_user3);
}