MDL-47494 gapselect: NOBUG changed unit tests to use PHPUnit
authorJamie Pratt <me@jamiep.org>
Tue, 19 Jun 2012 07:55:21 +0000 (14:55 +0700)
committerJamie Pratt <me@jamiep.org>
Tue, 19 Jun 2012 07:55:21 +0000 (14:55 +0700)
question/type/gapselect/tests/helper.php [moved from question/type/gapselect/simpletest/helper.php with 100% similarity]
question/type/gapselect/tests/question_test.php [moved from question/type/gapselect/simpletest/testquestion.php with 81% similarity]
question/type/gapselect/tests/questiontype_test.php [moved from question/type/gapselect/simpletest/testquestiontype.php with 92% similarity]
question/type/gapselect/tests/walkthrough_test.php [moved from question/type/gapselect/simpletest/testwalkthrough.php with 95% similarity]

  *
  * @package    qtype
  * @subpackage gapselect
- * @copyright  2011 The Open University
+ * @copyright  2012 The Open University
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 
 defined('MOODLE_INTERNAL') || die();
+global $CFG;
 
-require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
-require_once($CFG->dirroot . '/question/type/gapselect/simpletest/helper.php');
+require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
+require_once($CFG->dirroot . '/question/type/gapselect/tests/helper.php');
 
 
 /**
  * Unit tests for the select missing words question definition class.
  *
- * @copyright  2009 The Open University
+ * @copyright  2012 The Open University
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @group      qtype_gapselect
  */
