Skip to content

Commit

Permalink
Merge branch 'MDL-63394-35' of git://github.com/jleyva/moodle into MO…
Browse files Browse the repository at this point in the history
…ODLE_35_STABLE
  • Loading branch information
David Monllao committed Nov 20, 2018
2 parents 58c0297 + d555650 commit 3955dde
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
7 changes: 5 additions & 2 deletions mod/quiz/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 19 additions & 1 deletion mod/quiz/tests/external_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 3955dde

Please sign in to comment.