MDL-63738 question bank: a link to download a single question
[moodle.git] / lib / tests / questionlib_test.php
index cab8753..ced468b 100644 (file)
@@ -2000,4 +2000,34 @@ class core_questionlib_testcase extends advanced_testcase {
         $this->assertEquals($cat1->id, $parentcategories[1]);
         $this->assertCount(2, $parentcategories);
     }
+
+    public function test_question_get_export_single_question_url() {
+        $generator = $this->getDataGenerator();
+
+        // Create a course and an activity.
+        $course = $generator->create_course();
+        $quiz = $generator->create_module('quiz', ['course' => $course->id]);
+
+        // Create a question in each place.
+        $questiongenerator = $generator->get_plugin_generator('core_question');
+        $courseqcat = $questiongenerator->create_question_category(['contextid' => context_course::instance($course->id)->id]);
+        $courseq = $questiongenerator->create_question('truefalse', null, ['category' => $courseqcat->id]);
+        $quizqcat = $questiongenerator->create_question_category(['contextid' => context_module::instance($quiz->cmid)->id]);
+        $quizq = $questiongenerator->create_question('truefalse', null, ['category' => $quizqcat->id]);
+        $systemqcat = $questiongenerator->create_question_category();
+        $systemq = $questiongenerator->create_question('truefalse', null, ['category' => $systemqcat->id]);
+
+        // Verify some URLs.
+        $this->assertEquals(new moodle_url('/question/exportone.php',
+                ['id' => $courseq->id, 'courseid' => $course->id, 'sesskey' => sesskey()]),
+                question_get_export_single_question_url(question_bank::load_question_data($courseq->id)));
+
+        $this->assertEquals(new moodle_url('/question/exportone.php',
+                ['id' => $quizq->id, 'cmid' => $quiz->cmid, 'sesskey' => sesskey()]),
+                question_get_export_single_question_url(question_bank::load_question($quizq->id)));
+
+        $this->assertEquals(new moodle_url('/question/exportone.php',
+                ['id' => $systemq->id, 'courseid' => SITEID, 'sesskey' => sesskey()]),
+                question_get_export_single_question_url(question_bank::load_question($systemq->id)));
+    }
 }