/** * This function tests the question_delete_context function. */ public function test_question_delete_context() { global $DB; $this->resetAfterTest(true); $this->setAdminUser(); list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions(); // Get the module context id. $result = question_delete_context($qcat->contextid); // Verify category deleted. $criteria = array('id' => $qcat->id); $this->assertEquals(0, $DB->count_records('question_categories', $criteria)); // Verify questions deleted or moved. $criteria = array('category' => $qcat->id); $this->assertEquals(0, $DB->count_records('question', $criteria)); // Test that the feedback works. $expected[] = array($qcat->name, get_string('unusedcategorydeleted', 'question')); $this->assertEquals($expected, $result); }
/** * All question categories and their questions are deleted for this activity. * * @param object $cm the course module object representing the activity * @param boolean $feedback to specify if the process must output a summary of its work * @return boolean */ function question_delete_activity($cm, $feedback = true) { global $DB; $modcontext = context_module::instance($cm->id); $feedbackdata = question_delete_context($modcontext->id, $feedback); // Inform about changes performed if feedback is enabled. if ($feedback && $feedbackdata) { $table = new html_table(); $table->head = array(get_string('category', 'question'), get_string('action')); $table->data = $feedbackdata; echo html_writer::table($table); } return true; }