From adb21080a36e90c928c8bdf6654dbe8c4886aa0f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luca=20B=C3=B6sch?= Date: Fri, 26 Jan 2018 16:16:30 +0100 Subject: [PATCH] MDL-61502 questions: add filter tests to gapselect question type. --- question/type/gapselect/tests/helper.php | 41 ++++++++++++++++++++++ question/type/gapselect/tests/walkthrough_test.php | 23 ++++++++++++ 2 files changed, 64 insertions(+) diff --git a/question/type/gapselect/tests/helper.php b/question/type/gapselect/tests/helper.php index c9664e78c1c..6c1b2a2606a 100644 --- a/question/type/gapselect/tests/helper.php +++ b/question/type/gapselect/tests/helper.php @@ -105,4 +105,45 @@ class qtype_gapselect_test_helper { return $gapselect; } + + /** + * Get an example gapselect question with multilang entries to use for testing. + * @return qtype_gapselect_question + */ + public static function make_a_multilang_gapselect_question() { + question_bank::load_question_definition_classes('gapselect'); + $gapselect = new qtype_gapselect_question(); + + test_question_maker::initialise_a_question($gapselect); + + $gapselect->name = 'Multilang select missing words question'; + $gapselect->questiontext = 'The [[1]] ' . + 'sat on theсидела на [[2]].'; + $gapselect->generalfeedback = 'This sentence uses each letter of the alphabet.'; + $gapselect->qtype = question_bank::get_qtype('gapselect'); + + $gapselect->shufflechoices = true; + + test_question_maker::set_standard_combined_feedback_fields($gapselect); + + $gapselect->choices = array( + 1 => array( + 1 => new qtype_gapselect_choice('catкошка', 1, true), + 2 => new qtype_gapselect_choice('dogпес', 1, true)), + 2 => array( + 1 => new qtype_gapselect_choice('matковрике', 2, true), + 2 => new qtype_gapselect_choice('batбита', 2, true)) + ); + + $gapselect->places = array(1 => 1, 2 => 2); + $gapselect->rightchoices = array(1 => 1, 2 => 1); + $gapselect->textfragments = array('The ', + ' sat on theсидела на ', '.'); + + return $gapselect; + } } diff --git a/question/type/gapselect/tests/walkthrough_test.php b/question/type/gapselect/tests/walkthrough_test.php index b51b439a4e7..67752b2896c 100644 --- a/question/type/gapselect/tests/walkthrough_test.php +++ b/question/type/gapselect/tests/walkthrough_test.php @@ -143,4 +143,27 @@ class qtype_gapselect_walkthrough_test extends qbehaviour_walkthrough_test_base $this->check_current_state(question_state::$gradedright); $this->check_current_mark(2); } + + public function test_multilang_behaviour() { + + // Enable multilang filter to on content and heading. + filter_set_global_state('multilang', TEXTFILTER_ON); + filter_set_applies_to_strings('multilang', 1); + $filtermanager = filter_manager::instance(); + $filtermanager->reset_caches(); + + // Create a multilang gapselect question. + $q = qtype_gapselect_test_helper::make_a_multilang_gapselect_question(); + $q->shufflechoices = false; + $this->start_attempt_at_question($q, 'interactive', 3); + + // Check the initial state. + $this->check_current_state(question_state::$todo); + $this->check_current_mark(null); + $this->check_current_output( + $this->get_contains_select_expectation('p1', + array('' => get_string('choosedots'), '1' => 'cat', '2' => 'dog'), null, true), + $this->get_contains_select_expectation('p2', + array('' => get_string('choosedots'), '1' => 'mat', '2' => 'bat'), null, true)); + } } -- 2.11.4.GIT