From f4b1b6368420e600b39ffe4949cacfd47cc0465c Mon Sep 17 00:00:00 2001 From: Safat Shahin Date: Tue, 19 Oct 2021 11:00:26 +1100 Subject: [PATCH] MDL-72843 qbank_comment: unit test fix for individual testsuite This change resolves a unit test issue while running an individual testsuite rather than the entire one after the first init call for phpunit. It requires the file so it can point back to the comment api while required. --- question/bank/comment/lib.php | 20 +++++++++----------- question/bank/comment/tests/backup_test.php | 3 +-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/question/bank/comment/lib.php b/question/bank/comment/lib.php index 51664541c4a..5235f1df9d8 100644 --- a/question/bank/comment/lib.php +++ b/question/bank/comment/lib.php @@ -25,6 +25,8 @@ defined('MOODLE_INTERNAL') || die(); +require_once($CFG->dirroot. '/comment/lib.php'); + /** * Validate comment parameter before perform other comments actions. * @@ -105,7 +107,6 @@ function qbank_comment_preview_display($question, $courseid): string { * * @param array $args * @return string rendered output - * @todo cleanup after class renaming to remove check for previewlib.php MDL-71679 */ function qbank_comment_output_fragment_question_comment($args): string { global $USER, $PAGE, $CFG; @@ -115,19 +116,16 @@ function qbank_comment_output_fragment_question_comment($args): string { $quba = question_engine::make_questions_usage_by_activity( 'core_question_preview', context_user::instance($USER->id)); + // Just in case of any regression, it should not break the modal, just show the comments. if (class_exists('\\qbank_previewquestion\\question_preview_options')) { $options = new \qbank_previewquestion\question_preview_options($question); - } else { - require_once($CFG->dirroot . '/question/previewlib.php'); - $options = new question_preview_options($question); + $options->load_user_defaults(); + $options->set_from_request(); + $quba->set_preferred_behaviour($options->behaviour); + $slot = $quba->add_question($question, $options->maxmark); + $quba->start_question($slot, $options->variant); + $displaydata['question'] = $quba->render_question($slot, $options, '1'); } - - $options->load_user_defaults(); - $options->set_from_request(); - $quba->set_preferred_behaviour($options->behaviour); - $slot = $quba->add_question($question, $options->maxmark); - $quba->start_question($slot, $options->variant); - $displaydata['question'] = $quba->render_question($slot, $options, '1'); $displaydata['comment'] = qbank_comment_preview_display($question, $args['courseid']); $displaydata['commenstdisabled'] = false; if (empty($displaydata['comment']) && !$CFG->usecomments) { diff --git a/question/bank/comment/tests/backup_test.php b/question/bank/comment/tests/backup_test.php index f4aa106999f..02b9a84a3ff 100644 --- a/question/bank/comment/tests/backup_test.php +++ b/question/bank/comment/tests/backup_test.php @@ -19,7 +19,7 @@ defined('MOODLE_INTERNAL') || die(); global $CFG; require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php'); require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php'); - +require_once($CFG->dirroot. '/comment/lib.php'); /** * Question comment backup and restore unit tests. @@ -138,7 +138,6 @@ class qbank_comment_backup_restore_test extends \advanced_testcase { */ public function test_backup_restore() { global $DB; - $this->resetAfterTest(); $this->setAdminUser();