View source
<?php
class NodeViewPermissionsTest extends DrupalWebTestCase {
const HTTP_FORBIDDEN = 403;
const HTTP_OK = 200;
public static function getInfo() {
return array(
'name' => 'Node View Permissions',
'description' => 'Tests permissions for viewing nodes.',
'group' => 'Node View Permissions',
);
}
public function setUp() {
parent::setUp(array(
'node_view_permissions',
));
$this
->drupalGet('<front>');
$this
->assertResponse(self::HTTP_OK);
variable_set('node_view_permissions_article', TRUE);
$this
->refreshVariables();
$this
->assertEqual(array(
'article',
), node_view_permissions_get_configured_types());
$this
->checkPermissions(array(
'view own article content',
), TRUE);
node_access_rebuild();
}
public function testViewOwn() {
$user1 = $this
->drupalCreateUser(array(
'view own article content',
));
$user2 = $this
->drupalCreateUser(array(
'view own article content',
));
$node = $this
->drupalCreateNode([
'type' => 'article',
'uid' => $user1->uid,
]);
$lookup = [
[
$user1,
self::HTTP_OK,
],
[
$user2,
self::HTTP_FORBIDDEN,
],
];
foreach ($lookup as $i) {
list($user, $expected) = $i;
$this
->drupalLogin($user);
$this
->drupalGet("node/{$node->nid}");
$this
->assertResponse($expected);
}
}
public function testViewAny() {
$user1 = $this
->drupalCreateUser(array(
'view any article content',
));
$user2 = $this
->drupalCreateUser(array(
'view any article content',
));
$node = $this
->drupalCreateNode([
'type' => 'article',
'uid' => $user1->uid,
]);
foreach ([
$user1,
$user2,
] as $user) {
$this
->drupalLogin($user);
$this
->drupalGet("node/{$node->nid}");
$this
->assertResponse(self::HTTP_OK);
}
}
}