Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 30... Línea 30...
30
 * @copyright  2021 Catalyst IT Australia Pty Ltd
30
 * @copyright  2021 Catalyst IT Australia Pty Ltd
31
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
31
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
32
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33
 * @coversDefaultClass \qbank_previewquestion\helper
33
 * @coversDefaultClass \qbank_previewquestion\helper
34
 */
34
 */
35
class qbank_preview_helper_test extends \advanced_testcase {
35
final class qbank_preview_helper_test extends \advanced_testcase {
Línea 36... Línea 36...
36
 
36
 
37
    /**
37
    /**
38
     * @var bool|\context|\context_course $context
38
     * @var bool|\context|\context_course $context
39
     */
39
     */
Línea 64... Línea 64...
64
     *
64
     *
65
     * This is executed before running any test in this file.
65
     * This is executed before running any test in this file.
66
     */
66
     */
67
    public function setUp(): void {
67
    public function setUp(): void {
68
        global $USER;
68
        global $USER;
-
 
69
        parent::setUp();
69
        $this->resetAfterTest();
70
        $this->resetAfterTest();
70
        $this->setAdminUser();
71
        $this->setAdminUser();
71
        $generator = $this->getDataGenerator();
72
        $generator = $this->getDataGenerator();
72
        $questiongenerator = $generator->get_plugin_generator('core_question');
73
        $questiongenerator = $generator->get_plugin_generator('core_question');
73
        // Create a course.
74
        // Create a course.
74
        $course = $generator->create_course();
75
        $course = $generator->create_course();
-
 
76
        $qbank = $generator->create_module('qbank', ['course' => $course->id]);
75
        $this->context = context_course::instance($course->id);
77
        $qbankcontext = \context_module::instance($qbank->cmid);
-
 
78
        $this->context = $qbankcontext;
76
        // Create a question in the default category.
79
        // Create a question in the default category.
77
        $contexts = new \core_question\local\bank\question_edit_contexts($this->context);
80
        $contexts = new \core_question\local\bank\question_edit_contexts($qbankcontext);
78
        $cat = question_make_default_categories($contexts->all());
81
        $cat = question_get_default_category($contexts->lowest()->id, true);
79
        $this->questiondata = $questiongenerator->create_question('numerical', null,
82
        $this->questiondata = $questiongenerator->create_question('numerical', null,
80
                ['name' => 'Example question', 'category' => $cat->id]);
83
                ['name' => 'Example question', 'category' => $cat->id]);
81
        $this->quba = question_engine::make_questions_usage_by_activity('core_question_preview',
84
        $this->quba = question_engine::make_questions_usage_by_activity('core_question_preview',
82
            \context_user::instance($USER->id));
85
            \context_user::instance($USER->id));
83
        $this->options = new question_preview_options($this->questiondata);
86
        $this->options = new question_preview_options($this->questiondata);
Línea 96... Línea 99...
96
                $this->context, $this->returnurl, question_preview_options::ALWAYS_LATEST);
99
                $this->context, $this->returnurl, question_preview_options::ALWAYS_LATEST);
97
        $params = [
100
        $params = [
98
           'id' => $this->questiondata->id,
101
           'id' => $this->questiondata->id,
99
           'previewid' => $this->quba->get_id(),
102
           'previewid' => $this->quba->get_id(),
100
           'returnurl' => $this->returnurl,
103
           'returnurl' => $this->returnurl,
101
           'courseid' => $this->context->instanceid,
104
           'cmid' => $this->context->instanceid,
102
           'restartversion' => question_preview_options::ALWAYS_LATEST,
105
           'restartversion' => question_preview_options::ALWAYS_LATEST,
103
        ];
106
        ];
104
        $params = array_merge($params, $this->options->get_url_params());
107
        $params = array_merge($params, $this->options->get_url_params());
105
        $expectedurl = new moodle_url('/question/bank/previewquestion/preview.php', $params);
108
        $expectedurl = new moodle_url('/question/bank/previewquestion/preview.php', $params);
106
        $this->assertEquals($expectedurl, $actionurl);
109
        $this->assertEquals($expectedurl, $actionurl);
Línea 116... Línea 119...
116
                $this->context, $this->returnurl);
119
                $this->context, $this->returnurl);