-class qtype_gapselect_question_test extends UnitTestCase {
+class qtype_gapselect_question_test extends basic_testcase {
 
     public function test_get_question_summary() {
         $gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
-        $this->assertEqual('The [[1]] brown [[2]] jumped over the [[3]] dog.; ' .
+        $this->assertEquals('The [[1]] brown [[2]] jumped over the [[3]] dog.; ' .
                 '[[1]] -> {quick / slow}; [[2]] -> {fox / dog}; [[3]] -> {lazy / assiduous}',
                 $gapselect->get_question_summary());
     }
 
     public function test_get_question_summary_maths() {
         $gapselect = qtype_gapselect_test_helper::make_a_maths_gapselect_question();
-        $this->assertEqual('Fill in the operators to make this equation work: ' .
+        $this->assertEquals('Fill in the operators to make this equation work: ' .
                 '7 [[1]] 11 [[2]] 13 [[1]] 17 [[2]] 19 = 3; [[1]] -> {+ / - / * / /}',
                 $gapselect->get_question_summary());
     }
@@ -57,7 +59,7 @@ class qtype_gapselect_question_test extends UnitTestCase {
         $gapselect->shufflechoices = false;
         $gapselect->start_attempt(new question_attempt_step(), 1);
 
-        $this->assertEqual('{quick} {fox} {lazy}',
+        $this->assertEquals('{quick} {fox} {lazy}',
                 $gapselect->summarise_response(array('p1' => '1', 'p2' => '1', 'p3' => '1')));
     }
 
@@ -66,18 +68,18 @@ class qtype_gapselect_question_test extends UnitTestCase {
         $gapselect->shufflechoices = false;
         $gapselect->start_attempt(new question_attempt_step(), 1);
 
-        $this->assertEqual('{+} {-} {+} {-}', $gapselect->summarise_response(
+        $this->assertEquals('{+} {-} {+} {-}', $gapselect->summarise_response(
                 array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
     }
 
     public function test_get_random_guess_score() {
         $gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
-        $this->assertEqual(0.5, $gapselect->get_random_guess_score());
+        $this->assertEquals(0.5, $gapselect->get_random_guess_score());
     }
 
     public function test_get_random_guess_score_maths() {
         $gapselect = qtype_gapselect_test_helper::make_a_maths_gapselect_question();
-        $this->assertEqual(0.25, $gapselect->get_random_guess_score());
+        $this->assertEquals(0.25, $gapselect->get_random_guess_score());
     }
 
     public function test_get_right_choice_for() {
@@ -85,8 +87,8 @@ class qtype_gapselect_question_test extends UnitTestCase {
         $gapselect->shufflechoices = false;
         $gapselect->start_attempt(new question_attempt_step(), 1);
 
-        $this->assertEqual(1, $gapselect->get_right_choice_for(1));
-        $this->assertEqual(1, $gapselect->get_right_choice_for(2));
+        $this->assertEquals(1, $gapselect->get_right_choice_for(1));
+        $this->assertEquals(1, $gapselect->get_right_choice_for(2));
     }
 
     public function test_get_right_choice_for_maths() {
@@ -94,8 +96,8 @@ class qtype_gapselect_question_test extends UnitTestCase {
         $gapselect->shufflechoices = false;
         $gapselect->start_attempt(new question_attempt_step(), 1);
 
-        $this->assertEqual(1, $gapselect->get_right_choice_for(1));
-        $this->assertEqual(2, $gapselect->get_right_choice_for(2));
+        $this->assertEquals(1, $gapselect->get_right_choice_for(1));
+        $this->assertEquals(2, $gapselect->get_right_choice_for(2));
     }
 
     public function test_clear_wrong_from_response() {
@@ -104,7 +106,7 @@ class qtype_gapselect_question_test extends UnitTestCase {
         $gapselect->start_attempt(new question_attempt_step(), 1);
 
         $initialresponse = array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1');
-        $this->assertEqual(array('p1' => '1', 'p2' => '0', 'p3' => '1', 'p4' => '0'),
+        $this->assertEquals(array('p1' => '1', 'p2' => '0', 'p3' => '1', 'p4' => '0'),
                 $gapselect->clear_wrong_from_response($initialresponse));
     }
 
@@ -113,9 +115,9 @@ class qtype_gapselect_question_test extends UnitTestCase {
         $gapselect->shufflechoices = false;
         $gapselect->start_attempt(new question_attempt_step(), 1);
 
-        $this->assertEqual(array(2, 3),
+        $this->assertEquals(array(2, 3),
                 $gapselect->get_num_parts_right(array('p1' => '1', 'p2' => '1', 'p3' => '2')));
-        $this->assertEqual(array(3, 3),
+        $this->assertEquals(array(3, 3),
                 $gapselect->get_num_parts_right(array('p1' => '1', 'p2' => '1', 'p3' => '1')));
     }
 
@@ -124,7 +126,7 @@ class qtype_gapselect_question_test extends UnitTestCase {
         $gapselect->shufflechoices = false;
         $gapselect->start_attempt(new question_attempt_step(), 1);
 
-        $this->assertEqual(array(2, 4), $gapselect->get_num_parts_right(
+        $this->assertEquals(array(2, 4), $gapselect->get_num_parts_right(
                 array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
     }
 
@@ -132,7 +134,7 @@ class qtype_gapselect_question_test extends UnitTestCase {
         $gapselect = qtype_gapselect_test_helper::make_a_gapselect_question();
         $gapselect->start_attempt(new question_attempt_step(), 1);
 
-        $this->assertEqual(array('p1' => PARAM_INT, 'p2' => PARAM_INT, 'p3' => PARAM_INT),
+        $this->assertEquals(array('p1' => PARAM_INT, 'p2' => PARAM_INT, 'p3' => PARAM_INT),
                 $gapselect->get_expected_data());
     }
 
@@ -141,7 +143,7 @@ class qtype_gapselect_question_test extends UnitTestCase {
         $gapselect->shufflechoices = false;
         $gapselect->start_attempt(new question_attempt_step(), 1);
 
-        $this->assertEqual(array('p1' => '1', 'p2' => '1', 'p3' => '1'),
+        $this->assertEquals(array('p1' => '1', 'p2' => '1', 'p3' => '1'),
                 $gapselect->get_correct_response());
     }
 
@@ -150,7 +152,7 @@ class qtype_gapselect_question_test extends UnitTestCase {
         $gapselect->shufflechoices = false;
         $gapselect->start_attempt(new question_attempt_step(), 1);
 
-        $this->assertEqual(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2'),
+        $this->assertEquals(array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2'),
                 $gapselect->get_correct_response());
     }
 
@@ -209,11 +211,11 @@ class qtype_gapselect_question_test extends UnitTestCase {
         $gapselect->shufflechoices = false;
         $gapselect->start_attempt(new question_attempt_step(), 1);
 
-        $this->assertEqual(array(1, question_state::$gradedright),
+        $this->assertEquals(array(1, question_state::$gradedright),
                 $gapselect->grade_response(array('p1' => '1', 'p2' => '1', 'p3' => '1')));
-        $this->assertEqual(array(1/3, question_state::$gradedpartial),
+        $this->assertEquals(array(1/3, question_state::$gradedpartial),
                 $gapselect->grade_response(array('p1' => '1')));
-        $this->assertEqual(array(0, question_state::$gradedwrong),
+        $this->assertEquals(array(0, question_state::$gradedwrong),
                 $gapselect->grade_response(array('p1' => '2', 'p2' => '2', 'p3' => '2')));
     }
 
@@ -222,11 +224,11 @@ class qtype_gapselect_question_test extends UnitTestCase {
         $gapselect->shufflechoices = false;
         $gapselect->start_attempt(new question_attempt_step(), 1);
 
-        $this->assertEqual(array(1, question_state::$gradedright), $gapselect->grade_response(
+        $this->assertEquals(array(1, question_state::$gradedright), $gapselect->grade_response(
                 array('p1' => '1', 'p2' => '2', 'p3' => '1', 'p4' => '2')));
-        $this->assertEqual(array(0.5, question_state::$gradedpartial), $gapselect->grade_response(
+        $this->assertEquals(array(0.5, question_state::$gradedpartial), $gapselect->grade_response(
                 array('p1' => '1', 'p2' => '1', 'p3' => '1', 'p4' => '1')));
-        $this->assertEqual(array(0, question_state::$gradedwrong), $gapselect->grade_response(
+        $this->assertEquals(array(0, question_state::$gradedwrong), $gapselect->grade_response(
                 array('p1' => '0', 'p2' => '1', 'p3' => '2', 'p4' => '1')));
     }
 
@@ -235,12 +237,12 @@ class qtype_gapselect_question_test extends UnitTestCase {
         $gapselect->shufflechoices = false;
         $gapselect->start_attempt(new question_attempt_step(), 1);
 
-        $this->assertEqual(array(
+        $this->assertEquals(array(
                     1 => new question_classified_response(1, 'quick', 1/3),
                     2 => new question_classified_response(2, 'dog', 0),
                     3 => new question_classified_response(1, 'lazy', 1/3),
                 ), $gapselect->classify_response(array('p1' => '1', 'p2' => '2', 'p3' => '1')));
-        $this->assertEqual(array(
+        $this->assertEquals(array(
                     1 => question_classified_response::no_response(),
                     2 => new question_classified_response(1, 'fox', 1/3),
                     3 => new question_classified_response(2, 'assiduous', 0),
  *
  * @package    qtype
  * @subpackage gapselect
- * @copyright  2011 The Open University
+ * @copyright  2012 The Open University
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 
 defined('MOODLE_INTERNAL') || die();
+global $CFG;
 
-require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
-require_once($CFG->dirroot . '/question/type/gapselect/simpletest/helper.php');
+require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
+require_once($CFG->dirroot . '/question/type/gapselect/tests/helper.php');
 
 
 /**
  * Unit tests for the select missing words question definition class.
  *
- * @copyright  2011 The Open University
+ * @copyright  2012 The Open University
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @group      qtype_gapselect
  */
-class qtype_gapselect_test extends UnitTestCase {
+class qtype_gapselect_test extends question_testcase {
     /** @var qtype_gapselect instance of the question type class to test. */
     protected $qtype;
 
-    public function setUp() {
+    protected function setUp() {
         $this->qtype = question_bank::get_qtype('gapselect');;
     }
 
-    public function tearDown() {
+    protected function tearDown() {
         $this->qtype = null;
     }
 
     public function assert_same_xml($expectedxml, $xml) {
-        $this->assertEqual(str_replace("\r\n", "\n", $expectedxml),
+        $this->assertEquals(str_replace("\r\n", "\n", $expectedxml),
                 str_replace("\r\n", "\n", $xml));
     }
 
@@ -83,6 +85,7 @@ class qtype_gapselect_test extends UnitTestCase {
         $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.';
         $gapselect->qtype = 'gapselect';
 
+        $gapselect->options = new stdClass();
         $gapselect->options->shuffleanswers = true;
 
         test_question_maker::set_standard_combined_feedback_fields($gapselect->options);
@@ -100,7 +103,7 @@ class qtype_gapselect_test extends UnitTestCase {
     }
 
     public function test_name() {
-        $this->assertEqual($this->qtype->name(), 'gapselect');
+        $this->assertEquals($this->qtype->name(), 'gapselect');
     }
 
     public function test_can_analyse_responses() {
@@ -116,18 +119,18 @@ class qtype_gapselect_test extends UnitTestCase {
 
         $q = $this->qtype->make_question($qdata);
 
-        $this->assertEqual($expected, $q);
+        $this->assertEquals($expected, $q);
     }
 
     public function test_get_random_guess_score() {
         $q = $this->get_test_question_data();
-        $this->assertWithinMargin(0.5, $this->qtype->get_random_guess_score($q), 0.0000001);
+        $this->assertEquals(0.5, $this->qtype->get_random_guess_score($q), '', 0.0000001);
     }
 
     public function test_get_possible_responses() {
         $q = $this->get_test_question_data();
 
-        $this->assertEqual(array(
+        $this->assertEquals(array(
             1 => array(
                 1 => new question_possible_response('quick', 1/3),
                 2 => new question_possible_response('slow', 0),
@@ -228,8 +231,8 @@ class qtype_gapselect_test extends UnitTestCase {
                         'format' => FORMAT_MOODLE, 'files' => array()));
         $expectedq->hintshownumcorrect = array(true, true);
         $expectedq->hintclearwrong = array(false, true);
-        $this->assert(new CheckSpecifiedFieldsExpectation($expectedq), $q);
-        $this->assertEqual($expectedq->hint, $q->hint);
+        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
+        $this->assertEquals($expectedq->hint, $q->hint);
     }
 
     public function test_xml_export() {
@@ -247,6 +250,7 @@ class qtype_gapselect_test extends UnitTestCase {
         $qdata->penalty = 0.3333333;
         $qdata->hidden = 0;
 
+        $qdata->options = new stdClass();
         $qdata->options->shuffleanswers = 1;
         $qdata->options->correctfeedback = '<p>Your answer is correct.</p>';
         $qdata->options->correctfeedbackformat = FORMAT_MOODLE;
  *
  * @package    qtype
  * @subpackage gapselect
- * @copyright  2011 The Open University
+ * @copyright  2012 The Open University
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
 
 defined('MOODLE_INTERNAL') || die();
+global $CFG;
 
-require_once($CFG->dirroot . '/question/engine/simpletest/helpers.php');
-require_once($CFG->dirroot . '/question/type/gapselect/simpletest/helper.php');
+require_once($CFG->dirroot . '/question/engine/tests/helpers.php');
+require_once($CFG->dirroot . '/question/type/gapselect/tests/helper.php');
 
 
 /**
  * Unit tests for the gap-select question type.
  *
- * @copyright  2011 The Open University
+ * @copyright  2012 The Open University
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @group      qtype_gapselect
  */
 class qtype_gapselect_walkthrough_test extends qbehaviour_walkthrough_test_base {
     public function test_interactive_behaviour() {
@@ -99,7 +101,7 @@ class qtype_gapselect_walkthrough_test extends qbehaviour_walkthrough_test_base
                         $this->get_contains_submit_button_expectation(false),
                 $this->get_contains_try_again_button_expectation(true),
                 $this->get_does_not_contain_correctness_expectation(),
-                new PatternExpectation('/' . preg_quote(
+                new question_pattern_expectation('/' . preg_quote(
                         get_string('notcomplete', 'qbehaviour_interactive')) . '/'),
                 $this->get_contains_hint_expectation('This is the first hint'));