MDL-68757 questions: don't do output in low-level functions

This commit is contained in:
Tim Hunt 2020-05-18 13:09:24 +01:00
parent d85118369d
commit 4a45b7112c
7 changed files with 52 additions and 131 deletions

View file

@ -1993,7 +1993,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr
// Now delete anything that may depend on course category context.
grade_course_category_delete($this->id, 0, $showfeedback);
if (!question_delete_course_category($this, 0, $showfeedback)) {
if (!question_delete_course_category($this, null)) {
throw new moodle_exception('cannotdeletecategoryquestions', '', '', $this->get_formatted_name());
}
@ -2153,7 +2153,7 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr
// Now delete anything that may depend on course category context.
grade_course_category_delete($this->id, $newparentid, $showfeedback);
if (!question_delete_course_category($this, $newparentcat, $showfeedback)) {
if (!question_delete_course_category($this, $newparentcat)) {
if ($showfeedback) {
echo $OUTPUT->notification(get_string('errordeletingquestionsfromcategory', 'question', $catname), 'notifysuccess');
}

View file

@ -1054,10 +1054,7 @@ function course_delete_module($cmid, $async = false) {
}
}
// Delete activity context questions and question categories.
$showinfo = !defined('AJAX_SCRIPT') || AJAX_SCRIPT == '0';
question_delete_activity($cm, $showinfo);
question_delete_activity($cm);
// Call the delete_instance function, if it returns false throw an exception.
if (!$deleteinstancefunction($cm->instance)) {

View file

@ -1653,11 +1653,8 @@ class core_course_courselib_testcase extends advanced_testcase {
case 'quiz':
$qgen = $this->getDataGenerator()->get_plugin_generator('core_question');
$qcat = $qgen->create_question_category(array('contextid' => $modcontext->id));
$questions = array(
$qgen->create_question('shortanswer', null, array('category' => $qcat->id)),
$qgen->create_question('shortanswer', null, array('category' => $qcat->id)),
);
$this->expectOutputRegex('/'.get_string('unusedcategorydeleted', 'question').'/');
$qgen->create_question('shortanswer', null, array('category' => $qcat->id));
$qgen->create_question('shortanswer', null, array('category' => $qcat->id));
break;
default:
break;