117
        $params = [
120
        $params = [
118
            'id' => $this->questiondata->id,
121
            'id' => $this->questiondata->id,
119
            'previewid' => $this->quba->get_id(),
122
            'previewid' => $this->quba->get_id(),
120
            'returnurl' => $this->returnurl,
123
            'returnurl' => $this->returnurl,
121
            'courseid' => $this->context->instanceid
124
            'cmid' => $this->context->instanceid,
122
        ];
125
        ];
123
        $params = array_merge($params, $this->options->get_url_params());
126
        $params = array_merge($params, $this->options->get_url_params());
124
        $expectedurl = new moodle_url('/question/bank/previewquestion/preview.php', $params);
127
        $expectedurl = new moodle_url('/question/bank/previewquestion/preview.php', $params);
125
        $this->assertEquals($expectedurl, $actionurl);
128
        $this->assertEquals($expectedurl, $actionurl);
126
    }
129
    }
Línea 135... Línea 138...
135
                $this->questiondata->id, $this->context, $this->quba->get_id(), $this->returnurl);
138
                $this->questiondata->id, $this->context, $this->quba->get_id(), $this->returnurl);
136
        $params = [
139
        $params = [
137
            'id' => $this->questiondata->id,
140
            'id' => $this->questiondata->id,
138
            'previewid' => $this->quba->get_id(),
141
            'previewid' => $this->quba->get_id(),
139
            'returnurl' => $this->returnurl,
142
            'returnurl' => $this->returnurl,
140
            'courseid' => $this->context->instanceid
143
            'cmid' => $this->context->instanceid,
141
        ];
144
        ];
142
        $expectedurl = new moodle_url('/question/bank/previewquestion/preview.php', $params);
145
        $expectedurl = new moodle_url('/question/bank/previewquestion/preview.php', $params);
143
        $this->assertEquals($expectedurl, $formurl);
146
        $this->assertEquals($expectedurl, $formurl);
144
    }
147
    }
Línea 153... Línea 156...
153
                $this->options, $this->options->variant, $this->context, null, question_preview_options::ALWAYS_LATEST);
156
                $this->options, $this->options->variant, $this->context, null, question_preview_options::ALWAYS_LATEST);
154
        $params = [
157
        $params = [
155
            'id' => $this->questiondata->id,
158
            'id' => $this->questiondata->id,
156
            'behaviour' => $this->options->behaviour,
159
            'behaviour' => $this->options->behaviour,
157
            'maxmark' => $this->options->maxmark,
160
            'maxmark' => $this->options->maxmark,
158
            'courseid' => $this->context->instanceid,
161
            'cmid' => $this->context->instanceid,
159
            'restartversion' => question_preview_options::ALWAYS_LATEST,
162
            'restartversion' => question_preview_options::ALWAYS_LATEST,
160
        ];
163
        ];
161
        // Extra params for options.
164
        // Extra params for options.
162
        $params['correctness']     = $this->options->correctness;
165
        $params['correctness']     = $this->options->correctness;
163
        $params['marks']           = $this->options->marks;
166
        $params['marks']           = $this->options->marks;
Línea 181... Línea 184...
181
                $this->options, $this->options->variant, $this->context, null);
184
                $this->options, $this->options->variant, $this->context, null);
182
        $params = [
185
        $params = [
183
            'id' => $this->questiondata->id,
186
            'id' => $this->questiondata->id,
184
            'behaviour' => $this->options->behaviour,
187
            'behaviour' => $this->options->behaviour,
185
            'maxmark' => $this->options->maxmark,
188
            'maxmark' => $this->options->maxmark,
186
            'courseid' => $this->context->instanceid,
189
            'cmid' => $this->context->instanceid,
187
        ];
190
        ];
188
        // Extra params for options.
191
        // Extra params for options.
189
        $params['correctness']     = $this->options->correctness;
192
        $params['correctness']     = $this->options->correctness;
190
        $params['marks']           = $this->options->marks;
193
        $params['marks']           = $this->options->marks;
191
        $params['markdp']          = $this->options->markdp;
194
        $params['markdp']          = $this->options->markdp;