public function EntityAPICommentNodeAccessTestCase::testCommentNodeAccess in Entity API 7
Tests comment access when node access is enabled.
File
- ./
entity.test, line 568 - Entity CRUD API tests.
Class
- EntityAPICommentNodeAccessTestCase
- Tests comments with node access.
Code
public function testCommentNodeAccess() {
// Post comment.
$this
->drupalLogin($this->accessUser);
$comment_text = $this
->randomName();
$comment = $this
->postComment($this->node, $comment_text);
$comment_loaded = comment_load($comment->id);
$this
->assertTrue($this
->commentExists($comment), 'Comment found.');
$this
->drupalLogout();
// Check access to node and associated comment for access user.
$this
->assertTrue(entity_access('view', 'node', $this->node, $this->accessUser), 'Access to view node was granted for access user');
$this
->assertTrue(entity_access('view', 'comment', $comment_loaded, $this->accessUser), 'Access to view comment was granted for access user');
$this
->assertTrue(entity_access('update', 'comment', $comment_loaded, $this->accessUser), 'Access to update comment was granted for access user');
$this
->assertFalse(entity_access('delete', 'comment', $comment_loaded, $this->accessUser), 'Access to delete comment was denied for access user');
// Check access to node and associated comment for no access user.
$this
->assertFalse(entity_access('view', 'node', $this->node, $this->noAccessUser), 'Access to view node was denied for no access user');
$this
->assertFalse(entity_access('view', 'comment', $comment_loaded, $this->noAccessUser), 'Access to view comment was denied for no access user');
$this
->assertFalse(entity_access('update', 'comment', $comment_loaded, $this->noAccessUser), 'Access to update comment was denied for no access user');
$this
->assertFalse(entity_access('delete', 'comment', $comment_loaded, $this->noAccessUser), 'Access to delete comment was denied for no access user');
}