Merge branch 'MDL-61502-master' of https://github.com/lucaboesch/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 3 Apr 2018 22:49:59 +0000 (00:49 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 3 Apr 2018 22:49:59 +0000 (00:49 +0200)
question/type/gapselect/tests/helper.php
question/type/gapselect/tests/walkthrough_test.php

index c9664e7..6c1b2a2 100644 (file)
@@ -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 = '<span lang="en" class="multilang">The </span><span lang="ru" class="multilang"></span>[[1]] ' .
+            '<span lang="en" class="multilang">sat on the</span><span lang="ru" class="multilang">сидела на</span> [[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('<span lang="en" class="multilang">cat</span><span lang="ru" ' .
+                        'class="multilang">кошка</span>', 1, true),
+                    2 => new qtype_gapselect_choice('<span lang="en" class="multilang">dog</span><span lang="ru" ' .
+                        'class="multilang">пес</span>', 1, true)),
+                2 => array(
+                    1 => new qtype_gapselect_choice('<span lang="en" class="multilang">mat</span><span lang="ru" ' .
+                        'class="multilang">коврике</span>', 2, true),
+                    2 => new qtype_gapselect_choice('<span lang="en" class="multilang">bat</span><span lang="ru" ' .
+                        'class="multilang">бита</span>', 2, true))
+                );
+
+        $gapselect->places = array(1 => 1, 2 => 2);
+        $gapselect->rightchoices = array(1 => 1, 2 => 1);
+        $gapselect->textfragments = array('<span lang="en" class="multilang">The </span><span lang="ru" class="multilang"></span>',
+            ' <span lang="en" class="multilang">sat on the</span><span lang="ru" class="multilang">сидела на</span> ', '.');
+
+        return $gapselect;
+    }
 }
index b51b439..67752b2 100644 (file)
@@ -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));
+    }
 }