| Línea 27... |
Línea 27... |
| 27 |
* @copyright 2021 Catalyst IT Australia Pty Ltd
|
27 |
* @copyright 2021 Catalyst IT Australia Pty Ltd
|
| 28 |
* @author Guillermo Gomez Arias <guillermogomez@catalyst-au.net>
|
28 |
* @author Guillermo Gomez Arias <guillermogomez@catalyst-au.net>
|
| 29 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
29 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 30 |
* @coversDefaultClass \question_bank
|
30 |
* @coversDefaultClass \question_bank
|
| 31 |
*/
|
31 |
*/
|
| 32 |
class version_test extends \advanced_testcase {
|
32 |
final class version_test extends \advanced_testcase {
|
| Línea 33... |
Línea 33... |
| 33 |
|
33 |
|
| 34 |
/**
|
34 |
/**
|
| 35 |
* @var \context_module module context.
|
35 |
* @var \context_module module context.
|
| 36 |
*/
|
36 |
*/
|
| Línea 201... |
Línea 201... |
| 201 |
global $DB;
|
201 |
global $DB;
|
| Línea 202... |
Línea 202... |
| 202 |
|
202 |
|
| 203 |
$qcategory = $this->qgenerator->create_question_category(['contextid' => $this->context->id]);
|
203 |
$qcategory = $this->qgenerator->create_question_category(['contextid' => $this->context->id]);
|
| 204 |
$qcategorychild = $this->qgenerator->create_question_category(['contextid' => $this->context->id,
|
204 |
$qcategorychild = $this->qgenerator->create_question_category(['contextid' => $this->context->id,
|
| - |
|
205 |
'parent' => $qcategory->id]);
|
| 205 |
'parent' => $qcategory->id]);
|
206 |
$qbank = self::getDataGenerator()->create_module('qbank', ['course' => $this->course->id]);
|
| 206 |
$systemcontext = \context_system::instance();
|
207 |
$bankcontext = \context_module::instance($qbank->cmid);
|
| 207 |
$qcategorysys = $this->qgenerator->create_question_category(['contextid' => $systemcontext->id]);
|
208 |
$qcategorysys = $this->qgenerator->create_question_category(['contextid' => $bankcontext->id]);
|
| 208 |
$question = $this->qgenerator->create_question('shortanswer', null, ['category' => $qcategorychild->id]);
|
209 |
$question = $this->qgenerator->create_question('shortanswer', null, ['category' => $qcategorychild->id]);
|
| Línea 209... |
Línea 210... |
| 209 |
$questiondefinition = question_bank::load_question($question->id);
|
210 |
$questiondefinition = question_bank::load_question($question->id);
|
| 210 |
|
211 |
|
| Línea 211... |
Línea 212... |
| 211 |
// Add it to the quiz.
|
212 |
// Add it to the quiz.
|
| 212 |
quiz_add_quiz_question($question->id, $this->quiz);
|
- |
|
| 213 |
|
- |
|
| 214 |
// Move the category to system context.
|
- |
|
| 215 |
$contexts = new \core_question\local\bank\question_edit_contexts($systemcontext);
|
- |
|
| 216 |
$qcobject = new \qbank_managecategories\question_category_object(null,
|
213 |
quiz_add_quiz_question($question->id, $this->quiz);
|
| 217 |
new \moodle_url('/question/bank/managecategories/category.php', ['courseid' => SITEID]),
|
214 |
|
| Línea 218... |
Línea 215... |
| 218 |
$contexts->having_one_edit_tab_cap('categories'), 0, null, 0,
|
215 |
// Move the category to qbank context.
|
| 219 |
$contexts->having_cap('moodle/question:add'));
|
216 |
$manager = new category_manager();
|
| 220 |
$qcobject->move_questions_and_delete_category($qcategorychild->id, $qcategorysys->id);
|
217 |
$manager->move_questions_and_delete_category($qcategorychild->id, $qcategorysys->id);
|
| 221 |
|
218 |
|
| Línea 326... |
Línea 323... |
| 326 |
$this->assertEquals($questionbankentryid->questionbankentryid, $questionbankentryids);
|
323 |
$this->assertEquals($questionbankentryid->questionbankentryid, $questionbankentryids);
|
| 327 |
$this->assertEquals($questionversions, $questionversionsofquestions[$questionbankentryids]);
|
324 |
$this->assertEquals($questionversions, $questionversionsofquestions[$questionbankentryids]);
|
| 328 |
}
|
325 |
}
|
| Línea 329... |
Línea 326... |
| 329 |
|
326 |
|
| - |
|
327 |
/**
|
| - |
|
328 |
* Test the get_version_of_questions function.
|
| - |
|
329 |
*
|
| - |
|
330 |
* @covers ::get_version_of_questions
|
| - |
|
331 |
*/
|
| - |
|
332 |
public function test_get_version_of_questions(): void {
|
| - |
|
333 |
global $DB;
|
| - |
|
334 |
|
| - |
|
335 |
$qcategory = $this->qgenerator->create_question_category(['contextid' => $this->context->id]);
|
| - |
|
336 |
$question = $this->qgenerator->create_question('shortanswer', null, ['category' => $qcategory->id]);
|
| - |
|
337 |
|
| - |
|
338 |
// Update the question to create new versions.
|
| - |
|
339 |
$question = $this->qgenerator->update_question($question, null, ['name' => 'Version 2']);
|
| - |
|
340 |
|
| - |
|
341 |
// Get the current version of the question.
|
| - |
|
342 |
$currentversions = question_bank::get_version_of_questions([$question->id]);
|
| - |
|
343 |
|
| - |
|
344 |
// Get questionbankentryid for assertion.
|
| - |
|
345 |
$questionbankentryid = $DB->get_field('question_versions', 'questionbankentryid',
|
| - |
|
346 |
['questionid' => $question->id]);
|
| - |
|
347 |
|
| - |
|
348 |
// Assert that the structure matches.
|
| - |
|
349 |
$this->assertArrayHasKey($questionbankentryid, $currentversions);
|
| - |
|
350 |
$this->assertArrayHasKey(2, $currentversions[$questionbankentryid]);
|
| - |
|
351 |
$this->assertEquals($question->id, $currentversions[$questionbankentryid][2]);
|
| - |
|
352 |
|
| - |
|
353 |
// Update the question to create new versions.
|
| - |
|
354 |
$question = $this->qgenerator->update_question($question, null, ['name' => 'Version 3']);
|
| - |
|
355 |
$currentversions = question_bank::get_version_of_questions([$question->id]);
|
| - |
|
356 |
|
| - |
|
357 |
// Assert the updated version.
|
| - |
|
358 |
$this->assertArrayHasKey($questionbankentryid, $currentversions);
|
| - |
|
359 |
$this->assertArrayHasKey(3, $currentversions[$questionbankentryid]);
|
| - |
|
360 |
$this->assertEquals($question->id, $currentversions[$questionbankentryid][3]);
|
| - |
|
361 |
}
|
| - |
|
362 |
|
| 330 |
/**
|
363 |
/**
|
| 331 |
* Test population of latestversion field in question_definition objects
|
364 |
* Test population of latestversion field in question_definition objects
|
| 332 |
*
|
365 |
*
|
| 333 |
* When an instance of question_definition is created, it is added to an array of pending definitions which
|
366 |
* When an instance of question_definition is created, it is added to an array of pending definitions which
|
| 334 |
* do not yet have the latestversion field populated. When one definition has its latestversion property accessed,
|
367 |
* do not yet have the latestversion field populated. When one definition has its latestversion property accessed,
|