MDL-52014 quiz: do not log preview attempt deletions

This happens automatically by the system.
This commit is contained in:
Dan Poltawski
2015-11-02 16:19:19 +00:00
parent c12979c7df
commit 1dcf6b339a
2 changed files with 36 additions and 14 deletions
+14 -12
View File
@@ -362,18 +362,20 @@ function quiz_delete_attempt($attempt, $quiz) {
question_engine::delete_questions_usage_by_activity($attempt->uniqueid);
$DB->delete_records('quiz_attempts', array('id' => $attempt->id));
// Log the deletion of the attempt.
$params = array(
'objectid' => $attempt->id,
'relateduserid' => $attempt->userid,
'context' => context_module::instance($quiz->cmid),
'other' => array(
'quizid' => $quiz->id
)
);
$event = \mod_quiz\event\attempt_deleted::create($params);
$event->add_record_snapshot('quiz_attempts', $attempt);
$event->trigger();
// Log the deletion of the attempt if not a preview.
if (!$attempt->preview) {
$params = array(
'objectid' => $attempt->id,
'relateduserid' => $attempt->userid,
'context' => context_module::instance($quiz->cmid),
'other' => array(
'quizid' => $quiz->id
)
);
$event = \mod_quiz\event\attempt_deleted::create($params);
$event->add_record_snapshot('quiz_attempts', $attempt);
$event->trigger();
}
// Search quiz_attempts for other instances by this user.
// If none, then delete record for this quiz, this user from quiz_grades
+22 -2
View File
@@ -38,7 +38,12 @@ require_once($CFG->dirroot . '/mod/quiz/attemptlib.php');
*/
class mod_quiz_events_testcase extends advanced_testcase {
protected function prepare_quiz_data() {
/**
* Setup some convenience test data with a single attempt.
*
* @param bool $ispreview Make the attempt a preview attempt when true.
*/
protected function prepare_quiz_data($ispreview = false) {
$this->resetAfterTest(true);
@@ -75,7 +80,7 @@ class mod_quiz_events_testcase extends advanced_testcase {
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
$timenow = time();
$attempt = quiz_create_attempt($quizobj, 1, false, $timenow);
$attempt = quiz_create_attempt($quizobj, 1, false, $timenow, $ispreview);
quiz_start_new_attempt($quizobj, $quba, $attempt, 1, $timenow);
quiz_attempt_save_started($quizobj, $quba, $attempt);
@@ -283,6 +288,21 @@ class mod_quiz_events_testcase extends advanced_testcase {
$this->assertEventContextNotUsed($event);
}
/**
* Test that preview attempt deletions are not logged.
*/
public function test_preview_attempt_deleted() {
// Create quiz with preview attempt.
list($quizobj, $quba, $previewattempt) = $this->prepare_quiz_data(true);
// Delete a preview attempt, capturing events.
$sink = $this->redirectEvents();
quiz_delete_attempt($previewattempt, $quizobj->get_quiz());
// Verify that no events were generated.
$this->assertEmpty($sink->get_events());
}
/**
* Test the report viewed event.
*