Skip to content

Commit

Permalink
Merge branch 'MDL-77913-400' of https://github.com/paulholden/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_400_STABLE
  • Loading branch information
sarjona committed Apr 14, 2023
2 parents 9cae117 + 53f5432 commit 95b427d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 2 additions & 1 deletion question/bank/previewquestion/classes/helper.php
Expand Up @@ -311,7 +311,8 @@ public static function load_versions(string $questionbankentryid) : array {
$questionids = [];
$sql = 'SELECT version, questionid
FROM {question_versions}
WHERE questionbankentryid = ?';
WHERE questionbankentryid = ?
ORDER BY version';

$versions = $DB->get_records_sql($sql, [$questionbankentryid]);
foreach ($versions as $key => $version) {
Expand Down
15 changes: 11 additions & 4 deletions question/bank/previewquestion/tests/qbank_preview_helper_test.php
Expand Up @@ -221,21 +221,28 @@ public function test_get_preview_extra_elements() {
* @covers ::load_versions
*/
public function test_load_versions() {
global $DB;
$this->resetAfterTest();

$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$qcat1 = $generator->create_question_category(['name' => 'My category', 'sortorder' => 1, 'idnumber' => 'myqcat']);
$questiongenerated = $generator->create_question('description', null, ['name' => 'q1', 'category' => $qcat1->id]);

$qtypeobj = question_bank::get_qtype($questiongenerated->qtype);
$question = question_bank::load_question($questiongenerated->id);
$versionids = helper::load_versions($question->questionbankentryid);
$this->assertCount(1, $versionids);
$this->assertEquals([
$question->id => 1,
], $versionids);

$fromform = new stdClass();
$fromform->name = 'Name edited';
$fromform->category = $qcat1->id;
$qtypeobj->save_question($questiongenerated, $fromform);
$questiontwo = $qtypeobj->save_question($questiongenerated, $fromform);
$versionids = helper::load_versions($question->questionbankentryid);
$this->assertCount(2, $versionids);
$this->assertSame([
$question->id => 1,
$questiontwo->id => 2,
], $versionids);
}

/**
Expand Down

0 comments on commit 95b427d

Please sign in to comment.