Skip to content

Commit 146e39d

Browse files
committed
test: fix test_upsert_question_should_save_draft_files
1 parent 5300ad9 commit 146e39d

File tree

3 files changed

+6
-62
lines changed

3 files changed

+6
-62
lines changed

classes/question_service.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ public function upsert_question(object $question): void {
217217

218218
// Save the draft area files belonging to the question.
219219
// file_upload_element and wysiwyg_editor_element add to qpy_options_draftitems.
220-
$draftitems = array_filter((array) $question->qpy_options_draftitems ?? [], fn($draftitemid) => is_int($draftitemid));
220+
$draftitems = array_filter(
221+
isset($question->qpy_options_draftitems) ? (array) $question->qpy_options_draftitems : [],
222+
fn($draftitemid) => is_int($draftitemid)
223+
);
221224
global $USER;
222225
if ($draftitems) {
223226
$this->ofs->save_draft_area_files($question->context->id, $question->id, $USER->id, $draftitems);

tests/phpunit_compat.php

Lines changed: 0 additions & 55 deletions
This file was deleted.

tests/question_service_test.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use coding_exception;
2424
use dml_exception;
2525
use moodle_exception;
26-
use phpunit_compat;
2726
use qtype_questionpy\local\api\api;
2827
use qtype_questionpy\local\api\lms_permissions;
2928
use qtype_questionpy\local\api\package_api;
@@ -37,8 +36,6 @@
3736
use qtype_questionpy\local\package\package_raw;
3837
use stdClass;
3938

40-
require_once(__DIR__ . '/phpunit_compat.php');
41-
4239
/**
4340
* Unit tests for {@see question_service}.
4441
*
@@ -405,10 +402,9 @@ public function test_upsert_question_should_save_draft_files(): void {
405402
->willReturn(new question_response('en', '{}', scoring_method::automatically_scorable));
406403

407404
global $USER;
408-
$matcher = $this->exactly(2);
409-
$this->ofs->expects($matcher)
405+
$this->ofs->expects($this->once())
410406
->method('save_draft_area_files')
411-
->with($PAGE->context->id, 42, $USER->id, phpunit_compat::consecutively($matcher, 1234, 2345));
407+
->with($PAGE->context->id, 42, $USER->id, [1234, 2345]);
412408

413409
$this->questionservice->upsert_question(
414410
(object)[

0 commit comments

Comments
 (0)