Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 42... Línea 42...
42
            phpunit_util::normalise_line_endings($expectedtext),
42
            phpunit_util::normalise_line_endings($expectedtext),
43
            phpunit_util::normalise_line_endings($text)
43
            phpunit_util::normalise_line_endings($text)
44
        );
44
        );
45
    }
45
    }
Línea 46... Línea 46...
46
 
46
 
47
    public function test_import_essay() {
47
    public function test_import_essay(): void {
48
        $gift = '
48
        $gift = '
49
// essay
49
// essay
50
::Q8:: How are you? {}';
50
::Q8:: How are you? {}';
Línea 73... Línea 73...
73
        );
73
        );
Línea 74... Línea 74...
74
 
74
 
75
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
75
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
Línea 76... Línea 76...
76
    }
76
    }
77
 
77
 
78
    public function test_export_essay() {
78
    public function test_export_essay(): void {
79
        $qdata = (object) array(
79
        $qdata = (object) array(
80
            'id' => 666 ,
80
            'id' => 666 ,
81
            'name' => 'Q8',
81
            'name' => 'Q8',
Línea 105... Línea 105...
105
";
105
";
Línea 106... Línea 106...
106
 
106
 
107
        $this->assert_same_gift($expectedgift, $gift);
107
        $this->assert_same_gift($expectedgift, $gift);
Línea 108... Línea 108...
108
    }
108
    }
109
 
109
 
110
    public function test_import_match() {
110
    public function test_import_match(): void {
111
        $gift = '
111
        $gift = '
112
// question: 2  name: Moodle activities
112
// question: 2  name: Moodle activities
113
::Moodle activities::[html]Match the <b>activity</b> to the description.{
113
::Moodle activities::[html]Match the <b>activity</b> to the description.{
Línea 187... Línea 187...
187
        // Repeated test for better failure messages.
187
        // Repeated test for better failure messages.
188
        $this->assertEquals($expectedq->subquestions, $q->subquestions);
188
        $this->assertEquals($expectedq->subquestions, $q->subquestions);
189
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
189
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
190
    }
190
    }
Línea 191... Línea 191...
191
 
191
 
192
    public function test_export_match() {
192
    public function test_export_match(): void {
193
        $qdata = (object) array(
193
        $qdata = (object) array(
194
            'id' => 666 ,
194
            'id' => 666 ,
195
            'name' => 'Moodle activities',
195
            'name' => 'Moodle activities',
196
            'questiontext' => 'Match the <b>activity</b> to the description.',
196
            'questiontext' => 'Match the <b>activity</b> to the description.',
Línea 273... Línea 273...
273
     * @dataProvider numberingstyle_provider
273
     * @dataProvider numberingstyle_provider
274
     *
274
     *
275
     * @param string $numberingstyle multichoice numbering style to set for qtype_multichoice
275
     * @param string $numberingstyle multichoice numbering style to set for qtype_multichoice
276
     *
276
     *
277
     */
277
     */
278
    public function test_import_multichoice($numberingstyle) {
278
    public function test_import_multichoice($numberingstyle): void {
279
        $this->resetAfterTest(true);
279
        $this->resetAfterTest(true);
Línea 280... Línea 280...
280
 
280
 
281
        set_config('answernumbering', $numberingstyle, 'qtype_multichoice');
281
        set_config('answernumbering', $numberingstyle, 'qtype_multichoice');
282
        $gift = "
282
        $gift = "
Línea 378... Línea 378...
378
            ['IIII'],
378
            ['IIII'],
379
            ['none']
379
            ['none']
380
        ];
380
        ];
381
    }
381
    }
Línea 382... Línea 382...
382
 
382
 
383
    public function test_import_multichoice_multi() {
383
    public function test_import_multichoice_multi(): void {
384
        $gift = "
384
        $gift = "
385
// multiple choice, multiple response with specified feedback for right and wrong answers
385
// multiple choice, multiple response with specified feedback for right and wrong answers
386
::colours:: What's between orange and green in the spectrum?
386
::colours:: What's between orange and green in the spectrum?
387
{
387
{
Línea 474... Línea 474...
474
        $this->assertEquals($expectedq->answer, $q->answer);
474
        $this->assertEquals($expectedq->answer, $q->answer);
475
        $this->assertEquals($expectedq->feedback, $q->feedback);
475
        $this->assertEquals($expectedq->feedback, $q->feedback);
476
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
476
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
477
    }
477
    }
Línea 478... Línea 478...
478
 
478
 
479
    public function test_import_multichoice_multi_tricky() {
479
    public function test_import_multichoice_multi_tricky(): void {
480
        $gift = "
480
        $gift = "
481
// multiple choice, multiple response with specified feedback for right and wrong answers
481
// multiple choice, multiple response with specified feedback for right and wrong answers
482
::colours:: What's between orange and green in the spectrum?
482
::colours:: What's between orange and green in the spectrum?
483
{
483
{
Línea 559... Línea 559...
559
        $this->assertEquals($expectedq->answer, $q->answer);
559
        $this->assertEquals($expectedq->answer, $q->answer);
560
        $this->assertEquals($expectedq->feedback, $q->feedback);
560
        $this->assertEquals($expectedq->feedback, $q->feedback);
561
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
561
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
562
    }
562
    }
Línea 563... Línea 563...
563
 
563
 
564
    public function test_export_multichoice() {
564
    public function test_export_multichoice(): void {
565
        $qdata = (object) array(
565
        $qdata = (object) array(
566
            'id' => 666 ,
566
            'id' => 666 ,
567
            'name' => 'Q8',
567
            'name' => 'Q8',
568
            'questiontext' => "What's between orange and green in the spectrum?",
568
            'questiontext' => "What's between orange and green in the spectrum?",
Línea 625... Línea 625...
625
";
625
";
Línea 626... Línea 626...
626
 
626
 
627
        $this->assert_same_gift($expectedgift, $gift);
627
        $this->assert_same_gift($expectedgift, $gift);
Línea 628... Línea 628...
628
    }
628
    }
629
 
629
 
630
    public function test_export_multichoice_multi_tricky() {
630
    public function test_export_multichoice_multi_tricky(): void {
631
        $qdata = (object) array(
631
        $qdata = (object) array(
632
            'id' => 666 ,
632
            'id' => 666 ,
633
            'name' => 'Q8',
633
            'name' => 'Q8',
Línea 691... Línea 691...
691
";
691
";
Línea 692... Línea 692...
692
 
692
 
693
        $this->assert_same_gift($expectedgift, $gift);
693
        $this->assert_same_gift($expectedgift, $gift);
Línea 694... Línea 694...
694
    }
694
    }
695
 
695
 
696
    public function test_import_numerical() {
696
    public function test_import_numerical(): void {
697
        $gift = "
697
        $gift = "
698
// math range question
698
// math range question
Línea 737... Línea 737...
737
        $this->assertEquals($expectedq->fraction, $q->fraction);
737
        $this->assertEquals($expectedq->fraction, $q->fraction);
738
        $this->assertEquals($expectedq->feedback, $q->feedback);
738
        $this->assertEquals($expectedq->feedback, $q->feedback);
739
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
739
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
740
    }
740
    }
Línea 741... Línea 741...
741
 
741
 
742
    public function test_export_numerical() {
742
    public function test_export_numerical(): void {
743
        $qdata = (object) array(
743
        $qdata = (object) array(
744
            'id' => 666 ,
744
            'id' => 666 ,
745
            'name' => 'Q5',
745
            'name' => 'Q5',
746
            'questiontext' => "What is a number from 1 to 5?",
746
            'questiontext' => "What is a number from 1 to 5?",
Línea 793... Línea 793...
793
";
793
";
Línea 794... Línea 794...
794
 
794
 
795
        $this->assert_same_gift($expectedgift, $gift);
795
        $this->assert_same_gift($expectedgift, $gift);
Línea 796... Línea 796...
796
    }
796
    }
797
 
797
 
798
    public function test_import_shortanswer() {
798
    public function test_import_shortanswer(): void {
799
        $gift = "
799
        $gift = "
800
// question: 666  name: Shortanswer
800
// question: 666  name: Shortanswer
801
::Shortanswer::Which is the best animal?{
801
::Shortanswer::Which is the best animal?{
Línea 848... Línea 848...
848
        $this->assertEquals($expectedq->fraction, $q->fraction);
848
        $this->assertEquals($expectedq->fraction, $q->fraction);
849
        $this->assertEquals($expectedq->feedback, $q->feedback);
849
        $this->assertEquals($expectedq->feedback, $q->feedback);
850
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
850
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
851
    }
851
    }
Línea 852... Línea 852...
852
 
852
 
853
    public function test_import_shortanswer_with_general_feedback() {
853
    public function test_import_shortanswer_with_general_feedback(): void {
854
        $gift = "
854
        $gift = "
855
// question: 666  name: Shortanswer
855
// question: 666  name: Shortanswer
856
::Shortanswer::Which is the best animal?{
856
::Shortanswer::Which is the best animal?{
857
    =Frog#Good!
857
    =Frog#Good!
Línea 904... Línea 904...
904
        $this->assertEquals($expectedq->fraction, $q->fraction);
904
        $this->assertEquals($expectedq->fraction, $q->fraction);
905
        $this->assertEquals($expectedq->feedback, $q->feedback);
905
        $this->assertEquals($expectedq->feedback, $q->feedback);
906
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
906
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
907
    }
907
    }
Línea 908... Línea 908...
908
 
908
 
909
    public function test_export_shortanswer() {
909
    public function test_export_shortanswer(): void {
910
        $qdata = (object) array(
910
        $qdata = (object) array(
911
            'id' => 666 ,
911
            'id' => 666 ,
912
            'name' => 'Shortanswer',
912
            'name' => 'Shortanswer',
913
            'questiontext' => "Which is the best animal?",
913
            'questiontext' => "Which is the best animal?",
Línea 964... Línea 964...
964
";
964
";
Línea 965... Línea 965...
965
 
965
 
966
        $this->assert_same_gift($expectedgift, $gift);
966
        $this->assert_same_gift($expectedgift, $gift);
Línea 967... Línea 967...
967
    }
967
    }
968
 
968
 
969
    public function test_export_shortanswer_with_general_feedback() {
969
    public function test_export_shortanswer_with_general_feedback(): void {
970
        $qdata = (object) array(
970
        $qdata = (object) array(
971
            'id' => 666 ,
971
            'id' => 666 ,
972
            'name' => 'Shortanswer',
972
            'name' => 'Shortanswer',
Línea 1025... Línea 1025...
1025
";
1025
";
Línea 1026... Línea 1026...
1026
 
1026
 
1027
        $this->assert_same_gift($expectedgift, $gift);
1027
        $this->assert_same_gift($expectedgift, $gift);
Línea 1028... Línea 1028...
1028
    }
1028
    }
1029
 
1029
 
1030
    public function test_import_truefalse() {
1030
    public function test_import_truefalse(): void {
1031
        $gift = "
1031
        $gift = "
1032
// true/false
1032
// true/false
1033
::Q1:: 42 is the Absolute Answer to everything.{
1033
::Q1:: 42 is the Absolute Answer to everything.{
Línea 1061... Línea 1061...
1061
        );
1061
        );
Línea 1062... Línea 1062...
1062
 
1062
 
1063
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
1063
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
Línea 1064... Línea 1064...
1064
    }
1064
    }
1065
 
1065
 
1066
    public function test_import_truefalse_true_answer1() {
1066
    public function test_import_truefalse_true_answer1(): void {
1067
        $gift = "// name 0-11
1067
        $gift = "// name 0-11
Línea 1068... Línea 1068...
1068
::2-08 TSL::TSL is blablabla.{T}";
1068
::2-08 TSL::TSL is blablabla.{T}";
Línea 1095... Línea 1095...
1095
        );
1095
        );
Línea 1096... Línea 1096...
1096
 
1096
 
1097
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
1097
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
Línea 1098... Línea 1098...
1098
    }
1098
    }
1099
 
1099
 
1100
    public function test_import_truefalse_true_answer2() {
1100
    public function test_import_truefalse_true_answer2(): void {
1101
        $gift = "// name 0-11
1101
        $gift = "// name 0-11
Línea 1102... Línea 1102...
1102
::2-08 TSL::TSL is blablabla.{TRUE}";
1102
::2-08 TSL::TSL is blablabla.{TRUE}";
Línea 1129... Línea 1129...
1129
        );
1129
        );
Línea 1130... Línea 1130...
1130
 
1130
 
1131
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
1131
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
Línea 1132... Línea 1132...
1132
    }
1132
    }
1133
 
1133
 
1134
    public function test_export_truefalse() {
1134
    public function test_export_truefalse(): void {
1135
        $qdata = (object) array(
1135
        $qdata = (object) array(
1136
            'id' => 666 ,
1136
            'id' => 666 ,
1137
            'name' => 'Q1',
1137
            'name' => 'Q1',
Línea 1178... Línea 1178...
1178
";
1178
";
Línea 1179... Línea 1179...
1179
 
1179
 
1180
        $this->assert_same_gift($expectedgift, $gift);
1180
        $this->assert_same_gift($expectedgift, $gift);
Línea 1181... Línea 1181...
1181
    }
1181
    }
1182
 
1182
 
1183
    public function test_export_backslash() {
1183
    public function test_export_backslash(): void {
1184
        // There was a bug (MDL-34171) where \\ was getting exported as \\, not
1184
        // There was a bug (MDL-34171) where \\ was getting exported as \\, not
1185
        // \\\\, and on import, \\ in converted to \.
1185
        // \\\\, and on import, \\ in converted to \.
1186
        // We need \\\\ in the test code, because of PHPs string escaping rules.
1186
        // We need \\\\ in the test code, because of PHPs string escaping rules.
Línea 1213... Línea 1213...
1213
";
1213
";
Línea 1214... Línea 1214...
1214
 
1214
 
1215
        $this->assert_same_gift($expectedgift, $gift);
1215
        $this->assert_same_gift($expectedgift, $gift);
Línea 1216... Línea 1216...
1216
    }
1216
    }
1217
 
1217
 
1218
    public function test_import_backslash() {
1218
    public function test_import_backslash(): void {
1219
        // There was a bug (MDL-34171) where \\ in the import was getting changed
1219
        // There was a bug (MDL-34171) where \\ in the import was getting changed
1220
        // to \. This test checks for that.
1220
        // to \. This test checks for that.
1221
        // We need \\\\ in the test code, because of PHPs string escaping rules.
1221
        // We need \\\\ in the test code, because of PHPs string escaping rules.
Línea 1247... Línea 1247...
1247
        );
1247
        );
Línea 1248... Línea 1248...
1248
 
1248
 
1249
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
1249
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
Línea 1250... Línea 1250...
1250
    }
1250
    }
1251
 
1251
 
1252
    public function test_import_pre_content() {
1252
    public function test_import_pre_content(): void {
1253
        $gift = '
1253
        $gift = '
1254
::Q001::[html]<p>What would running the test method print?</p>
1254
::Q001::[html]<p>What would running the test method print?</p>
1255
<pre>
1255
<pre>
Línea 1292... Línea 1292...
1292
        );
1292
        );
Línea 1293... Línea 1293...
1293
 
1293
 
1294
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
1294
        $this->assert(new question_check_specified_fields_expectation($expectedq), $q);
Línea 1295... Línea 1295...
1295
    }
1295
    }
1296
 
1296
 
1297
    public function test_import_question_with_tags() {
1297
    public function test_import_question_with_tags(): void {
1298
        $gift = '
1298
        $gift = '
1299
// This question is to test importing tags: [tag:tag] [tag:other-tag].
1299
// This question is to test importing tags: [tag:tag] [tag:other-tag].
1300
// And an idnumber: [id:myid].
1300
// And an idnumber: [id:myid].
Línea 1355... Línea 1355...
1355
     * @param string $expectedidnumber the expected idnumber.
1355
     * @param string $expectedidnumber the expected idnumber.
1356
     * @param array $expectedtags the expected tags.
1356
     * @param array $expectedtags the expected tags.
1357
     * @param string $comment the comment to parse.
1357
     * @param string $comment the comment to parse.
1358
     */
1358
     */
1359
    public function test_extract_idnumber_and_tags_from_comment(
1359
    public function test_extract_idnumber_and_tags_from_comment(
1360
            string $expectedidnumber, array $expectedtags, string $comment) {
1360
            string $expectedidnumber, array $expectedtags, string $comment): void {
1361
        $importer = new qformat_gift();
1361
        $importer = new qformat_gift();
Línea 1362... Línea 1362...
1362
 
1362
 
1363
        list($idnumber, $tags) = $importer->extract_idnumber_and_tags_from_comment($comment);
1363
        list($idnumber, $tags) = $importer->extract_idnumber_and_tags_from_comment($comment);
1364
        $this->assertSame($expectedidnumber, $idnumber);
1364
        $this->assertSame($expectedidnumber, $idnumber);
1365
        $this->assertSame($expectedtags, $tags);
1365
        $this->assertSame($expectedtags, $tags);
Línea 1366... Línea 1366...
1366
    }
1366
    }
1367
 
1367
 
Línea 1368... Línea 1368...
1368
    public function test_export_question_with_tags_and_idnumber() {
1368
    public function test_export_question_with_tags_and_idnumber(): void {
1369
        $this->resetAfterTest();
1369
        $this->resetAfterTest();
1370
 
1370