Permalink
Browse files

MDL-29571 qtype description refactor unit test code a bit.

  • Loading branch information...
1 parent 133173e commit 5e69fe49718b0095926bf5a97c96eed130ba7a89 @timhunt timhunt committed with stronk7 Sep 29, 2011
@@ -41,7 +41,7 @@ class qbehaviour_informationitem_walkthrough_test extends qbehaviour_walkthrough
public function test_informationitem_feedback_description() {
// Create a true-false question with correct answer true.
- $description = test_question_maker::make_a_description_question();
+ $description = test_question_maker::make_question('description');
$this->start_attempt_at_question($description, 'deferredfeedback');
// Check the initial state.
@@ -298,24 +298,6 @@ public static function make_an_essay_question() {
}
/**
- * Makes a truefalse question with correct ansewer true, defaultmark 1.
- * @return question_truefalse
- */
- public static function make_a_description_question() {
- question_bank::load_question_definition_classes('description');
- $description = new qtype_description_question();
- self::initialise_a_question($description);
- $description->name = 'Description question';
- $description->questiontext =
- 'This text tells you a bit about the next few questions in this quiz.';
- $description->generalfeedback =
- 'This is what this section of the quiz should have taught you.';
- $description->qtype = question_bank::get_qtype('description');
-
- return $description;
- }
-
- /**
* Add some standard overall feedback to a question. You need to use these
* specific feedback strings for the corresponding contains_..._feedback
* methods in {@link qbehaviour_walkthrough_test_base} to works.
@@ -47,7 +47,7 @@ class question_attempt_test extends UnitTestCase {
private $qa;
public function setUp() {
- $this->question = test_question_maker::make_a_description_question();
+ $this->question = test_question_maker::make_question('description');
$this->question->defaultmark = 3;
$this->usageid = 13;
$this->qa = new question_attempt($this->question, $this->usageid);
@@ -141,7 +141,7 @@ class question_attempt_with_steps_test extends UnitTestCase {
private $qa;
public function setUp() {
- $this->question = test_question_maker::make_a_description_question();
+ $this->question = test_question_maker::make_question('description');
$this->qa = new testable_question_attempt($this->question, 0, null, 2);
for ($i = 0; $i < 3; $i++) {
$step = new question_attempt_step(array('i' => $i));
@@ -46,10 +46,10 @@ public function setUp() {
get_context_instance(CONTEXT_SYSTEM));
$this->quba->set_preferred_behaviour('deferredfeedback');
- $slot = $this->quba->add_question(test_question_maker::make_a_description_question());
+ $slot = $this->quba->add_question(test_question_maker::make_question('description'));
$this->qas[$slot] = $this->quba->get_question_attempt($slot);
- $slot = $this->quba->add_question(test_question_maker::make_a_description_question());
+ $slot = $this->quba->add_question(test_question_maker::make_question('description'));
$this->qas[$slot] = $this->quba->get_question_attempt($slot);
$this->iterator = $this->quba->get_attempt_iterator();
@@ -41,7 +41,7 @@ class question_attempt_step_iterator_test extends UnitTestCase {
private $iterator;
public function setUp() {
- $question = test_question_maker::make_a_description_question();
+ $question = test_question_maker::make_question('description');
$this->qa = new testable_question_attempt($question, 0);
for ($i = 0; $i < 3; $i++) {
$step = new question_attempt_step(array('i' => $i));
@@ -0,0 +1,93 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Test helper code for the description question type.
+ *
+ * @package qtype
+ * @subpackage description
+ * @copyright 2010 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+
+defined('MOODLE_INTERNAL') || die();
+
+
+/**
+ * Test helper class for the description question type.
+ *
+ * @copyright 2010 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class qtype_description_test_helper extends question_test_helper {
+ public function get_test_questions() {
+ return array('info');
+ }
+
+ /**
+ * @return qtype_description_question
+ */
+ public static function make_description_question_info() {
+ question_bank::load_question_definition_classes('description');
+ $q = new qtype_description_question();
+
+ test_question_maker::initialise_a_question($q);
+ $q->defaultmark = 0;
+ $q->penalty = 0;
+ $q->length = 0;
+
+ $q->name = 'Description';
+ $q->questiontext = 'Here is some information about the questions you are about to attempt.';
+ $q->generalfeedback = 'And here is some more text shown only on the review page.';
+ $q->qtype = question_bank::get_qtype('description');
+
+ return $q;
+ }
+
+ /**
+ * Get the question data, as it would be loaded by get_question_options, for
+ * the question returned by {@link make_an_oumultiresponse_two_of_four()}.
+ * @return object
+ */
+ public static function get_question_data() {
+ global $USER;
+
+ $qdata = new stdClass();
+ $qdata->id = 0;
+ $qdata->contextid = 0;
+ $qdata->category = 0;
+ $qdata->parent = 0;
+ $qdata->stamp = make_unique_id_code();
+ $qdata->version = make_unique_id_code();
+ $qdata->timecreated = time();
+ $qdata->timemodified = time();
+ $qdata->createdby = $USER->id;
+ $qdata->modifiedby = $USER->id;
+ $qdata->qtype = 'description';
+ $qdata->name = 'Description';
+ $qdata->questiontext = 'Here is some information about the questions you are about to attempt.';
+ $qdata->questiontextformat = FORMAT_HTML;
+ $qdata->generalfeedback = 'And here is some more text shown only on the review page.';
+ $qdata->generalfeedbackformat = FORMAT_HTML;
+ $qdata->defaultmark = 0;
+ $qdata->length = 0;
+ $qdata->penalty = 0;
+ $qdata->hidden = 0;
+
+ return $qdata;
+ }
+}

0 comments on commit 5e69fe4

Please sign in to comment.