function test_everything()
 {
     // Add a bunch of comments
     ouwiki_add_comment(13, 'frog', 'Frogs', 'My happy comment', 'This comment has a title');
     ouwiki_add_comment(13, 'frog', 'Frogs', null, 'This one does not');
     ouwiki_add_comment(13, null, null, null, 'This comment is on the main page section');
     ouwiki_add_comment(13, 'zombie', 'Zombies', null, 'This one is on a different section');
     ouwiki_add_comment(66, null, null, null, 'This one is on another page');
     ouwiki_add_comment(66, 'frog', 'Frogs', null, 'This one is on another page but same section');
     ouwiki_add_comment(13, null, null, null, 'Main 2', 2);
     ouwiki_add_comment(13, null, null, null, 'Main 3', OUWIKI_SYSTEMUSER);
     ouwiki_add_comment(13, null, null, null, 'Main 4');
     ouwiki_add_comment(13, 'frog', 'Frogs', null, 'Frog 3');
     ouwiki_add_comment(13, 'frog', 'Frogs', null, 'Frog 4');
     ouwiki_add_comment(13, 'frog', 'Frogs', null, 'Frog 5');
     // Check sections
     $sections = get_records('ouwiki_sections');
     $this->assertEqual(count($sections), 5);
     $this->assertEqual((array) array_shift($sections), array('pageid' => 13, 'xhtmlid' => 'frog', 'title' => 'Frogs', 'id' => 1));
     $this->assertEqual((array) array_shift($sections), array('pageid' => 13, 'xhtmlid' => null, 'title' => null, 'id' => 2));
     $this->assertEqual((array) array_shift($sections), array('pageid' => 13, 'xhtmlid' => 'zombie', 'title' => 'Zombies', 'id' => 3));
     $this->assertEqual((array) array_shift($sections), array('pageid' => 66, 'xhtmlid' => null, 'title' => null, 'id' => 4));
     $this->assertEqual((array) array_shift($sections), array('pageid' => 66, 'xhtmlid' => 'frog', 'title' => 'Frogs', 'id' => 5));
     $comments = get_records('ouwiki_comments');
     $this->assertEqual(count($comments), 12);
     // Check timeposted once then chuck it because it makes comparison harder
     $this->assertTrue(time() - $comments[1]->timeposted < 5 && time() - $comments[1]->timeposted >= 0);
     for ($i = 1; $i <= 12; $i++) {
         unset($comments[$i]->timeposted);
     }
     $this->assertEqual((array) array_shift($comments), array('sectionid' => 1, 'title' => 'My happy comment', 'xhtml' => 'This comment has a title', 'userid' => 1, 'deleted' => 0, 'id' => 1));
     $this->assertEqual((array) array_shift($comments), array('sectionid' => 1, 'title' => null, 'xhtml' => 'This one does not', 'userid' => 1, 'deleted' => 0, 'id' => 2));
     $this->assertEqual((array) array_shift($comments), array('sectionid' => 2, 'title' => null, 'xhtml' => 'This comment is on the main page section', 'userid' => 1, 'deleted' => 0, 'id' => 3));
     $this->assertEqual((array) array_shift($comments), array('sectionid' => 3, 'title' => null, 'xhtml' => 'This one is on a different section', 'userid' => 1, 'deleted' => 0, 'id' => 4));
     $this->assertEqual((array) array_shift($comments), array('sectionid' => 4, 'title' => null, 'xhtml' => 'This one is on another page', 'userid' => 1, 'deleted' => 0, 'id' => 5));
     $this->assertEqual((array) array_shift($comments), array('sectionid' => 5, 'title' => null, 'xhtml' => 'This one is on another page but same section', 'userid' => 1, 'deleted' => 0, 'id' => 6));
     $this->assertEqual((array) array_shift($comments), array('sectionid' => 2, 'title' => null, 'xhtml' => 'Main 2', 'userid' => 2, 'deleted' => 0, 'id' => 7));
     $this->assertEqual((array) array_shift($comments), array('sectionid' => 2, 'title' => null, 'xhtml' => 'Main 3', 'userid' => null, 'deleted' => 0, 'id' => 8));
     $this->assertEqual((array) array_shift($comments), array('sectionid' => 2, 'title' => null, 'xhtml' => 'Main 4', 'userid' => 1, 'deleted' => 0, 'id' => 9));
     $this->assertEqual((array) array_shift($comments), array('sectionid' => 1, 'title' => null, 'xhtml' => 'Frog 3', 'userid' => 1, 'deleted' => 0, 'id' => 10));
     $this->assertEqual((array) array_shift($comments), array('sectionid' => 1, 'title' => null, 'xhtml' => 'Frog 4', 'userid' => 1, 'deleted' => 0, 'id' => 11));
     $this->assertEqual((array) array_shift($comments), array('sectionid' => 1, 'title' => null, 'xhtml' => 'Frog 5', 'userid' => 1, 'deleted' => 0, 'id' => 12));
     // Now delete Frog 3
     ouwiki_delete_comment(13, 10, 1);
     $comment = get_record('ouwiki_comments', 'id', 10);
     unset($comment->timeposted);
     $this->assertEqual((array) $comment, array('sectionid' => 1, 'title' => null, 'xhtml' => 'Frog 3', 'userid' => 1, 'deleted' => 1, 'id' => 10));
     // Check query for all content...
     $comments = ouwiki_get_all_comments(13, 'frog');
     $comment = $comments[1];
     unset($comment->timeposted);
     // Ensure comments have all expected details (just taking one example)
     $this->assertEqual((array) $comment, array('sectionid' => 1, 'title' => 'My happy comment', 'xhtml' => 'This comment has a title', 'userid' => 1, 'deleted' => 0, 'sectiontitle' => 'Frogs', 'section' => 'frog', 'firstname' => 'user', 'lastname' => 'one', 'username' => 'u1', 'id' => 1));
     // Now check correct comments are included
     $this->assertEqual(self::get_id_array($comments), array(1, 2, 11, 12));
     // Check it works to include deleted ones if asked
     $comments = ouwiki_get_all_comments(13, 'frog', true);
     $this->assertEqual(self::get_id_array($comments), array(1, 2, 10, 11, 12));
     // Ask for comments from main section with everything else valid...
     $comments = ouwiki_get_all_comments(13, null, false, array('frog' => 0, 'zombie' => 0));
     $this->assertEqual(self::get_id_array($comments), array(3, 7, 8, 9));
     // ...and with nothing else valid
     $comments = ouwiki_get_all_comments(13, null, false, array());
     $this->assertEqual(self::get_id_array($comments), array(1, 2, 3, 4, 7, 8, 9, 11, 12));
     // Check query for page-display content
     $comments = ouwiki_get_recent_comments(13, array('frog' => 0, 'zombie' => 0));
     $this->assertEqual($comments['']->count, 4);
     $this->assertEqual(self::get_id_array($comments['']->comments), array(7, 8, 9));
     $this->assertEqual($comments['frog']->count, 4);
     $this->assertEqual(self::get_id_array($comments['frog']->comments), array(2, 11, 12));
     $this->assertEqual($comments['zombie']->count, 1);
     $this->assertEqual(self::get_id_array($comments['zombie']->comments), array(4));
 }
    redirect($url);
    exit;
}
// Check permission
$comment = get_record('ouwiki_comments', 'id', $commentid);
$candelete = has_capability('mod/ouwiki:deletecomments', $context);
global $USER;
$owncomment = $comment->userid == $USER->id;
if (!$owncomment && !$candelete) {
    error('You do not have permission to delete this comment');
}
$confirmed = optional_param('confirm', 0, PARAM_INT);
// Admin users don't have to confirm delete since they can undelete
if ($candelete || $confirmed) {
    // Delete comment
    ouwiki_delete_comment($pageversion->pageid, $commentid, $delete);
    // Redirect
    redirect($url);
} else {
    // Display confirm form
    $nav = get_string('commentdelete', 'ouwiki');
    ouwiki_print_start($ouwiki, $cm, $course, $subwiki, $pagename, $context, array(array('name' => $nav, 'type' => 'ouwiki')), true, true);
    print_box_start();
    print '<p>' . get_string('commentdeleteconfirm', 'ouwiki') . '</p>';
    print '<form action="deletecomment.php" method="post">';
    print ouwiki_display_wiki_parameters($pageversion->title, $subwiki, $cm, OUWIKI_PARAMS_FORM);
    print '<input type="hidden" name="sesskey" value="' . sesskey() . '" />' . '<input type="hidden" name="comment" value="' . $commentid . '" />' . '<input type="hidden" name="section" value="' . $section . '" />' . '<input type="hidden" name="delete" value="' . $delete . '" />' . '<input type="hidden" name="confirm" value="1" />' . '<input type="submit" name="action" value="' . get_string('commentdelete', 'ouwiki') . '"/> ' . '<input type="submit" name="cancel" value="' . get_string('cancel') . '"/>';
    print '</form>';
    print_box_end();
    ouwiki_print_footer($course, $cm, $subwiki, $pagename);
}