Línea 32... |
Línea 32... |
32 |
* @copyright 2013 The Open University
|
32 |
* @copyright 2013 The Open University
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
34 |
*/
|
34 |
*/
|
35 |
class qtype_essay_test_helper extends question_test_helper {
|
35 |
class qtype_essay_test_helper extends question_test_helper {
|
36 |
public function get_test_questions() {
|
36 |
public function get_test_questions() {
|
37 |
return array('editor', 'editorfilepicker', 'plain', 'monospaced', 'responsetemplate', 'noinline');
|
37 |
return ['editor', 'editorfilepicker', 'plain', 'monospaced', 'responsetemplate', 'noinline', 'files'];
|
38 |
}
|
38 |
}
|
Línea 39... |
Línea 39... |
39 |
|
39 |
|
40 |
/**
|
40 |
/**
|
41 |
* Helper method to reduce duplication.
|
41 |
* Helper method to reduce duplication.
|
Línea 289... |
Línea 289... |
289 |
*/
|
289 |
*/
|
290 |
public function make_attachments_saver($attachments) {
|
290 |
public function make_attachments_saver($attachments) {
|
291 |
return new question_file_saver($this->make_attachments($attachments), 'question', 'response_attachments');
|
291 |
return new question_file_saver($this->make_attachments($attachments), 'question', 'response_attachments');
|
292 |
}
|
292 |
}
|
Línea -... |
Línea 293... |
- |
|
293 |
|
- |
|
294 |
/**
|
- |
|
295 |
* Create a question with images embedded in the questiontext, generalfeedback and graderinfo.
|
- |
|
296 |
*
|
- |
|
297 |
* @return stdClass
|
- |
|
298 |
*/
|
- |
|
299 |
public function get_essay_question_form_data_files() {
|
- |
|
300 |
global $CFG, $USER;
|
- |
|
301 |
$fromform = new stdClass();
|
- |
|
302 |
|
- |
|
303 |
$usercontext = context_user::instance($USER->id);
|
- |
|
304 |
$questiontextdraftid = 1;
|
- |
|
305 |
file_prepare_draft_area($questiontextdraftid, $usercontext->id, null, null, null);
|
- |
|
306 |
$fs = get_file_storage();
|
- |
|
307 |
$filerecord = new stdClass();
|
- |
|
308 |
$filerecord->contextid = $usercontext->id;
|
- |
|
309 |
$filerecord->component = 'user';
|
- |
|
310 |
$filerecord->filearea = 'draft';
|
- |
|
311 |
$filerecord->itemid = $questiontextdraftid;
|
- |
|
312 |
$filerecord->filepath = '/';
|
- |
|
313 |
$filerecord->filename = '1.png';
|
- |
|
314 |
$fs->create_file_from_pathname($filerecord, $CFG->dirroot .
|
- |
|
315 |
'/question/type/essay/tests/fixtures/1.png');
|
- |
|
316 |
|
- |
|
317 |
$feedbackdraftid = 2;
|
- |
|
318 |
file_prepare_draft_area($feedbackdraftid, $usercontext->id, null, null, null);
|
- |
|
319 |
$fs = get_file_storage();
|
- |
|
320 |
$filerecord = new stdClass();
|
- |
|
321 |
$filerecord->contextid = $usercontext->id;
|
- |
|
322 |
$filerecord->component = 'user';
|
- |
|
323 |
$filerecord->filearea = 'draft';
|
- |
|
324 |
$filerecord->itemid = $feedbackdraftid;
|
- |
|
325 |
$filerecord->filepath = '/';
|
- |
|
326 |
$filerecord->filename = '2.png';
|
- |
|
327 |
$fs->create_file_from_pathname($filerecord, $CFG->dirroot .
|
- |
|
328 |
'/question/type/essay/tests/fixtures/2.png');
|
- |
|
329 |
|
- |
|
330 |
$graderinfodraftid = 3;
|
- |
|
331 |
file_prepare_draft_area($graderinfodraftid, $usercontext->id, null, null, null);
|
- |
|
332 |
$fs = get_file_storage();
|
- |
|
333 |
$filerecord = new stdClass();
|
- |
|
334 |
$filerecord->contextid = $usercontext->id;
|
- |
|
335 |
$filerecord->component = 'user';
|
- |
|
336 |
$filerecord->filearea = 'draft';
|
- |
|
337 |
$filerecord->itemid = $graderinfodraftid;
|
- |
|
338 |
$filerecord->filepath = '/';
|
- |
|
339 |
$filerecord->filename = '3.png';
|
- |
|
340 |
$fs->create_file_from_pathname($filerecord, $CFG->dirroot .
|
- |
|
341 |
'/question/type/essay/tests/fixtures/3.png');
|
- |
|
342 |
|
- |
|
343 |
$fromform->name = 'Essay question (HTML editor)';
|
- |
|
344 |
$questionfileurl = $CFG->wwwroot . '/draftfile.php/' . $usercontext->id . '/user/draft/' . $questiontextdraftid . '/1.png';
|
- |
|
345 |
$fromform->questiontext = [
|
- |
|
346 |
'text' => 'Please write a story about a frog. <img src="'.$questionfileurl.'" alt="">',
|
- |
|
347 |
'format' => FORMAT_HTML,
|
- |
|
348 |
'itemid' => $questiontextdraftid,
|
- |
|
349 |
];
|
Línea -... |
Línea 350... |
- |
|
350 |
$fromform->defaultmark = 1.0;
|
- |
|
351 |
|
- |
|
352 |
$feedbackfileurl = $CFG->wwwroot . '/draftfile.php/' . $usercontext->id . '/user/draft/' . $feedbackdraftid . '/2.png';
|
- |
|
353 |
$fromform->generalfeedback = [
|
- |
|
354 |
'text' => 'I hope your story had a beginning, a middle and an end. <img src="'.$feedbackfileurl.'" alt="">',
|
- |
|
355 |
'format' => FORMAT_HTML,
|
- |
|
356 |
'itemid' => $feedbackdraftid,
|
- |
|
357 |
];
|
- |
|
358 |
$fromform->responseformat = 'editor';
|
- |
|
359 |
$fromform->responserequired = 1;
|
- |
|
360 |
$fromform->responsefieldlines = 10;
|
- |
|
361 |
$fromform->attachments = 0;
|
- |
|
362 |
$fromform->attachmentsrequired = 0;
|
- |
|
363 |
$fromform->maxbytes = 0;
|
- |
|
364 |
$fromform->filetypeslist = ''; // Although once saved in the DB, this becomes null, the form returns '' here.
|
- |
|
365 |
|
- |
|
366 |
$graderinfourl = $CFG->wwwroot . '/draftfile.php/' . $usercontext->id . '/user/draft/' . $graderinfodraftid . '/3.png';
|
- |
|
367 |
$fromform->graderinfo = [
|
- |
|
368 |
'text' => '',
|
- |
|
369 |
'format' => FORMAT_HTML,
|
- |
|
370 |
'itemid' => $graderinfodraftid,
|
- |
|
371 |
];
|
- |
|
372 |
$fromform->responsetemplate = ['text' => '<img src="'.$graderinfourl.'" alt="">', 'format' => FORMAT_HTML];
|
- |
|
373 |
$fromform->status = \core_question\local\bank\question_version_status::QUESTION_STATUS_READY;
|
- |
|
374 |
|
293 |
|
375 |
return $fromform;
|