Skip to content
Permalink
Browse files
Merge branch 'MDL-63394-35' of git://github.com/jleyva/moodle into MO…
…ODLE_35_STABLE
  • Loading branch information
David Monllao committed Nov 20, 2018
2 parents 58c0297 + d555650 commit 3955dde284a597d92bc191d4d1566c65098ca25a
Showing with 24 additions and 3 deletions.
  1. +5 −2 mod/quiz/classes/external.php
  2. +19 −1 mod/quiz/tests/external_test.php
@@ -1240,8 +1240,11 @@ public static function process_attempt($attemptid, $data, $finishattempt = false
);
$params = self::validate_parameters(self::process_attempt_parameters(), $params);

// Do not check access manager rules.
list($attemptobj, $messages) = self::validate_attempt($params, false);
// Do not check access manager rules and evaluate fail if overdue.
$attemptobj = quiz_attempt::create($params['attemptid']);
$failifoverdue = !($attemptobj->get_quizobj()->get_quiz()->overduehandling == 'graceperiod');

list($attemptobj, $messages) = self::validate_attempt($params, false, $failifoverdue);

// Create the $_POST object required by the question engine.
$_POST = array();
@@ -1207,11 +1207,29 @@ public function test_process_attempt() {
$result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
$this->assertEquals(quiz_attempt::OVERDUE, $result['state']);

// Force grace period for time limit.
$quiz->timeclose = 0;
$quiz->timelimit = 1;
$quiz->graceperiod = 60;
$quiz->overduehandling = 'graceperiod';
$DB->update_record('quiz', $quiz);

$timenow = time();
$quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
$attempt = quiz_create_attempt($quizobj, 3, 2, $timenow - 10, false, $this->student->id);
quiz_start_new_attempt($quizobj, $quba, $attempt, 2, $timenow - 10);
quiz_attempt_save_started($quizobj, $quba, $attempt);

$result = mod_quiz_external::process_attempt($attempt->id, array());
$result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
$this->assertEquals(quiz_attempt::OVERDUE, $result['state']);

// New attempt.
$timenow = time();
$quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
$attempt = quiz_create_attempt($quizobj, 3, 2, $timenow, false, $this->student->id);
$attempt = quiz_create_attempt($quizobj, 4, 3, $timenow, false, $this->student->id);
quiz_start_new_attempt($quizobj, $quba, $attempt, 3, $timenow);
quiz_attempt_save_started($quizobj, $quba, $attempt);

0 comments on commit 3955dde

Please sign in to comment.