Skip to content

Commit

Permalink
unit test resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
safatshahin committed Oct 6, 2022
1 parent e4f6795 commit 470abbd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
6 changes: 4 additions & 2 deletions question/tests/question_manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function test_delete_question_bank_entry() {
*/
public function test_question_delete_question() {
global $DB;

$this->resetAfterTest();
// Setup.
$context = \context_system::instance();
$qgen = $this->getDataGenerator()->get_plugin_generator('core_question');
Expand All @@ -146,7 +146,7 @@ public function test_question_delete_question() {
*/
public function test_question_delete_question_broken_data() {
global $DB;

$this->resetAfterTest();
// Setup.
$context = \context_system::instance();
$qgen = $this->getDataGenerator()->get_plugin_generator('core_question');
Expand Down Expand Up @@ -406,6 +406,7 @@ public function test_match_grade_options() {
* get_question_options should add the category object to the given question.
*/
public function test_get_question_options_includes_category_object_single_question() {
$this->resetAfterTest();
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions();
$question = array_shift($questions);

Expand All @@ -419,6 +420,7 @@ public function test_get_question_options_includes_category_object_single_questi
* the given list.
*/
public function test_get_question_options_includes_category_object_multiple_questions() {
$this->resetAfterTest();
list($category, $course, $quiz, $qcat, $questions) = $this->setup_quiz_and_questions();

\core_question\question_manager::get_question_options($questions);
Expand Down
42 changes: 41 additions & 1 deletion question/tests/question_tags_manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,53 @@
*/
class question_tags_manager_test extends \advanced_testcase {

/**
* Setup a course, a quiz, a question category and a question for testing.
*
* @param string $type The type of question category to create.
* @return array The created data objects
*/
public function setup_quiz_and_questions() {
// Create course category.
$category = $this->getDataGenerator()->create_category();

// Create course.
$course = $this->getDataGenerator()->create_course(array(
'numsections' => 5,
'category' => $category->id
));

$options = array(
'course' => $course->id,
'duedate' => time(),
);

// Generate an assignment with due date (will generate a course event).
$quiz = $this->getDataGenerator()->create_module('quiz', $options);

$qgen = $this->getDataGenerator()->get_plugin_generator('core_question');

$context = \context_module::instance($quiz->cmid);

$qcat = $qgen->create_question_category(array('contextid' => $context->id));

$questions = array(
$qgen->create_question('shortanswer', null, array('category' => $qcat->id)),
$qgen->create_question('shortanswer', null, array('category' => $qcat->id)),
);

quiz_add_quiz_question($questions[0]->id, $quiz);

return array($category, $course, $quiz, $qcat, $questions);
}

/**
* This function tests that the functions responsible for moving questions to
* different contexts also updates the tag instances associated with the questions.
*/
public function test_altering_tag_instance_context() {
global $CFG, $DB;

$this->resetAfterTest();
// Set to admin user.
$this->setAdminUser();

Expand Down

0 comments on commit 470abbd

Please sign in to comment.