mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-74255 quiz: clean up lots of stuff mainly in the tests
This fixes lots of stuff like outdated or incomplete PHPdoc comments or test heler functions where the arguments don't have their types declared. A few more significant fixes, like places were a silly method was used to get a context which was readily available.
This commit is contained in:
parent
37e8faf0ed
commit
5fff990e25
@ -271,7 +271,7 @@ class course_modinfo {
|
||||
|
||||
/**
|
||||
* Obtains all instances of a particular module on this course.
|
||||
* @param $modname Name of module (not full frankenstyle) e.g. 'label'
|
||||
* @param string $modname Name of module (not full frankenstyle) e.g. 'label'
|
||||
* @return cm_info[] Array from instance id => cm_info for modules on this course; empty if none
|
||||
*/
|
||||
public function get_instances_of($modname) {
|
||||
|
@ -2102,7 +2102,7 @@ function is_latest(string $version, string $questionbankentryid) : bool {
|
||||
* filter settings, theme, lang, etc.) Defaults to $PAGE->context.
|
||||
* @return moodle_url the URL.
|
||||
* @deprecated since Moodle 4.0
|
||||
* @see qbank_previewquestion\previewquestion_helper::question_preview_url()
|
||||
* @see qbank_previewquestion\helper::question_preview_url()
|
||||
* @todo Final deprecation on Moodle 4.4 MDL-72438
|
||||
*/
|
||||
function question_preview_url($questionid, $preferredbehaviour = null,
|
||||
|
@ -220,4 +220,4 @@ class slot_random {
|
||||
]);
|
||||
$event->trigger();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
use mod_quiz\question\bank\qbank_helper;
|
||||
use \mod_quiz\structure;
|
||||
use \html_writer;
|
||||
use \qbank_previewquestion\helper;
|
||||
use renderable;
|
||||
|
||||
/**
|
||||
@ -733,7 +732,6 @@ class edit_renderer extends \plugin_renderer_base {
|
||||
* @return string HTML to output.
|
||||
*/
|
||||
public function question(structure $structure, int $slot, \moodle_url $pageurl) {
|
||||
global $DB;
|
||||
// Get the data required by the question_slot template.
|
||||
$slotid = $structure->get_slot_id_for_slot($slot);
|
||||
|
||||
|
@ -28,7 +28,6 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot . '/mod/quiz/lib.php');
|
||||
@ -81,7 +80,7 @@ define('QUIZ_SHOWIMAGE_LARGE', 2);
|
||||
*
|
||||
* @param object $quizobj the quiz object to create an attempt for.
|
||||
* @param int $attemptnumber the sequence number for the attempt.
|
||||
* @param object $lastattempt the previous attempt by this user, if any. Only needed
|
||||
* @param stdClass|null $lastattempt the previous attempt by this user, if any. Only needed
|
||||
* if $attemptnumber > 1 and $quiz->attemptonlast is true.
|
||||
* @param int $timenow the time the attempt was started at.
|
||||
* @param bool $ispreview whether this new attempt is a preview.
|
||||
|
@ -42,7 +42,7 @@ require_once($CFG->dirroot . '/mod/quiz/report/reportlib.php');
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class quiz_report_responses_from_steps_testcase extends mod_quiz_attempt_walkthrough_from_csv_testcase {
|
||||
protected function get_full_path_of_csv_file($setname, $test) {
|
||||
protected function get_full_path_of_csv_file(string $setname, string $test): string {
|
||||
// Overridden here so that __DIR__ points to the path of this file.
|
||||
return __DIR__."/fixtures/{$setname}{$test}.csv";
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class quiz_report_statistics_from_steps_testcase extends mod_quiz_attempt_walkth
|
||||
*/
|
||||
protected $report;
|
||||
|
||||
protected function get_full_path_of_csv_file($setname, $test) {
|
||||
protected function get_full_path_of_csv_file(string $setname, string $test): string {
|
||||
// Overridden here so that __DIR__ points to the path of this file.
|
||||
return __DIR__."/fixtures/{$setname}{$test}.csv";
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ class mod_quiz_attempt_walkthrough_from_csv_testcase extends advanced_testcase {
|
||||
global $SITE, $DB;
|
||||
$this->setAdminUser();
|
||||
|
||||
/** @var core_question_generator $questiongenerator */
|
||||
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
||||
$slots = array();
|
||||
$qidsbycat = array();
|
||||
@ -147,8 +148,8 @@ class mod_quiz_attempt_walkthrough_from_csv_testcase extends advanced_testcase {
|
||||
* @param array $quizsettings Quiz overrides for this quiz.
|
||||
* @param array $csvdata Data loaded from csv files for this test.
|
||||
*/
|
||||
protected function create_quiz_simulate_attempts_and_check_results($quizsettings, $csvdata) {
|
||||
$this->resetAfterTest(true);
|
||||
protected function create_quiz_simulate_attempts_and_check_results(array $quizsettings, array $csvdata) {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$this->create_quiz($quizsettings, $csvdata['questions']);
|
||||
|
||||
@ -166,7 +167,7 @@ class mod_quiz_attempt_walkthrough_from_csv_testcase extends advanced_testcase {
|
||||
* @param string $test
|
||||
* @return string full path of file.
|
||||
*/
|
||||
protected function get_full_path_of_csv_file($setname, $test) {
|
||||
protected function get_full_path_of_csv_file(string $setname, string $test): string {
|
||||
return __DIR__."/fixtures/{$setname}{$test}.csv";
|
||||
}
|
||||
|
||||
@ -177,7 +178,7 @@ class mod_quiz_attempt_walkthrough_from_csv_testcase extends advanced_testcase {
|
||||
* @param string $test
|
||||
* @return array
|
||||
*/
|
||||
protected function load_csv_data_file($setname, $test='') {
|
||||
protected function load_csv_data_file(string $setname, string $test = ''): array {
|
||||
$files = array($setname => $this->get_full_path_of_csv_file($setname, $test));
|
||||
return $this->dataset_from_files($files)->get_rows([$setname]);
|
||||
}
|
||||
@ -188,7 +189,7 @@ class mod_quiz_attempt_walkthrough_from_csv_testcase extends advanced_testcase {
|
||||
* @param array $row from csv file with field names with parts separate by '.'.
|
||||
* @return array the row with each part of the field name following a '.' being a separate sub array's index.
|
||||
*/
|
||||
protected function explode_dot_separated_keys_to_make_subindexs(array $row) {
|
||||
protected function explode_dot_separated_keys_to_make_subindexs(array $row): array {
|
||||
$parts = array();
|
||||
foreach ($row as $columnkey => $value) {
|
||||
$newkeys = explode('.', trim($columnkey));
|
||||
@ -214,7 +215,7 @@ class mod_quiz_attempt_walkthrough_from_csv_testcase extends advanced_testcase {
|
||||
* @return array One array element for each run of the test. Each element contains an array with the params for
|
||||
* test_walkthrough_from_csv.
|
||||
*/
|
||||
public function get_data_for_walkthrough() {
|
||||
public function get_data_for_walkthrough(): array {
|
||||
$quizzes = $this->load_csv_data_file('quizzes')['quizzes'];
|
||||
$datasets = array();
|
||||
foreach ($quizzes as $quizsettings) {
|
||||
@ -230,10 +231,10 @@ class mod_quiz_attempt_walkthrough_from_csv_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $steps array the step data from the csv file.
|
||||
* @param array $steps the step data from the csv file.
|
||||
* @return array attempt no as in csv file => the id of the quiz_attempt as stored in the db.
|
||||
*/
|
||||
protected function walkthrough_attempts($steps) {
|
||||
protected function walkthrough_attempts(array $steps): array {
|
||||
global $DB;
|
||||
$attemptids = array();
|
||||
foreach ($steps as $steprow) {
|
||||
@ -256,7 +257,7 @@ class mod_quiz_attempt_walkthrough_from_csv_testcase extends advanced_testcase {
|
||||
$prevattempts = quiz_get_user_attempts($this->quiz->id, $user->id, 'all', true);
|
||||
$attemptnumber = count($prevattempts) + 1;
|
||||
$timenow = time();
|
||||
$attempt = quiz_create_attempt($quizobj, $attemptnumber, false, $timenow, false, $user->id);
|
||||
$attempt = quiz_create_attempt($quizobj, $attemptnumber, null, $timenow, false, $user->id);
|
||||
// Select variant and / or random sub question.
|
||||
if (!isset($step['variants'])) {
|
||||
$step['variants'] = array();
|
||||
@ -291,10 +292,10 @@ class mod_quiz_attempt_walkthrough_from_csv_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $results array the results data from the csv file.
|
||||
* @param $attemptids array attempt no as in csv file => the id of the quiz_attempt as stored in the db.
|
||||
* @param array $results the results data from the csv file.
|
||||
* @param array $attemptids attempt no as in csv file => the id of the quiz_attempt as stored in the db.
|
||||
*/
|
||||
protected function check_attempts_results($results, $attemptids) {
|
||||
protected function check_attempts_results(array $results, array $attemptids) {
|
||||
foreach ($results as $resultrow) {
|
||||
$result = $this->explode_dot_separated_keys_to_make_subindexs($resultrow);
|
||||
// Re-load quiz attempt data.
|
||||
@ -308,9 +309,8 @@ class mod_quiz_attempt_walkthrough_from_csv_testcase extends advanced_testcase {
|
||||
*
|
||||
* @param array $result row of data read from csv file.
|
||||
* @param quiz_attempt $attemptobj the attempt object loaded from db.
|
||||
* @throws coding_exception
|
||||
*/
|
||||
protected function check_attempt_results($result, $attemptobj) {
|
||||
protected function check_attempt_results(array $result, quiz_attempt $attemptobj) {
|
||||
foreach ($result as $fieldname => $value) {
|
||||
if ($value === '!NULL!') {
|
||||
$value = null;
|
||||
|
@ -7,13 +7,13 @@ Feature: Quiz question versioning
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | category | groupmode |
|
||||
| Course 1 | C1 | 0 | 1 |
|
||||
| Course 1 | C1 | 0 | 1 |
|
||||
And the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| username | firstname | lastname | email |
|
||||
| teacher | Teacher | 1 | teacher@example.com |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| user | course | role |
|
||||
| teacher | C1 | editingteacher |
|
||||
And the following "question categories" exist:
|
||||
| contextlevel | reference | name |
|
||||
| Course | C1 | Test questions |
|
||||
|
2
mod/quiz/tests/external/external_test.php
vendored
2
mod/quiz/tests/external/external_test.php
vendored
@ -319,7 +319,7 @@ class external_test extends externallib_advanced_testcase {
|
||||
// We only see a limited set of fields.
|
||||
$this->assertCount(4, $result['quizzes'][0]);
|
||||
$this->assertEquals($quiz2->id, $result['quizzes'][0]['id']);
|
||||
$this->assertEquals($quiz2->coursemodule, $result['quizzes'][0]['coursemodule']);
|
||||
$this->assertEquals($quiz2->cmid, $result['quizzes'][0]['coursemodule']);
|
||||
$this->assertEquals($quiz2->course, $result['quizzes'][0]['course']);
|
||||
$this->assertEquals($quiz2->name, $result['quizzes'][0]['name']);
|
||||
$this->assertEquals($quiz2->course, $result['quizzes'][0]['course']);
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use mod_quiz\question\bank\qbank_helper;
|
||||
|
||||
/**
|
||||
* Class mod_quiz_local_structure_slot_random_test
|
||||
* Class for tests related to the {@link \mod_quiz\local\structure\slot_random} class.
|
||||
@ -352,7 +354,7 @@ class mod_quiz_local_structure_slot_random_test extends advanced_testcase {
|
||||
}
|
||||
|
||||
public function test_insert() {
|
||||
global $SITE, $DB;
|
||||
global $SITE;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
@ -360,6 +362,7 @@ class mod_quiz_local_structure_slot_random_test extends advanced_testcase {
|
||||
// Create a quiz.
|
||||
$quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
|
||||
$quiz = $quizgenerator->create_instance(array('course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0));
|
||||
$quizcontext = context_module::instance($quiz->cmid);
|
||||
|
||||
// Create a question category in the system context.
|
||||
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
||||
@ -400,7 +403,7 @@ class mod_quiz_local_structure_slot_random_test extends advanced_testcase {
|
||||
$randomslotdata = new stdClass();
|
||||
$randomslotdata->quizid = $quiz->id;
|
||||
$randomslotdata->maxmark = 1;
|
||||
$randomslotdata->usingcontextid = context_module::instance($quiz->cmid)->id;
|
||||
$randomslotdata->usingcontextid = $quizcontext->id;
|
||||
$randomslotdata->questionscontextid = $category->contextid;
|
||||
|
||||
// Insert the random question to the quiz.
|
||||
|
@ -36,6 +36,11 @@ require_once(__DIR__ . '/quiz_question_helper_test_trait.php');
|
||||
class qbank_helper_test extends \advanced_testcase {
|
||||
use \quiz_question_helper_test_trait;
|
||||
|
||||
/**
|
||||
* @var \stdClass test student user.
|
||||
*/
|
||||
protected $student;
|
||||
|
||||
/**
|
||||
* Called before every test.
|
||||
*/
|
||||
@ -79,29 +84,33 @@ class qbank_helper_test extends \advanced_testcase {
|
||||
* @covers ::get_version_options
|
||||
* @covers ::get_question_for_redo
|
||||
* @covers ::get_always_latest_version_question_ids
|
||||
* @covers ::question_load_random_questions
|
||||
*/
|
||||
public function test_reference_records() {
|
||||
$this->resetAfterTest();
|
||||
|
||||
$quiz = $this->create_test_quiz($this->course);
|
||||
// Test for questions from a different context.
|
||||
$context = \context_module::instance(get_coursemodule_from_instance("quiz", $quiz->id, $this->course->id)->id);
|
||||
|
||||
// Create a couple of questions.
|
||||
/** @var \core_question_generator $questiongenerator */
|
||||
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
||||
$cat = $questiongenerator->create_question_category(['contextid' => $context->id]);
|
||||
$numq = $questiongenerator->create_question('essay', null,
|
||||
['category' => $cat->id, 'name' => 'This is the first version']);
|
||||
|
||||
// Create two version.
|
||||
$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);
|
||||
|
||||
// Create the quiz object.
|
||||
$quizobj = \quiz::create($quiz->id);
|
||||
$quizobj->preload_questions();
|
||||
$quizobj->load_questions();
|
||||
$questions = $quizobj->get_questions();
|
||||
$question = reset($questions);
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$slots = $structure->get_slots();
|
||||
$slot = reset($slots);
|
||||
$this->assertEquals(3, count(qbank_helper::get_version_options($question->id)));
|
||||
@ -119,6 +128,7 @@ class qbank_helper_test extends \advanced_testcase {
|
||||
$questions = $quizobj->get_questions();
|
||||
$question = reset($questions);
|
||||
$this->assertEquals($question->id, qbank_helper::get_question_for_redo($slot->id));
|
||||
|
||||
// Test always latest version question ids.
|
||||
$latestquestionids = qbank_helper::get_always_latest_version_question_ids($quiz->id);
|
||||
$this->assertEquals($question->id, reset($latestquestionids));
|
||||
|
@ -45,16 +45,15 @@ trait quiz_question_helper_test_trait {
|
||||
*/
|
||||
protected function create_test_quiz(\stdClass $course): \stdClass {
|
||||
|
||||
/** @var mod_quiz_generator $quizgenerator */
|
||||
$quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
|
||||
|
||||
$quiz = $quizgenerator->create_instance([
|
||||
return $quizgenerator->create_instance([
|
||||
'course' => $course->id,
|
||||
'questionsperpage' => 0,
|
||||
'grade' => 100.0,
|
||||
'sumgrades' => 2,
|
||||
]);
|
||||
$quiz->coursemodule = $quiz->cmid;
|
||||
return $quiz;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,7 +63,7 @@ trait quiz_question_helper_test_trait {
|
||||
* @param \stdClass $quiz
|
||||
* @param array $override
|
||||
*/
|
||||
protected function add_regular_questions($questiongenerator, \stdClass $quiz, $override = null): void {
|
||||
protected function add_two_regular_questions($questiongenerator, \stdClass $quiz, $override = null): void {
|
||||
// Create a couple of questions.
|
||||
$cat = $questiongenerator->create_question_category($override);
|
||||
|
||||
@ -86,7 +85,7 @@ trait quiz_question_helper_test_trait {
|
||||
* @param \stdClass $quiz
|
||||
* @param array $override
|
||||
*/
|
||||
protected function add_random_questions($questiongenerator, \stdClass $quiz, $override = []): void {
|
||||
protected function add_one_random_question($questiongenerator, \stdClass $quiz, $override = []): void {
|
||||
// Create a random question.
|
||||
$cat = $questiongenerator->create_question_category($override);
|
||||
$questiongenerator->create_question('truefalse', null, array('category' => $cat->id));
|
||||
@ -106,18 +105,18 @@ trait quiz_question_helper_test_trait {
|
||||
$this->setUser($user);
|
||||
|
||||
$starttime = time();
|
||||
$quizobj = \quiz::create($quiz->id, $user->id);
|
||||
$quizobj = quiz::create($quiz->id, $user->id);
|
||||
|
||||
$quba = \question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
|
||||
$quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
|
||||
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
|
||||
|
||||
// Start the attempt.
|
||||
$attempt = quiz_create_attempt($quizobj, $attemptnumber, false, $starttime, false, $user->id);
|
||||
$attempt = quiz_create_attempt($quizobj, $attemptnumber, null, $starttime, false, $user->id);
|
||||
quiz_start_new_attempt($quizobj, $quba, $attempt, $attemptnumber, $starttime);
|
||||
quiz_attempt_save_started($quizobj, $quba, $attempt);
|
||||
|
||||
// Finish the attempt.
|
||||
$attemptobj = \quiz_attempt::create($attempt->id);
|
||||
$attemptobj = quiz_attempt::create($attempt->id);
|
||||
$attemptobj->process_finish($starttime, false);
|
||||
|
||||
$this->setUser();
|
||||
@ -140,7 +139,7 @@ trait quiz_question_helper_test_trait {
|
||||
|
||||
$backupid = 'test-question-backup-restore';
|
||||
|
||||
$bc = new backup_controller(backup::TYPE_1ACTIVITY, $quiz->coursemodule, backup::FORMAT_MOODLE,
|
||||
$bc = new backup_controller(backup::TYPE_1ACTIVITY, $quiz->cmid, backup::FORMAT_MOODLE,
|
||||
backup::INTERACTIVE_NO, backup::MODE_GENERAL, $user->id);
|
||||
$bc->execute_plan();
|
||||
|
||||
|
@ -38,6 +38,11 @@ require_once($CFG->dirroot . '/mod/quiz/locallib.php');
|
||||
class quiz_question_restore_test extends \advanced_testcase {
|
||||
use \quiz_question_helper_test_trait;
|
||||
|
||||
/**
|
||||
* @var \stdClass test student user.
|
||||
*/
|
||||
protected $student;
|
||||
|
||||
/**
|
||||
* Called before every test.
|
||||
*/
|
||||
@ -81,17 +86,22 @@ class quiz_question_restore_test extends \advanced_testcase {
|
||||
* @covers ::get_question_structure
|
||||
*/
|
||||
public function test_quiz_restore_in_a_different_course_using_quiz_question_bank() {
|
||||
global $DB;
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Create the test quiz.
|
||||
$quiz = $this->create_test_quiz($this->course);
|
||||
// Test for questions from a different context.
|
||||
$context = \context_module::instance(get_coursemodule_from_instance("quiz", $quiz->id, $this->course->id)->id);
|
||||
$quizcontext = \context_module::instance($quiz->cmid);
|
||||
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
||||
$this->add_regular_questions($questiongenerator, $quiz, ['contextid' => $context->id]);
|
||||
$this->add_random_questions($questiongenerator, $quiz, ['contextid' => $context->id]);
|
||||
$this->add_two_regular_questions($questiongenerator, $quiz, ['contextid' => $quizcontext->id]);
|
||||
$this->add_one_random_question($questiongenerator, $quiz, ['contextid' => $quizcontext->id]);
|
||||
|
||||
// Make the backup.
|
||||
$backupid = $this->backup_quiz($quiz, $this->user);
|
||||
|
||||
// Delete the current course to make sure there is no data.
|
||||
delete_course($this->course, false);
|
||||
|
||||
// Check if the questions and associated datas are deleted properly.
|
||||
$this->assertEquals(0, count(\mod_quiz\question\bank\qbank_helper::get_question_structure($quiz->id)));
|
||||
$newcourse = $this->getDataGenerator()->create_course();
|
||||
@ -103,11 +113,11 @@ class quiz_question_restore_test extends \advanced_testcase {
|
||||
/**
|
||||
* Count the questions for the context.
|
||||
*
|
||||
* @param int $context
|
||||
* @param int $contextid
|
||||
* @param string $extracondition
|
||||
* @return int
|
||||
* @return int the number of questions.
|
||||
*/
|
||||
protected function question_count($context, $extracondition = ''): int {
|
||||
protected function question_count(int $contextid, string $extracondition = ''): int {
|
||||
global $DB;
|
||||
return $DB->count_records_sql(
|
||||
"SELECT COUNT(q.id)
|
||||
@ -116,7 +126,7 @@ class quiz_question_restore_test extends \advanced_testcase {
|
||||
JOIN {question_bank_entries} qbe ON qbe.id = qv.questionbankentryid
|
||||
JOIN {question_categories} qc on qc.id = qbe.questioncategoryid
|
||||
WHERE qc.contextid = ?
|
||||
$extracondition", [$context]);
|
||||
$extracondition", [$contextid]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,8 +140,8 @@ class quiz_question_restore_test extends \advanced_testcase {
|
||||
// Test for questions from a different context.
|
||||
$context = \context_course::instance($this->course->id);
|
||||
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
||||
$this->add_regular_questions($questiongenerator, $quiz, ['contextid' => $context->id]);
|
||||
$this->add_random_questions($questiongenerator, $quiz, ['contextid' => $context->id]);
|
||||
$this->add_two_regular_questions($questiongenerator, $quiz, ['contextid' => $context->id]);
|
||||
$this->add_one_random_question($questiongenerator, $quiz, ['contextid' => $context->id]);
|
||||
// Count the questions in course context.
|
||||
$this->assertEquals(7, $this->question_count($context->id));
|
||||
$newquiz = $this->duplicate_quiz($this->course, $quiz);
|
||||
@ -150,10 +160,10 @@ class quiz_question_restore_test extends \advanced_testcase {
|
||||
$this->resetAfterTest();
|
||||
$quiz = $this->create_test_quiz($this->course);
|
||||
// Test for questions from a different context.
|
||||
$context = \context_module::instance(get_coursemodule_from_instance("quiz", $quiz->id, $this->course->id)->id);
|
||||
$context = \context_module::instance($quiz->cmid);
|
||||
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
||||
$this->add_regular_questions($questiongenerator, $quiz, ['contextid' => $context->id]);
|
||||
$this->add_random_questions($questiongenerator, $quiz, ['contextid' => $context->id]);
|
||||
$this->add_two_regular_questions($questiongenerator, $quiz, ['contextid' => $context->id]);
|
||||
$this->add_one_random_question($questiongenerator, $quiz, ['contextid' => $context->id]);
|
||||
// Count the questions in course context.
|
||||
$this->assertEquals(7, $this->question_count($context->id));
|
||||
$newquiz = $this->duplicate_quiz($this->course, $quiz);
|
||||
@ -220,7 +230,7 @@ class quiz_question_restore_test extends \advanced_testcase {
|
||||
$modinfo = get_fast_modinfo($newcourseid);
|
||||
$quiz = array_values($modinfo->get_instances_of('quiz'))[0];
|
||||
$quizobj = \quiz::create($quiz->instance);
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
// Are the correct slots returned?
|
||||
$slots = $structure->get_slots();
|
||||
@ -232,8 +242,7 @@ class quiz_question_restore_test extends \advanced_testcase {
|
||||
$this->assertCount(2, $questions);
|
||||
|
||||
// Count the questions in quiz qbank.
|
||||
$context = \context_module::instance(get_coursemodule_from_instance("quiz", $quizobj->get_quizid(), $newcourseid)->id);
|
||||
$this->assertEquals(2, $this->question_count($context->id));
|
||||
$this->assertEquals(2, $this->question_count($quizobj->get_context()->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -244,6 +253,7 @@ class quiz_question_restore_test extends \advanced_testcase {
|
||||
public function test_pre_4_quiz_restore_for_random_questions() {
|
||||
global $USER, $DB;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$backupid = 'abc';
|
||||
$backuppath = make_backup_temp_directory($backupid);
|
||||
get_file_packer('application/vnd.moodle.backup')->extract_to_pathname(
|
||||
@ -263,7 +273,7 @@ class quiz_question_restore_test extends \advanced_testcase {
|
||||
$modinfo = get_fast_modinfo($newcourseid);
|
||||
$quiz = array_values($modinfo->get_instances_of('quiz'))[0];
|
||||
$quizobj = \quiz::create($quiz->instance);
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
// Are the correct slots returned?
|
||||
$slots = $structure->get_slots();
|
||||
@ -280,8 +290,7 @@ class quiz_question_restore_test extends \advanced_testcase {
|
||||
"AND q.qtype <> 'random'"));
|
||||
|
||||
// Count the questions in quiz qbank.
|
||||
$context = \context_module::instance(get_coursemodule_from_instance("quiz", $quizobj->get_quizid(), $newcourseid)->id);
|
||||
$this->assertEquals(0, $this->question_count($context->id));
|
||||
$this->assertEquals(0, $this->question_count($quizobj->get_context()->id));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -23,6 +23,9 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
use mod_quiz\question\bank\qbank_helper;
|
||||
use mod_quiz\structure;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
@ -108,7 +111,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
$quizobj = new quiz($quiz, $cm, $course);
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
if (isset($headings[1])) {
|
||||
list($heading, $shuffle) = $this->parse_section_name($headings[1]);
|
||||
$sections = $structure->get_sections();
|
||||
@ -130,9 +133,9 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Verify that the given layout matches that expected.
|
||||
* @param array $expectedlayout as for $layout in {@link create_test_quiz()}.
|
||||
* @param \mod_quiz\structure $structure the structure to test.
|
||||
* @param structure $structure the structure to test.
|
||||
*/
|
||||
protected function assert_quiz_layout($expectedlayout, \mod_quiz\structure $structure) {
|
||||
protected function assert_quiz_layout($expectedlayout, structure $structure) {
|
||||
$sections = $structure->get_sections();
|
||||
|
||||
$slot = 1;
|
||||
@ -193,7 +196,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF2', 1, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
// Are the correct slots returned?
|
||||
$slots = $structure->get_slots();
|
||||
@ -204,7 +207,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
$quizobj = $this->create_test_quiz(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$sections = $structure->get_sections();
|
||||
$this->assertCount(1, $sections);
|
||||
@ -222,7 +225,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
'Heading 2*',
|
||||
array('TF2', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$sections = $structure->get_sections();
|
||||
$this->assertCount(2, $sections);
|
||||
@ -245,13 +248,13 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
'Heading 2',
|
||||
array('TF2', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$sections = $structure->get_sections();
|
||||
$section = end($sections);
|
||||
$structure->remove_section_heading($section->id);
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
'Heading 1',
|
||||
array('TF1', 1, 'truefalse'),
|
||||
@ -264,7 +267,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
'Heading 1',
|
||||
array('TF1', 1, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$sections = $structure->get_sections();
|
||||
$section = reset($sections);
|
||||
@ -279,13 +282,13 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF2', 1, 'truefalse'),
|
||||
array('TF3', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(2)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(1)->slotid;
|
||||
$structure->move_slot($idtomove, $idmoveafter, '1');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF2', 1, 'truefalse'),
|
||||
@ -299,13 +302,13 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF2', 1, 'truefalse'),
|
||||
array('TF3', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(2)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(2)->slotid;
|
||||
$structure->move_slot($idtomove, $idmoveafter, '2');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF2', 2, 'truefalse'),
|
||||
@ -318,13 +321,13 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF2', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(2)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(1)->slotid;
|
||||
$structure->move_slot($idtomove, $idmoveafter, '1');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF2', 1, 'truefalse'),
|
||||
@ -338,13 +341,13 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
'Heading',
|
||||
array('TF3', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(2)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(2)->slotid;
|
||||
$structure->move_slot($idtomove, $idmoveafter, '2');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
'Heading',
|
||||
@ -360,13 +363,13 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF2', 2, 'truefalse'),
|
||||
array('TF3', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(2)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(1)->slotid;
|
||||
$structure->move_slot($idtomove, $idmoveafter, '1');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF2', 1, 'truefalse'),
|
||||
@ -380,13 +383,13 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF2', 1, 'truefalse'),
|
||||
array('TF3', 1, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(2)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(3)->slotid;
|
||||
$structure->move_slot($idtomove, $idmoveafter, '1');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF3', 1, 'truefalse'),
|
||||
@ -400,13 +403,13 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF2', 2, 'truefalse'),
|
||||
array('TF3', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(3)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(1)->slotid;
|
||||
$structure->move_slot($idtomove, $idmoveafter, '1');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF3', 1, 'truefalse'),
|
||||
@ -420,13 +423,13 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF2', 2, 'truefalse'),
|
||||
array('TF3', 3, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(2)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(3)->slotid;
|
||||
$structure->move_slot($idtomove, $idmoveafter, '3');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF3', 2, 'truefalse'),
|
||||
@ -440,7 +443,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF2', 2, 'truefalse'),
|
||||
array('TF3', 3, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(3)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(2)->slotid;
|
||||
@ -454,7 +457,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF2', 2, 'truefalse'),
|
||||
array('TF3', 3, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(1)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(2)->slotid;
|
||||
@ -470,13 +473,13 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
'Heading 2',
|
||||
array('TF3', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(1)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(2)->slotid;
|
||||
$structure->move_slot($idtomove, $idmoveafter, '1');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
'Heading 1',
|
||||
array('TF2', 1, 'truefalse'),
|
||||
@ -494,13 +497,13 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
'Heading 2',
|
||||
array('TF3', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(2)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(3)->slotid;
|
||||
$structure->move_slot($idtomove, $idmoveafter, '2');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
'Heading 1',
|
||||
array('TF1', 1, 'truefalse'),
|
||||
@ -518,12 +521,12 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF2', 2, 'truefalse'),
|
||||
array('TF3', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(3)->slotid;
|
||||
$structure->move_slot($idtomove, 0, '1');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
'Heading 1',
|
||||
array('TF3', 1, 'truefalse'),
|
||||
@ -541,13 +544,13 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
'Heading 2',
|
||||
array('TF3', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(2)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(2)->slotid;
|
||||
$structure->move_slot($idtomove, $idmoveafter, '2');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
'Heading 1',
|
||||
array('TF1', 1, 'truefalse'),
|
||||
@ -563,12 +566,12 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF2', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(1)->slotid;
|
||||
$structure->move_slot($idtomove, 0, '2');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
'Heading 1',
|
||||
array('TF1', 1, 'truefalse'),
|
||||
@ -582,12 +585,12 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF2', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(1)->slotid;
|
||||
$structure->move_slot($idtomove, 0, '1');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
'Heading 1',
|
||||
array('TF1', 1, 'truefalse'),
|
||||
@ -601,12 +604,12 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF2', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(1)->slotid;
|
||||
$structure->move_slot($idtomove, 0, '');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
'Heading 1',
|
||||
array('TF1', 1, 'truefalse'),
|
||||
@ -624,13 +627,13 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF3', 3, 'truefalse'),
|
||||
array('TF4', 3, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(3)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(1)->slotid;
|
||||
$structure->move_slot($idtomove, $idmoveafter, '2');
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
'Heading 1',
|
||||
array('TF1', 1, 'truefalse'),
|
||||
@ -652,13 +655,13 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF3', 3, 'truefalse'),
|
||||
array('TF4', 3, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$idtomove = $structure->get_question_in_slot(4)->slotid;
|
||||
$idmoveafter = $structure->get_question_in_slot(1)->slotid;
|
||||
$structure->move_slot($idtomove, $idmoveafter, 1);
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
'Heading 1',
|
||||
array('TF1', 1, 'truefalse'),
|
||||
@ -677,11 +680,11 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
'Heading 2',
|
||||
array('TF3', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$structure->remove_slot(2);
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
'Heading 2',
|
||||
@ -702,7 +705,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
||||
$cat = $questiongenerator->create_question_category();
|
||||
quiz_add_random_questions($quizobj->get_quiz(), 1, $cat->id, 1, false);
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$sql = 'SELECT qsr.*
|
||||
FROM {question_set_references} qsr
|
||||
JOIN {quiz_slots} qs ON qs.id = qsr.itemid
|
||||
@ -713,7 +716,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
|
||||
$structure->remove_slot(2);
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
), $structure);
|
||||
@ -731,7 +734,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
'Heading 2',
|
||||
array('TF3', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$structure->remove_slot(1);
|
||||
$this->expectException(coding_exception::class);
|
||||
@ -745,7 +748,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
'Heading 2',
|
||||
array('TF3', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$this->expectException(coding_exception::class);
|
||||
$structure->remove_slot(3);
|
||||
@ -756,7 +759,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
'Heading 1',
|
||||
array('TF1', 1, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$structure->remove_slot(1);
|
||||
|
||||
@ -766,7 +769,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('name' => 'TF2', 'category' => $cat->id));
|
||||
|
||||
quiz_add_quiz_question($q->id, $quizobj->get_quiz(), 0);
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$this->assert_quiz_layout(array(
|
||||
'Heading 1',
|
||||
@ -788,7 +791,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
|
||||
quiz_add_quiz_question($q->id, $quizobj->get_quiz(), 1);
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF3', 1, 'truefalse'),
|
||||
@ -814,7 +817,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
|
||||
quiz_add_quiz_question($q->id, $quizobj->get_quiz(), 1);
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
'Heading 1',
|
||||
array('TF1', 1, 'truefalse'),
|
||||
@ -840,7 +843,7 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
|
||||
quiz_add_quiz_question($q->id, $quizobj->get_quiz(), 0);
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
'Heading 2',
|
||||
@ -854,12 +857,12 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF2', 2, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$slotid = $structure->get_question_in_slot(2)->slotid;
|
||||
$slots = $structure->update_page_break($slotid, \mod_quiz\repaginate::LINK);
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF2', 1, 'truefalse'),
|
||||
@ -871,12 +874,12 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF2', 1, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
$slotid = $structure->get_question_in_slot(2)->slotid;
|
||||
$slots = $structure->update_page_break($slotid, \mod_quiz\repaginate::UNLINK);
|
||||
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assert_quiz_layout(array(
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF2', 2, 'truefalse'),
|
||||
@ -888,21 +891,21 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
array('TF1', 1, 'truefalse'),
|
||||
array('TF2', 1, 'truefalse'),
|
||||
));
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
|
||||
// Test adding a dependency.
|
||||
$slotid = $structure->get_slot_id_for_slot(2);
|
||||
$structure->update_question_dependency($slotid, true);
|
||||
|
||||
// Having called update page break, we need to reload $structure.
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assertEquals(1, $structure->is_question_dependent_on_previous_slot(2));
|
||||
|
||||
// Test removing a dependency.
|
||||
$structure->update_question_dependency($slotid, false);
|
||||
|
||||
// Having called update page break, we need to reload $structure.
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quizobj);
|
||||
$structure = structure::create_for_quiz($quizobj);
|
||||
$this->assertEquals(0, $structure->is_question_dependent_on_previous_slot(2));
|
||||
}
|
||||
|
||||
@ -920,11 +923,11 @@ class mod_quiz_structure_testcase extends advanced_testcase {
|
||||
$noneditingteacher = $generator->create_and_enrol($course, 'teacher');
|
||||
|
||||
$this->setUser($teacher);
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quiz);
|
||||
$structure = structure::create_for_quiz($quiz);
|
||||
$this->assertTrue($structure->can_add_random_questions());
|
||||
|
||||
$this->setUser($noneditingteacher);
|
||||
$structure = \mod_quiz\structure::create_for_quiz($quiz);
|
||||
$structure = structure::create_for_quiz($quiz);
|
||||
$this->assertFalse($structure->can_add_random_questions());
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,8 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use mod_quiz\question\bank\qbank_helper;
|
||||
|
||||
/**
|
||||
* Test the restore of random question tags.
|
||||
*
|
||||
|
@ -903,7 +903,7 @@ class question_type {
|
||||
* specific information (it is passed by reference).
|
||||
*/
|
||||
public function get_question_options($question) {
|
||||
global $CFG, $DB, $OUTPUT;
|
||||
global $DB, $OUTPUT;
|
||||
|
||||
if (!isset($question->options)) {
|
||||
$question->options = new stdClass();
|
||||
|
Loading…
x
Reference in New Issue
Block a user