Permalink
Browse files

Merge branch 'MDL-63394-master' of git://github.com/jleyva/moodle

  • Loading branch information...
dmonllao committed Nov 19, 2018
2 parents 674c00e + 904c37c commit 9af8b0aef1c2f560e518bdf948f93e00065e6c86
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 9af8b0a

Please sign in to comment.