Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'MDL-35744_23' of git://github.com/timhunt/moodle into M…

…OODLE_23_STABLE
  • Loading branch information...
commit a8d7f5cf15a8c47ec904511a329d71ca813a663a 2 parents c67ed6a + db1052c
@stronk7 stronk7 authored
Showing with 89 additions and 1 deletion.
  1. +1 −1  mod/quiz/locallib.php
  2. +88 −0 mod/quiz/tests/locallib_test.php
View
2  mod/quiz/locallib.php
@@ -987,7 +987,7 @@ function quiz_get_flag_option($attempt, $context) {
* IMMEDIATELY_AFTER, LATER_WHILE_OPEN or AFTER_CLOSE constants.
*/
function quiz_attempt_state($quiz, $attempt) {
- if ($attempt->state != quiz_attempt::FINISHED) {
+ if ($attempt->state == quiz_attempt::IN_PROGRESS) {
return mod_quiz_display_options::DURING;
} else if (time() < $attempt->timefinish + 120) {
return mod_quiz_display_options::IMMEDIATELY_AFTER;
View
88 mod/quiz/tests/locallib_test.php
@@ -151,4 +151,92 @@ public function test_quiz_get_slot_for_question() {
$this->assertEquals(1, quiz_get_slot_for_question($quiz, 1));
$this->assertEquals(3, quiz_get_slot_for_question($quiz, 7));
}
+
+ public function test_quiz_attempt_state_in_progress() {
+ $attempt = new stdClass();
+ $attempt->state = quiz_attempt::IN_PROGRESS;
+ $attempt->timefinish = 0;
+
+ $quiz = new stdClass();
+ $quiz->timeclose = 0;
+
+ $this->assertEquals(mod_quiz_display_options::DURING, quiz_attempt_state($quiz, $attempt));
+ }
+
+ public function test_quiz_attempt_state_recently_submitted() {
+ $attempt = new stdClass();
+ $attempt->state = quiz_attempt::FINISHED;
+ $attempt->timefinish = time() - 10;
+
+ $quiz = new stdClass();
+ $quiz->timeclose = 0;
+
+ $this->assertEquals(mod_quiz_display_options::IMMEDIATELY_AFTER, quiz_attempt_state($quiz, $attempt));
+ }
+
+ public function test_quiz_attempt_state_sumitted_quiz_never_closes() {
+ $attempt = new stdClass();
+ $attempt->state = quiz_attempt::FINISHED;
+ $attempt->timefinish = time() - 7200;
+
+ $quiz = new stdClass();
+ $quiz->timeclose = 0;
+
+ $this->assertEquals(mod_quiz_display_options::LATER_WHILE_OPEN, quiz_attempt_state($quiz, $attempt));
+ }
+
+ public function test_quiz_attempt_state_sumitted_quiz_closes_later() {
+ $attempt = new stdClass();
+ $attempt->state = quiz_attempt::FINISHED;
+ $attempt->timefinish = time() - 7200;
+
+ $quiz = new stdClass();
+ $quiz->timeclose = time() + 3600;
+
+ $this->assertEquals(mod_quiz_display_options::LATER_WHILE_OPEN, quiz_attempt_state($quiz, $attempt));
+ }
+
+ public function test_quiz_attempt_state_sumitted_quiz_closed() {
+ $attempt = new stdClass();
+ $attempt->state = quiz_attempt::FINISHED;
+ $attempt->timefinish = time() - 7200;
+
+ $quiz = new stdClass();
+ $quiz->timeclose = time() - 3600;
+
+ $this->assertEquals(mod_quiz_display_options::AFTER_CLOSE, quiz_attempt_state($quiz, $attempt));
+ }
+
+ public function test_quiz_attempt_state_never_sumitted_quiz_never_closes() {
+ $attempt = new stdClass();
+ $attempt->state = quiz_attempt::ABANDONED;
+ $attempt->timefinish = 1000; // A very long time ago!
+
+ $quiz = new stdClass();
+ $quiz->timeclose = 0;
+
+ $this->assertEquals(mod_quiz_display_options::LATER_WHILE_OPEN, quiz_attempt_state($quiz, $attempt));
+ }
+
+ public function test_quiz_attempt_state_never_sumitted_quiz_closes_later() {
+ $attempt = new stdClass();
+ $attempt->state = quiz_attempt::ABANDONED;
+ $attempt->timefinish = time() - 7200;
+
+ $quiz = new stdClass();
+ $quiz->timeclose = time() + 3600;
+
+ $this->assertEquals(mod_quiz_display_options::LATER_WHILE_OPEN, quiz_attempt_state($quiz, $attempt));
+ }
+
+ public function test_quiz_attempt_state_never_sumitted_quiz_closed() {
+ $attempt = new stdClass();
+ $attempt->state = quiz_attempt::ABANDONED;
+ $attempt->timefinish = time() - 7200;
+
+ $quiz = new stdClass();
+ $quiz->timeclose = time() - 3600;
+
+ $this->assertEquals(mod_quiz_display_options::AFTER_CLOSE, quiz_attempt_state($quiz, $attempt));
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.