Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Unit tests for the Moodle Aiken format. 19 * 20 * @package qformat_aiken 21 * @copyright 2018 Eric Merrill (eric.a.merrill@gmail.com) 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 global $CFG; 29 require_once($CFG->libdir . '/questionlib.php'); 30 require_once($CFG->dirroot . '/question/format.php'); 31 require_once($CFG->dirroot . '/question/format/aiken/format.php'); 32 require_once($CFG->dirroot . '/question/engine/tests/helpers.php'); 33 34 35 /** 36 * Unit tests for the matching question definition class. 37 * 38 * @copyright 2018 Eric Merrill (eric.a.merrill@gmail.com) 39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 40 */ 41 class aikenformat_test extends question_testcase { 42 public function test_readquestions() { 43 global $CFG; 44 45 $lines = file($CFG->dirroot.'/question/format/aiken/tests/fixtures/aiken_errors.txt'); 46 $importer = new qformat_aiken($lines); 47 48 // The importer echos some errors, so we need to capture and check that. 49 ob_start(); 50 $questions = $importer->readquestions($lines); 51 $output = ob_get_contents(); 52 ob_end_clean(); 53 54 // Check that there were some expected errors. 55 $this->assertStringContainsString('Error importing question A question with too few answers', $output); 56 $this->assertStringContainsString('Question must have at least 2 answers on line 3', $output); 57 $this->assertStringContainsString('Question not started on line 5', $output); 58 $this->assertStringContainsString('Question not started on line 7', $output); 59 $this->assertStringContainsString('Error importing question A question started but not finished', $output); 60 $this->assertStringContainsString('Question not completed before next question start on line 18', $output); 61 62 // There are two expected questions. 63 $this->assertCount(2, $questions); 64 65 $q1 = null; 66 $q2 = null; 67 foreach ($questions as $question) { 68 if ($question->name === 'A good question') { 69 $q1 = $question; 70 } else if ($question->name === 'A second good question') { 71 $q2 = $question; 72 } 73 } 74 75 // Check the first good question. 76 $this->assertCount(2, $q1->answer); 77 $this->assertEquals(1, $q1->fraction[0]); 78 $this->assertEquals('Correct', $q1->answer[0]['text']); 79 $this->assertEquals('Incorrect', $q1->answer[1]['text']); 80 81 // Check the second good question. 82 $this->assertCount(2, $q2->answer); 83 $this->assertEquals(1, $q2->fraction[1]); 84 $this->assertEquals('Incorrect (No space)', $q2->answer[0]['text']); 85 $this->assertEquals('Correct (No space)', $q2->answer[1]['text']); 86 } 87 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body