array( 'name' => t('simpletest_example page'), 'module' => 'simpletest_example', 'description' => t('simpletest_example page node type.'), ) ); } /** * Implementation of hook_perm(). */ function simpletest_example_perm() { return array('create simpletest_example', 'edit own simpletest_example'); } /** * Implementation of hook_access(). */ 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)); } } /** * Implementation of hook_form(). */ function simpletest_example_form(&$node) { $type = node_get_types('type', $node); if ($type->has_title) { $form['title'] = array( '#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5 ); } if ($type->has_body) { $form['body_field'] = node_body_field($node, $type->body_label, $type->min_word_count); } return $form; } /** * Implementation of hook_menu(). * * Provide an explanation. */ function simpletest_example_menu() { $items['examples/simpletest_example'] = array( 'title' => 'SimpleTest Example', 'description' => 'Explain the SimpleTest example.', 'page callback' => '_simpletest_example_explanation', 'access callback' => TRUE, ); return $items; } /** * Page to explain this example. */ function _simpletest_example_explanation() { $explanation = t("This SimpleTest Example is designed to give an introductory tutorial to writing a SimpleTest test. Please see the associated tutorial."); return $explanation; } /** * @} End of "defgroup simpletest_example". */