MDL-74184 quiz: prevent repagination of quizzes with attepts

There was a loophole to this rule on the settings form, which is now fixed.
This commit is contained in:
Tim Hunt 2022-03-12 16:21:53 +00:00
parent 0d0f09bc7f
commit 439ecc57fd
3 changed files with 59 additions and 32 deletions

View File

@ -154,7 +154,7 @@ function quiz_update_instance($quiz, $mform) {
quiz_delete_previews($quiz);
// Repaginate, if asked to.
if (!empty($quiz->repaginatenow)) {
if (!empty($quiz->repaginatenow) && !quiz_has_attempts($quiz->id)) {
quiz_repaginate_questions($quiz->id, $quiz->questionsperpage);
}

View File

@ -146,7 +146,7 @@ class mod_quiz_mod_form extends moodleform_mod {
get_string('newpage', 'quiz'), quiz_questions_per_page_options(), array('id' => 'id_questionsperpage'));
$mform->setDefault('questionsperpage', $quizconfig->questionsperpage);
if (!empty($this->_cm)) {
if (!empty($this->_cm) && !quiz_has_attempts($this->_cm->instance)) {
$pagegroup[] = $mform->createElement('checkbox', 'repaginatenow', '',
get_string('repaginatenow', 'quiz'), array('id' => 'id_repaginatenow'));
}

View File

@ -18,13 +18,12 @@ Feature: Settings form fields disabled if not required
| teacher | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
And I log in as "teacher"
And I am on "Course 1" course homepage with editing mode on
And I change window size to "large"
@javascript
Scenario: Depending on the number of attempts, different form fields are disabled.
When I add a "Quiz" to section "1"
When I log in as "teacher"
And I am on "Course 1" course homepage with editing mode on
And I add a "Quiz" to section "1"
And I expand all fieldsets
And I set the field "Name" to "Test quiz"
And I set the field "Attempts allowed" to "1"
@ -33,25 +32,25 @@ Feature: Settings form fields disabled if not required
And the "id_delay1_enabled" "field" should be disabled
And the "id_delay2_enabled" "field" should be disabled
When I set the field "Attempts allowed" to "2"
Then the "Grading method" "field" should be enabled
And I set the field "Attempts allowed" to "2"
And the "Grading method" "field" should be enabled
And the "Each attempt builds on the last" "field" should be enabled
And the "id_delay1_enabled" "field" should be enabled
And the "id_delay2_enabled" "field" should be disabled
When I set the field "Attempts allowed" to "3"
Then the "Grading method" "field" should be enabled
And I set the field "Attempts allowed" to "3"
And the "Grading method" "field" should be enabled
And the "Each attempt builds on the last" "field" should be enabled
And the "id_delay1_enabled" "field" should be enabled
And the "id_delay2_enabled" "field" should be enabled
When I set the field "Attempts allowed" to "Unlimited"
Then the "Grading method" "field" should be enabled
And I set the field "Attempts allowed" to "Unlimited"
And the "Grading method" "field" should be enabled
And the "Each attempt builds on the last" "field" should be enabled
# And the "id_delay1_enabled" "field" should be enabled
# And the "id_delay2_enabled" "field" should be enabled
When I press "Save and display"
And I press "Save and display"
And I navigate to "Overrides" in current page administration
And I press "Add user override"
And I set the following fields to these values:
@ -61,12 +60,12 @@ Feature: Settings form fields disabled if not required
And I navigate to "Settings" in current page administration
And I expand all fieldsets
And I set the field "Attempts allowed" to "1"
Then the "Grading method" "field" should be enabled
And the "Grading method" "field" should be enabled
And the "Each attempt builds on the last" "field" should be enabled
And the "id_delay1_enabled" "field" should be enabled
And the "id_delay2_enabled" "field" should be enabled
When I press "Save and display"
And I press "Save and display"
And I navigate to "Overrides" in current page administration
And I click on "Edit" "link" in the "region-main" "region"
And I set the field "Attempts allowed" to "2"
@ -74,12 +73,12 @@ Feature: Settings form fields disabled if not required
And I navigate to "Settings" in current page administration
And I expand all fieldsets
And I set the field "Attempts allowed" to "1"
Then the "Grading method" "field" should be enabled
And the "Grading method" "field" should be enabled
And the "Each attempt builds on the last" "field" should be enabled
And the "id_delay1_enabled" "field" should be enabled
And the "id_delay2_enabled" "field" should be disabled
When I press "Save and display"
And I press "Save and display"
And I navigate to "Overrides" in current page administration
And I press "Add user override"
And I set the following fields to these values:
@ -89,28 +88,56 @@ Feature: Settings form fields disabled if not required
And I navigate to "Settings" in current page administration
And I expand all fieldsets
And I set the field "Attempts allowed" to "1"
Then the "Grading method" "field" should be enabled
And the "Grading method" "field" should be enabled
And the "Each attempt builds on the last" "field" should be enabled
And the "id_delay1_enabled" "field" should be enabled
And the "id_delay2_enabled" "field" should be enabled
@javascript
Scenario: Depending on whether there is a close date, some review options are disabled.
When I add a "Quiz" to section "1"
When I log in as "teacher"
And I am on "Course 1" course homepage with editing mode on
And I add a "Quiz" to section "1"
And I expand all fieldsets
And I set the field "Name" to "Test quiz"
Then the "id_attemptclosed" "checkbox" should be disabled
Then the "id_correctnessclosed" "checkbox" should be disabled
Then the "id_marksclosed" "checkbox" should be disabled
Then the "id_specificfeedbackclosed" "checkbox" should be disabled
Then the "id_generalfeedbackclosed" "checkbox" should be disabled
Then the "id_rightanswerclosed" "checkbox" should be disabled
Then the "id_overallfeedbackclosed" "checkbox" should be disabled
And the "id_correctnessclosed" "checkbox" should be disabled
And the "id_marksclosed" "checkbox" should be disabled
And the "id_specificfeedbackclosed" "checkbox" should be disabled
And the "id_generalfeedbackclosed" "checkbox" should be disabled
And the "id_rightanswerclosed" "checkbox" should be disabled
And the "id_overallfeedbackclosed" "checkbox" should be disabled
And I set the field "id_timeclose_enabled" to "1"
Then the "id_attemptclosed" "checkbox" should be enabled
Then the "id_correctnessclosed" "checkbox" should be enabled
Then the "id_marksclosed" "checkbox" should be enabled
Then the "id_specificfeedbackclosed" "checkbox" should be enabled
Then the "id_generalfeedbackclosed" "checkbox" should be enabled
Then the "id_rightanswerclosed" "checkbox" should be enabled
Then the "id_overallfeedbackclosed" "checkbox" should be enabled
And the "id_attemptclosed" "checkbox" should be enabled
And the "id_correctnessclosed" "checkbox" should be enabled
And the "id_marksclosed" "checkbox" should be enabled
And the "id_specificfeedbackclosed" "checkbox" should be enabled
And the "id_generalfeedbackclosed" "checkbox" should be enabled
And the "id_rightanswerclosed" "checkbox" should be enabled
And the "id_overallfeedbackclosed" "checkbox" should be enabled
And I should not see "Repaginate now"
@javascript
Scenario: If there are quiz attempts, there is not option to repaginate.
Given the following "activities" exist:
| activity | name | intro | course | idnumber |
| quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 |
And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | truefalse | TF1 | First question |
| Test questions | truefalse | TF2 | Second question |
And quiz "Quiz 1" contains the following questions:
| question | page | maxmark |
| TF1 | 1 | |
When I am on the "Quiz 1" "quiz activity editing" page logged in as teacher
And I expand all fieldsets
Then I should see "Repaginate now"
And user "student1" has attempted "Quiz 1" with responses:
| slot | response |
| 1 | True |
And I am on the "Quiz 1" "quiz activity editing" page
And I expand all fieldsets
And I should not see "Repaginate now"