Skip to content

Commit

Permalink
MDL-29571 qtype description refactor unit test code a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt authored and stronk7 committed Oct 4, 2011
1 parent 0870a06 commit 9d1658a
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 0 additions & 18 deletions question/engine/simpletest/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,24 +297,6 @@ public static function make_an_essay_question() {
return $essay;
}

/**
* 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
Expand Down
4 changes: 2 additions & 2 deletions question/engine/simpletest/testquestionattempt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions question/engine/simpletest/testquestionattemptiterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
93 changes: 93 additions & 0 deletions question/type/description/simpletest/helper.php
Original file line number Diff line number Diff line change
@@ -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 9d1658a

Please sign in to comment.