Línea 19... |
Línea 19... |
19 |
* @package qformat_aiken
|
19 |
* @package qformat_aiken
|
20 |
* @copyright 2018 Jean-Michel Vedrine
|
20 |
* @copyright 2018 Jean-Michel Vedrine
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
21 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
22 |
*/
|
22 |
*/
|
Línea -... |
Línea 23... |
- |
|
23 |
|
- |
|
24 |
use core_question\local\bank\question_version_status;
|
23 |
|
25 |
|
Línea 24... |
Línea 26... |
24 |
defined('MOODLE_INTERNAL') || die();
|
26 |
defined('MOODLE_INTERNAL') || die();
|
25 |
|
27 |
|
26 |
global $CFG;
|
28 |
global $CFG;
|
Línea 33... |
Línea 35... |
33 |
/**
|
35 |
/**
|
34 |
* Unit tests for the Aiken question format export.
|
36 |
* Unit tests for the Aiken question format export.
|
35 |
*
|
37 |
*
|
36 |
* @copyright 2018 Jean-Michel vedrine)
|
38 |
* @copyright 2018 Jean-Michel vedrine)
|
37 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
39 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
- |
|
40 |
* @covers \qformat_aiken
|
38 |
*/
|
41 |
*/
|
39 |
class qformat_aiken_export_test extends advanced_testcase {
|
42 |
final class qformat_aiken_export_test extends advanced_testcase {
|
40 |
/**
|
43 |
/**
|
41 |
* Assert that 2 strings are the same, ignoring ends of line.
|
44 |
* Assert that 2 strings are the same, ignoring ends of line.
|
42 |
* We need to override this function because we don't want any output
|
45 |
* We need to override this function because we don't want any output
|
43 |
* @param string $expectedtext The expected string.
|
46 |
* @param string $expectedtext The expected string.
|
44 |
* @param string $text The actual string.
|
47 |
* @param string $text The actual string.
|
Línea 54... |
Línea 57... |
54 |
$this->resetAfterTest();
|
57 |
$this->resetAfterTest();
|
55 |
$this->setAdminUser();
|
58 |
$this->setAdminUser();
|
56 |
// Create a new course category and and a new course in that.
|
59 |
// Create a new course category and and a new course in that.
|
57 |
$category = $this->getDataGenerator()->create_category();
|
60 |
$category = $this->getDataGenerator()->create_category();
|
58 |
$course = $this->getDataGenerator()->create_course(array('category' => $category->id));
|
61 |
$course = $this->getDataGenerator()->create_course(array('category' => $category->id));
|
- |
|
62 |
$qbank = self::getDataGenerator()->create_module('qbank', ['course' => $course->id]);
|
- |
|
63 |
$context = context_module::instance($qbank->cmid);
|
59 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
64 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
60 |
$context = context_coursecat::instance($category->id);
|
- |
|
61 |
$cat = $generator->create_question_category(array('contextid' => $context->id));
|
65 |
$cat = $generator->create_question_category(array('contextid' => $context->id));
|
62 |
$question1 = $generator->create_question('shortanswer', null,
|
66 |
$question1 = $generator->create_question('shortanswer', null,
|
63 |
array('category' => $cat->id));
|
67 |
array('category' => $cat->id));
|
64 |
$question2 = $generator->create_question('essay', null,
|
68 |
$question2 = $generator->create_question('essay', null,
|
65 |
array('category' => $cat->id));
|
69 |
array('category' => $cat->id));
|
Línea 89... |
Línea 93... |
89 |
$this->setAdminUser();
|
93 |
$this->setAdminUser();
|
90 |
// Create a new course category and and a new course in that.
|
94 |
// Create a new course category and and a new course in that.
|
91 |
$category = $this->getDataGenerator()->create_category();
|
95 |
$category = $this->getDataGenerator()->create_category();
|
92 |
$course = $this->getDataGenerator()->create_course(array('category' => $category->id));
|
96 |
$course = $this->getDataGenerator()->create_course(array('category' => $category->id));
|
93 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
97 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
- |
|
98 |
$qbank = self::getDataGenerator()->create_module('qbank', ['course' => $course->id]);
|
94 |
$context = context_coursecat::instance($category->id);
|
99 |
$context = context_module::instance($qbank->cmid);
|
95 |
$cat = $generator->create_question_category(array('contextid' => $context->id));
|
100 |
$cat = $generator->create_question_category(array('contextid' => $context->id));
|
96 |
$question = $generator->create_question('multichoice', 'one_of_four',
|
101 |
$question = $generator->create_question('multichoice', 'one_of_four',
|
97 |
array('category' => $cat->id));
|
102 |
array('category' => $cat->id));
|
98 |
$question->questiontext = <<<EOT
|
103 |
$question->questiontext = <<<EOT
|
99 |
<p>Which is the</p>
|
104 |
<p>Which is the</p>
|
Línea 111... |
Línea 116... |
111 |
ANSWER: A
|
116 |
ANSWER: A
|
Línea 112... |
Línea 117... |
112 |
|
117 |
|
113 |
EOT;
|
118 |
EOT;
|
114 |
$this->assert_same_aiken($expectedoutput, $exporter->exportprocess());
|
119 |
$this->assert_same_aiken($expectedoutput, $exporter->exportprocess());
|
- |
|
120 |
}
|
- |
|
121 |
|
- |
|
122 |
public function test_hidden_question_not_exported(): void {
|
- |
|
123 |
$this->resetAfterTest();
|
- |
|
124 |
$this->setAdminUser();
|
- |
|
125 |
|
- |
|
126 |
// Create a new course category and a new course in that.
|
- |
|
127 |
$category = $this->getDataGenerator()->create_category();
|
- |
|
128 |
$course = $this->getDataGenerator()->create_course(['category' => $category->id]);
|
- |
|
129 |
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
|
- |
|
130 |
$context = context_coursecat::instance($category->id);
|
- |
|
131 |
$cat = $generator->create_question_category(['contextid' => $context->id]);
|
- |
|
132 |
|
- |
|
133 |
// Create a visible and a hidden question.
|
- |
|
134 |
$generator->create_question('multichoice', 'one_of_four', [
|
- |
|
135 |
'category' => $cat->id,
|
- |
|
136 |
'questiontext' => ['text' => 'This question is the visible one.', 'format' => FORMAT_HTML],
|
- |
|
137 |
]);
|
- |
|
138 |
$generator->create_question('multichoice', 'one_of_four', [
|
- |
|
139 |
'category' => $cat->id,
|
- |
|
140 |
'questiontext' => ['text' => 'This question is the hidden one.', 'format' => FORMAT_HTML],
|
- |
|
141 |
'status' => question_version_status::QUESTION_STATUS_HIDDEN,
|
- |
|
142 |
]);
|
- |
|
143 |
|
- |
|
144 |
// Prepared the expected result.
|
- |
|
145 |
$expectedoutput = <<<EOT
|
- |
|
146 |
This question is the visible one.
|
- |
|
147 |
A) One
|
- |
|
148 |
B) Two
|
- |
|
149 |
C) Three
|
- |
|
150 |
D) Four
|
- |
|
151 |
ANSWER: A
|
- |
|
152 |
|
- |
|
153 |
EOT;
|
- |
|
154 |
|
- |
|
155 |
// Do the export and verify.
|
- |
|
156 |
$exporter = new qformat_aiken();
|
- |
|
157 |
$exporter->category = $cat;
|
- |
|
158 |
$exporter->setCourse($course);
|
- |
|
159 |
$this->assert_same_aiken($expectedoutput, $exporter->exportprocess());
|
115 |
}
|
160 |
}
|