diff --git a/question.php b/question.php index fbf4071..fdafb11 100755 --- a/question.php +++ b/question.php @@ -37,6 +37,7 @@ class qtype_gapfill_question extends question_graded_automatically_with_countbac */ public $answer; + /** * Display draggables after the body of the question * @var boolean diff --git a/tests/helper.php b/tests/helper.php index 64ea1f0..6f0c4ce 100755 --- a/tests/helper.php +++ b/tests/helper.php @@ -33,13 +33,14 @@ */ class qtype_gapfill_test_helper extends question_test_helper { + /** * must be implemented or class made abstract * * @return string */ public function get_test_questions() { - return array('catmat'); + return ['catmat']; } /** @@ -218,7 +219,7 @@ public static function make_question($questiontext = "The [cat] sat on the [mat] 'qtype' => 'gapfill', 'length' => '1', 'stamp' => 'tjh238.vledev.open.ac.uk+100708154547+JrHygi', - 'version' => 'tjh238.vledev.open.ac.uk+100708154548+a3zh8v', + 'version' => 1, 'hidden' => '0', 'timecreated' => '1278603947', 'timemodified' => '1278603947', @@ -231,7 +232,6 @@ public static function make_question($questiontext = "The [cat] sat on the [mat] ]; $question = $question->qtype->make_question($questiondata); - $question->gapstofill = count($answerwords); return $question; } diff --git a/tests/question_test.php b/tests/question_test.php index fb6ee78..f73f914 100755 --- a/tests/question_test.php +++ b/tests/question_test.php @@ -43,6 +43,15 @@ * @coversDefaultClass \question\type\gapfill\question */ class question_test extends \advanced_testcase { + + /** + * + * @var qtype_gapfill $gapfill + * An instance of the question type + */ + public $qtype; + + /** * Test value returned by questionid_column_name() * @@ -255,6 +264,7 @@ public function test_is_same_response() { } public function setUp(): void { $this->qtype = \question_bank::get_qtype('gapfill'); + } protected function tearDown(): void { diff --git a/tests/questiontype_test.php b/tests/questiontype_test.php index e0fa0f6..df077da 100755 --- a/tests/questiontype_test.php +++ b/tests/questiontype_test.php @@ -40,13 +40,21 @@ class questiontype_test extends \advanced_testcase { /** - * explained here https://docs.moodle.org/dev/Unit_test_API + * + * @var qtype_gapfill $gapfill + * + * An instance of the question type + */ + public $qtype; + + /** + * Explained here https://docs.moodle.org/dev/Unit_test_API * @var array */ - protected static $includecoverage = array( + protected static $includecoverage = [ 'question/type/questiontypebase.php', 'question/type/gapfill/questiontype.php', - ); + ]; protected function setUp(): void { $this->qtype = new \qtype_gapfill(); @@ -94,7 +102,7 @@ protected function get_test_question_data() { * * @covers ::save_question */ - public function test_save_question() { + public function test_save_question() : void { $this->resetAfterTest(); global $DB; $syscontext = \context_system::instance(); @@ -128,7 +136,7 @@ public function test_save_question() { * * @covers ::name() */ - public function test_name() { + public function test_name() :void { $this->assertEquals($this->qtype->name(), 'gapfill'); } @@ -141,7 +149,7 @@ public function test_name() { * * @covers ::can_analyse_responses() */ - public function test_can_analyse_responses() { + public function test_can_analyse_responses() :void { $this->assertFalse($this->qtype->can_analyse_responses()); } @@ -150,7 +158,7 @@ public function test_can_analyse_responses() { * * @covers ::questionid_column_name() */ - public function test_questionid_column_name() { + public function test_questionid_column_name() : void { $this->assertEquals($this->qtype->questionid_column_name(), 'question'); } @@ -159,9 +167,9 @@ public function test_questionid_column_name() { * * @covers ::extra_question_fields() */ - public function test_extra_question_fields() { - $extraquestionfields = array('question_gapfill', 'answerdisplay', 'delimitchars', - 'casesensitive', 'noduplicates', 'disableregex', 'fixedgapsize', 'optionsaftertext', 'letterhints', 'singleuse'); + public function test_extra_question_fields() :void { + $extraquestionfields = ['question_gapfill', 'answerdisplay', 'delimitchars', + 'casesensitive', 'noduplicates', 'disableregex', 'fixedgapsize', 'optionsaftertext', 'letterhints', 'singleuse']; $this->assertEquals($this->qtype->extra_question_fields(), $extraquestionfields); } } diff --git a/tests/walkthrough_test.php b/tests/walkthrough_test.php index 9f3032a..f55e32e 100755 --- a/tests/walkthrough_test.php +++ b/tests/walkthrough_test.php @@ -423,7 +423,8 @@ public function test_disableregex() { 'disableregex' => 1, ]; $gapfill = helper::make_question($questiontext, $options); - $this->start_attempt_at_question($gapfill, 'interactive', $gapfill->gapstofill); + $gapstofill = count($gapfill->answers); + $this->start_attempt_at_question($gapfill, 'interactive', $gapstofill); $this->check_current_state(\question_state::$todo); $this->check_current_mark(null); @@ -467,8 +468,9 @@ public function test_interactive_discard_duplicates() { $submission = array('-submit' => 1, 'p1' => 'gold', 'p2' => 'silver', 'p3' => 'silver'); $gapfill = helper::make_question( $questiontext, $options); + $gapstofill = count($gapfill->answers); - $this->start_attempt_at_question($gapfill, 'interactive', $gapfill->gapstofill); + $this->start_attempt_at_question($gapfill, 'interactive', $gapstofill); // Check the initial state. $this->check_current_state(\question_state::$todo); @@ -498,7 +500,9 @@ public function test_interactive_discard_duplicates() { public function test_no_duplicate_draggables() { $qtext = 'Bicycles have [wheels]. Cars have [wheels|engines].'; $gapfill = helper::make_question($qtext); - $this->start_attempt_at_question($gapfill, 'interactive', $gapfill->gapstofill); + $gapstofill = count($gapfill->answers); + + $this->start_attempt_at_question($gapfill, 'interactive', $gapstofill); // Confirm draggables are unique, i.e. wheels appears only once. $this->assertEquals(2, count($gapfill->allanswers)); } @@ -509,11 +513,13 @@ public function test_no_duplicate_draggables() { */ public function test_get_letter_hints() { $gapfill = helper::make_question(); + $gapstofill = count($gapfill->answers); + $gapfill->hints = [ new \question_hint(1, 'This is the first hint.', FORMAT_HTML), new \question_hint(2, 'This is the second hint.', FORMAT_HTML), ]; - $this->start_attempt_at_question($gapfill, 'interactive', $gapfill->gapstofill); + $this->start_attempt_at_question($gapfill, 'interactive', $gapstofill); $this->process_submission([ '-submit' => 1, 'p1' => 'cat', 'p2' => 'cat']); $this->process_submission(array('-tryagain' => 1)); $qa = $this->quba->get_question_attempt($this->slot); @@ -549,8 +555,9 @@ public function test_interactive_grade_for_blank() { [one] sat on the [two] [!!] '; $gapfill = helper::make_question( $questiontext); + $gapstofill = count($gapfill->answers); - $this->start_attempt_at_question($gapfill, 'interactive', $gapfill->gapstofill); + $this->start_attempt_at_question($gapfill, 'interactive', $gapstofill); /* answer with duplicate values, only one of each duplicate should get a mark */ /* save answer */ @@ -579,7 +586,7 @@ public function test_interactive_grade_for_blank() { $this->check_current_state(\question_state::$gradedright); /* start again but put a value in the field expecting a blank */ - $this->start_attempt_at_question($gapfill, 'interactive', $gapfill->gapstofill); + $this->start_attempt_at_question($gapfill, 'interactive', $gapstofill); $submission = array('p1' => 'one', 'p2' => 'two', 'p3' => "three"); $this->process_submission($submission); $this->check_step_count(2); @@ -669,8 +676,9 @@ public function test_deferred_grade_for_blank() { [one] sat on the [two] [!!] '; $gapfill = helper::make_question( $questiontext); + $gapstofill = count($gapfill->answers); - $this->start_attempt_at_question($gapfill, 'deferredfeedback', $gapfill->gapstofill); + $this->start_attempt_at_question($gapfill, 'deferredfeedback', $gapstofill); /* A mark for a blank submission where the gap is [!!] */ $submission = array('p1' => 'one', 'p2' => 'two', 'p3' => ''); @@ -704,7 +712,6 @@ public function test_immediatefeedback_with_correct() { $gapfill = helper::make_question(); $maxmark = 2; - $gapfill->showanswers = true; $this->start_attempt_at_question($gapfill, 'immediatefeedback', $maxmark); // Check the initial state.