Tests revision access permissions for a specific content type.
function testNodeRevisionAccessPerType() {
// Create three users, one with each revision permission.
foreach ($this->type_map as $op => $permission) {
// Create the user.
$account = $this
->drupalCreateUser(array(
'access content',
'edit any page content',
'delete any page content',
$permission,
));
$account->op = $op;
$accounts[] = $account;
}
$parameters = array(
'op' => array_keys($this->type_map),
'account' => $accounts,
);
// Test that the accounts have access to the correspoding page revision permissions.
$revision = $this->node_revisions['page'][1];
$permutations = $this
->generatePermutations($parameters);
foreach ($permutations as $case) {
// Skip this test if there are no revisions for the node.
if (!($revision
->isDefaultRevision() && (db_query('SELECT COUNT(vid) FROM {node_field_revision} WHERE nid = :nid', array(
':nid' => $revision->nid,
))
->fetchField() == 1 || $case['op'] == 'update' || $case['op'] == 'delete'))) {
if (!empty($case['account']->is_admin) || user_access($this->type_map[$case['op']], $case['account'])) {
$this
->assertTrue(_node_revision_access($revision, $case['op'], $case['account']), "{$this->type_map[$case['op']]} granted.");
}
else {
$this
->assertFalse(_node_revision_access($revision, $case['op'], $case['account']), "{$this->type_map[$case['op']]} not granted.");
}
}
}
// Test that the accounts have no access to the article revisions.
$revision = $this->node_revisions['article'][1];
foreach ($permutations as $case) {
$this
->assertFalse(_node_revision_access($revision, $case['op'], $case['account']), "{$this->type_map[$case['op']]} did not grant revision permission for articles.");
}
}