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.
This commit is contained in:
Safat Shahin 2021-10-19 11:00:26 +11:00
parent 385938b472
commit f4b1b63684
2 changed files with 10 additions and 13 deletions

View File

@ -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) {

View File

@ -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();