mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
MDL-74007 quiz: questions should start as 'Always latest' version
Thanks to Safat Shahin <safatshahin@catalyst-au.net> for help with the Behat scenarios.
This commit is contained in:
parent
1d99ba19a2
commit
61f11f848d
@ -57,6 +57,8 @@ class restore_quiz_decode_testcase extends \core_privacy\tests\provider_testcase
|
||||
|
||||
// Add to the quiz.
|
||||
quiz_add_quiz_question($question->id, $quiz);
|
||||
mod_quiz\external\submit_question_version::execute(
|
||||
$DB->get_field('quiz_slots', 'id', ['quizid' => $quiz->id, 'slot' => 1]), 1);
|
||||
|
||||
$questiondata = question_bank::load_question_data($question->id);
|
||||
|
||||
@ -81,7 +83,7 @@ class restore_quiz_decode_testcase extends \core_privacy\tests\provider_testcase
|
||||
$quizquestions = \mod_quiz\question\bank\qbank_helper::get_question_structure_data($newcm->instance);
|
||||
$questionids = [];
|
||||
foreach ($quizquestions as $quizquestion) {
|
||||
$questionids [] = $quizquestion->id;
|
||||
$questionids[] = $quizquestion->id;
|
||||
}
|
||||
list($condition, $param) = $DB->get_in_or_equal($questionids, SQL_PARAMS_NAMED, 'questionid');
|
||||
$condition = 'WHERE qa.question ' . $condition;
|
||||
|
@ -2396,9 +2396,7 @@ function quiz_add_quiz_question($questionid, $quiz, $page = 0, $maxmark = null)
|
||||
$questionreferences->questionarea = 'slot';
|
||||
$questionreferences->itemid = $slotid;
|
||||
$questionreferences->questionbankentryid = get_question_bank_entry($questionid)->id;
|
||||
$version = get_question_version($questionid);
|
||||
$questionreferences->version = $version[array_key_first($version)]->version;
|
||||
|
||||
$questionreferences->version = null; // Always latest.
|
||||
$DB->insert_record('question_references', $questionreferences);
|
||||
|
||||
} else if ($qreferenceitem->itemid === 0 || $qreferenceitem->itemid === null) {
|
||||
@ -2414,8 +2412,7 @@ function quiz_add_quiz_question($questionid, $quiz, $page = 0, $maxmark = null)
|
||||
$questionreferences->questionarea = 'slot';
|
||||
$questionreferences->itemid = $slotid;
|
||||
$questionreferences->questionbankentryid = get_question_bank_entry($questionid)->id;
|
||||
$version = get_question_version($questionid);
|
||||
$questionreferences->version = $version[array_key_first($version)]->version;
|
||||
$questionreferences->version = null; // Always latest.
|
||||
$DB->insert_record('question_references', $questionreferences);
|
||||
}
|
||||
|
||||
|
@ -76,3 +76,27 @@ Feature: Quiz question versioning
|
||||
And I press "id_saveupdate"
|
||||
And I click on "finish" "button"
|
||||
Then I should see "The correct answer is 'False'."
|
||||
|
||||
@javascript
|
||||
Scenario: Creating a new question should have always latest in the version selection
|
||||
When I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1"
|
||||
And I click on "Add" "link"
|
||||
And I follow "a new question"
|
||||
And I set the field "item_qtype_essay" to "1"
|
||||
And I press "submitbutton"
|
||||
Then I should see "Adding an Essay question"
|
||||
And I set the field "Question name" to "Essay 01 new"
|
||||
And I set the field "Question text" to "Please write 200 words about Essay 01"
|
||||
And I press "id_submitbutton"
|
||||
And I should see "Essay 01 new" on quiz page "1"
|
||||
And I should see "Always latest" on quiz page "1"
|
||||
|
||||
@javascript
|
||||
Scenario: Adding a question from question bank should have always latest in the version selection
|
||||
When I am on the "Quiz 1" "mod_quiz > Edit" page logged in as "teacher1"
|
||||
And I click on "Add" "link"
|
||||
And I follow "from question bank"
|
||||
And I set the field with xpath "//input[@type='checkbox' and @id='qbheadercheckbox']" to "1"
|
||||
And I press "Add selected questions to the quiz"
|
||||
And I should see "First question" on quiz page "1"
|
||||
And I should see "Always latest" on quiz page "1"
|
||||
|
@ -204,6 +204,7 @@ class qbank_helper_test extends \advanced_testcase {
|
||||
* @covers ::get_specific_version_question_ids
|
||||
*/
|
||||
public function test_get_specific_version_question_ids() {
|
||||
global $DB;
|
||||
$this->resetAfterTest();
|
||||
$quiz = $this->create_test_quiz($this->course);
|
||||
// Test for questions from a different context.
|
||||
@ -217,6 +218,7 @@ class qbank_helper_test extends \advanced_testcase {
|
||||
$questiongenerator->update_question($numq, null, ['name' => 'This is the second version']);
|
||||
$questiongenerator->update_question($numq, null, ['name' => 'This is the third version']);
|
||||
quiz_add_quiz_question($numq->id, $quiz);
|
||||
submit_question_version::execute($DB->get_field('quiz_slots', 'id', ['quizid' => $quiz->id, 'slot' => 1]), 3);
|
||||
$specificversionquestionid = qbank_helper::get_specific_version_question_ids($quiz->id);
|
||||
$specificversionquestionid = reset($specificversionquestionid);
|
||||
$this->assertEquals($numq->id, $specificversionquestionid);
|
||||
|
@ -72,7 +72,7 @@ class quiz_question_version_test extends \advanced_testcase {
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$slots = $structure->get_slots();
|
||||
$slot = reset($slots);
|
||||
// Test that the version added is the latest version, as there are three created.
|
||||
// Test that the version added is 'always latest'.
|
||||
$this->assertEquals(3, $slot->version);
|
||||
$quizobj->preload_questions();
|
||||
$quizobj->load_questions();
|
||||
@ -80,9 +80,22 @@ class quiz_question_version_test extends \advanced_testcase {
|
||||
$question = reset($questions);
|
||||
$this->assertEquals(3, $question->version);
|
||||
$this->assertEquals('This is the third version', $question->name);
|
||||
// Create another version.
|
||||
$questiongenerator->update_question($numq, null, ['name' => 'This is the latest version']);
|
||||
// Check that 'Always latest is working'.
|
||||
$quizobj->preload_questions();
|
||||
$quizobj->load_questions();
|
||||
$questions = $quizobj->get_questions();
|
||||
$question = reset($questions);
|
||||
$this->assertEquals(4, $question->version);
|
||||
$this->assertEquals('This is the latest version', $question->name);
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$slots = $structure->get_slots();
|
||||
$slot = reset($slots);
|
||||
$this->assertEquals(4, $slot->version);
|
||||
// Now change the version using the external service.
|
||||
$versions = qbank_helper::get_version_options($slot->questionid);
|
||||
// We dont want the current version.
|
||||
// We don't want the current version.
|
||||
$selectversions = [];
|
||||
foreach ($versions as $version) {
|
||||
if ($version->version === $slot->version) {
|
||||
@ -114,20 +127,6 @@ class quiz_question_version_test extends \advanced_testcase {
|
||||
$slots = $structure->get_slots();
|
||||
$slot = reset($slots);
|
||||
$this->assertEquals(2, $slot->version);
|
||||
// Create another version.
|
||||
$questiongenerator->update_question($numq, null, ['name' => 'This is the latest version']);
|
||||
// Change to always latest.
|
||||
submit_question_version::execute($slot->id, 0);
|
||||
$quizobj->preload_questions();
|
||||
$quizobj->load_questions();
|
||||
$questions = $quizobj->get_questions();
|
||||
$question = reset($questions);
|
||||
$this->assertEquals(4, $question->version);
|
||||
$this->assertEquals('This is the latest version', $question->name);
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$slots = $structure->get_slots();
|
||||
$slot = reset($slots);
|
||||
$this->assertEquals(4, $slot->version);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user