function simpletest_example_access in Examples for Developers 6
Implementation of hook_access().
Related topics
File
- simpletest_example/
simpletest_example.module, line 49 - An example of simpletest tests to accompany the tutorial at http://drupal.org/node/395012.
Code
function simpletest_example_access($op, $node) {
global $user;
if ($op == 'create') {
return user_access('create simpletest_example');
}
// This code has a BUG that we'll find in testing
// Correct version
// if ($op == 'update' || $op == 'delete') {
// Incorrect version we'll use to demonstrate test failure. We were always testing
// with User 1, so it always allowed access and the bug wasn't noticed!
if ($op == 'delete') {
return user_access('edit own simpletest_example') && $user->uid == $node->uid;
}
}