From d4572c1716a45aed1ba60dba367d46b5b86a540a Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Tue, 28 Apr 2015 11:31:00 +0100 Subject: [PATCH] MDL-50026 quiz: don't show locks for random Qs in deferred feedback can_finish_during_the_attempt was returning the wrong result for random questions for behaviours like deferred feedback. --- mod/quiz/classes/structure.php | 3 +- .../behat/editing_require_previous.feature | 33 +++++++++++++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/mod/quiz/classes/structure.php b/mod/quiz/classes/structure.php index 477ffa2e6a0..a02fabe4051 100644 --- a/mod/quiz/classes/structure.php +++ b/mod/quiz/classes/structure.php @@ -182,7 +182,8 @@ class structure { } if ($this->get_question_type_for_slot($slotnumber) == 'random') { - return true; + return \question_engine::can_questions_finish_during_the_attempt( + $this->quizobj->get_quiz()->preferredbehaviour); } if (isset($this->slotsinorder[$slotnumber]->canfinish)) { diff --git a/mod/quiz/tests/behat/editing_require_previous.feature b/mod/quiz/tests/behat/editing_require_previous.feature index 8a8f3535544..6e1784225d7 100644 --- a/mod/quiz/tests/behat/editing_require_previous.feature +++ b/mod/quiz/tests/behat/editing_require_previous.feature @@ -54,6 +54,24 @@ Feature: Edit quizzes where some questions require the previous one to have been And I follow "Edit quiz" Then "This question cannot be attempted until the previous question has been completed." "link" should be visible + @javascript + Scenario: A question can depend on a random question + Given the following "activities" exist: + | activity | name | intro | course | idnumber | preferredbehaviour | + | quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 | immediatefeedback | + And the following "questions" exist: + | questioncategory | qtype | name | questiontext | + | Test questions | truefalse | TF1 | First question | + | Test questions | random | Random (Test questions) | 0 | + And quiz "Quiz 1" contains the following questions: + | question | page | requireprevious | + | Random (Test questions) | 1 | 0 | + | TF1 | 1 | 1 | + And I follow "Course 1" + And I follow "Quiz 1" + And I follow "Edit quiz" + Then "This question cannot be attempted until the previous question has been completed." "link" should be visible + @javascript Scenario: The second question can be set to depend on the first Given the following "activities" exist: @@ -104,16 +122,19 @@ Feature: Edit quizzes where some questions require the previous one to have been | activity | name | intro | course | idnumber | preferredbehaviour | | quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 | deferredfeedback | And the following "questions" exist: - | questioncategory | qtype | name | questiontext | - | Test questions | truefalse | TF1 | First question | - | Test questions | truefalse | TF2 | Second question | + | questioncategory | qtype | name | questiontext | + | Test questions | truefalse | TF1 | First question | + | Test questions | truefalse | TF2 | Second question | + | Test questions | random | Random (Test questions) | 0 | And quiz "Quiz 1" contains the following questions: - | question | page | requireprevious | - | TF1 | 1 | 0 | - | TF2 | 1 | 1 | + | question | page | requireprevious | + | Random (Test questions) | 1 | 0 | + | TF1 | 1 | 1 | + | TF2 | 1 | 1 | And I follow "Course 1" And I follow "Quiz 1" And I follow "Edit quiz" + Then "be attempted" "link" in the "TF1" "list_item" should not be visible Then "be attempted" "link" in the "TF2" "list_item" should not be visible @javascript