function simpletest_example_node_access in Examples for Developers 7
Implements hook_node_access().
Demonstrates a bug that we'll find in our test.
If this is running on the testbot, we don't want the error to show so will work around it by testing to see if we're in the 'checkout' directory.
Related topics
File
- simpletest_example/
simpletest_example.module, line 52 - Module file for simpletest_example
Code
function simpletest_example_node_access($node, $op, $account) {
// Don't get involved if this isn't a simpletest_example node, etc.
$type = is_string($node) ? $node : $node->type;
if ($type != 'simpletest_example' || $op != 'update' && $op != 'delete') {
return NODE_ACCESS_IGNORE;
}
// This code has a BUG that we'll find in testing.
//
// This is the incorrect version we'll use to demonstrate test failure.
// The correct version should have ($op == 'update' || $op == 'delete').
// The author had mistakenly always tested with User 1 so it always
// allowed access and the bug wasn't noticed!
if ($op == 'delete' && (user_access('extra special edit any simpletest_example', $account) && $account->uid == $node->uid)) {
return NODE_ACCESS_ALLOW;
}
return NODE_ACCESS_DENY;
}