function BookAccessRuleTestCase::testUserAccess in Book access 6.2
File
- ./
book_access.test, line 180
Class
Code
function testUserAccess() {
$books = array();
$grants = array();
$nodes = array();
// Create the test books.
$this
->createBook($books, $nodes);
$this
->createBook($books, $nodes);
$user = $this
->drupalCreateUser(array(
'access content',
));
$uids = array(
$user->uid,
);
$grants['grant_view'][$user->uid] = TRUE;
$grants['grant_update'][$user->uid] = (bool) mt_rand(0, 1);
$grants['grant_delete'][$user->uid] = (bool) mt_rand(0, 1);
$grants['grant_admin_access'][$user->uid] = (bool) mt_rand(0, 1);
$grants['grant_add_child'][$user->uid] = FALSE;
$grants['grant_edit_outline'][$user->uid] = (bool) mt_rand(0, 1);
foreach ($books as $node) {
BookAccess::setUserGrants($node->book['bid'], $uids, $grants);
}
foreach ($nodes as $node) {
BookAccess::writeGrantRecords($node);
}
$this
->drupalLogin($user);
// Verify if the user has access to the book pages.
foreach ($nodes as $node) {
$nid = $node->nid;
$this
->drupalGet('node/' . $nid);
if ($this
->assertResponse('200', t('The user %uid can view the book page %nid.', array(
'%uid' => $user->uid,
'%nid' => $nid,
)))) {
$this
->assertNoLink(t('Add child page'), t('The user %uid cannot add child pages to the book page %nid.', array(
'%uid' => $user->uid,
'%nid' => $nid,
)));
$this
->drupalGet('node/' . $nid . '/book_access');
$this
->assertResponse($grants['grant_admin_access'][$user->uid] ? '200' : '403', t($grants['grant_admin_access'][$user->uid] ? 'The user %uid can change the permission for the book page %nid.' : 'The user %uid cannot change the permission for the book page %nid.', array(
'%uid' => $user->uid,
'%nid' => $nid,
)));
$this
->drupalGet('node/' . $nid . '/delete');
$this
->assertResponse($grants['grant_delete'][$user->uid] ? '200' : '403', t($grants['grant_delete'][$user->uid] ? 'The user %uid can delete the book page %nid.' : 'The user %uid cannot delete the book page %nid.', array(
'%uid' => $user->uid,
'%nid' => $nid,
)));
$this
->drupalGet('node/' . $nid . '/edit');
$this
->assertResponse($grants['grant_update'][$user->uid] ? '200' : '403', t($grants['grant_update'][$user->uid] ? 'The user %uid can edit the book page %nid.' : 'The user %uid cannot edit the book page %nid.', array(
'%uid' => $user->uid,
'%nid' => $nid,
)));
$this
->drupalGet('node/' . $nid . '/outline');
$this
->assertResponse($grants['grant_edit_outline'][$user->uid] ? '200' : '403', t($grants['grant_edit_outline'][$user->uid] ? 'The user %uid can edit the outline for the book page %nid.' : 'The user %uid cannot edit the outline for the book page %nid.', array(
'%uid' => $user->uid,
'%nid' => $nid,
)));
}
}
$this
->drupalLogout();
}