Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 39... Línea 39...
39
 *
39
 *
40
 * @package    qtype_missingtype
40
 * @package    qtype_missingtype
41
 * @copyright  2010 The Open University
41
 * @copyright  2010 The Open University
42
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
43
 */
43
 */
44
class missingtype_test extends \question_testcase {
44
final class missingtype_test extends \question_testcase {
Línea 45... Línea 45...
45
 
45
 
46
    protected function get_unknown_questiondata() {
46
    protected function get_unknown_questiondata() {
47
        $questiondata = new \stdClass();
47
        $questiondata = new \stdClass();
48
        $questiondata->id = 0;
48
        $questiondata->id = 0;
Línea 141... Línea 141...
141
 
141
 
142
    public function test_get_possible_responses(): void {
142
    public function test_get_possible_responses(): void {
143
        $qtype = new qtype_missingtype();
143
        $qtype = new qtype_missingtype();
144
        $this->assertEquals(array(), $qtype->get_possible_responses(null));
144
        $this->assertEquals(array(), $qtype->get_possible_responses(null));
-
 
145
    }
-
 
146
 
-
 
147
    /**
-
 
148
     * Test moving a question category from one context to another when it contains questions of an invalid type
-
 
149
     *
-
 
150
     * @covers ::question_move_category_to_context
-
 
151
     */
-
 
152
    public function test_move_question_category_with_missing_question_types(): void {
-
 
153
 
-
 
154
        global $DB;
-
 
155
 
-
 
156
        $this->resetAfterTest();
-
 
157
 
-
 
158
        // Create a course we can move the category to.
-
 
159
        $course = $this->getDataGenerator()->create_course();
-
 
160
 
-
 
161
        // Create a quiz module to attach the question category to.
-
 
162
        $module1 = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]);
-
 
163
 
-
 
164
        // And another one to move things to.
-
 
165
        $module2 = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]);
-
 
166
 
-
 
167
        // Create a question category on the system context.
-
 
168
        $generator = $this->getDataGenerator()->get_plugin_generator('core_question');
-
 
169
        $category = $generator->create_question_category([
-
 
170
            'contextid' => \core\context\module::instance($module1->cmid)->id,
-
 
171
        ]);
-
 
172
 
-
 
173
        // Create a question of an invalid type and put it in the category.
-
 
174
        $question = $generator->create_question('missingtype', null, ['category' => $category->id]);
-
 
175
 
-
 
176
        // Update the question to set an invalid qtype, as "missingtype" is actually installed and won't fail.
-
 
177
        $question->qtype = 'invalid';
-
 
178
        $DB->update_record('question', $question);
-
 
179
 
-
 
180
        // We just want to assert that no exception is thrown.
-
 
181
        $this->expectNotToPerformAssertions();
-
 
182
 
-
 
183
        // Try and move the categories.
-
 
184
        question_move_category_to_context(
-
 
185
            $category->id,
-
 
186
            \core\context\module::instance($module1->cmid)->id,
-
 
187
            \core\context\module::instance($module2->cmid)->id,
-
 
188
        );
-
 
189
 
-
 
190
    }
145
    }
191