MDL-40992 quiz: let students to redo questions within an attempt
[moodle.git] / question / engine / tests / questionengine_test.php
CommitLineData
603bd001
PS
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 * This file contains tests for the question_engine class.
19 *
20 * @package moodlecore
21 * @subpackage questionengine
22 * @copyright 2009 The Open University
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26
27defined('MOODLE_INTERNAL') || die();
28
29global $CFG;
30require_once(dirname(__FILE__) . '/../lib.php');
31
32
33/**
34 *Unit tests for the question_engine class.
35 *
36 * @copyright 2009 The Open University
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 */
39class question_engine_test extends advanced_testcase {
40
41 public function test_load_behaviour_class() {
42 // Exercise SUT
43 question_engine::load_behaviour_class('deferredfeedback');
44 // Verify
45 $this->assertTrue(class_exists('qbehaviour_deferredfeedback'));
46 }
47
48 public function test_load_behaviour_class_missing() {
49 // Set expectation.
50 $this->setExpectedException('moodle_exception');
51 // Exercise SUT
52 question_engine::load_behaviour_class('nonexistantbehaviour');
53 }
54
55 public function test_get_behaviour_unused_display_options() {
56 $this->assertEquals(array(), question_engine::get_behaviour_unused_display_options('interactive'));
57 $this->assertEquals(array('correctness', 'marks', 'specificfeedback', 'generalfeedback', 'rightanswer'),
58 question_engine::get_behaviour_unused_display_options('deferredfeedback'));
59 $this->assertEquals(array('correctness', 'marks', 'specificfeedback', 'generalfeedback', 'rightanswer'),
60 question_engine::get_behaviour_unused_display_options('deferredcbm'));
61 $this->assertEquals(array('correctness', 'marks', 'specificfeedback', 'generalfeedback', 'rightanswer'),
62 question_engine::get_behaviour_unused_display_options('manualgraded'));
63 }
64
65 public function test_sort_behaviours() {
66 $in = array('b1' => 'Behave 1', 'b2' => 'Behave 2', 'b3' => 'Behave 3', 'b4' => 'Behave 4', 'b5' => 'Behave 5', 'b6' => 'Behave 6');
67
68 $out = array('b1' => 'Behave 1', 'b2' => 'Behave 2', 'b3' => 'Behave 3', 'b4' => 'Behave 4', 'b5' => 'Behave 5', 'b6' => 'Behave 6');
69 $this->assertSame($out, question_engine::sort_behaviours($in, '', '', ''));
70
71 $this->assertSame($out, question_engine::sort_behaviours($in, '', 'b4', 'b4'));
72
73 $out = array('b4' => 'Behave 4', 'b5' => 'Behave 5', 'b6' => 'Behave 6');
74 $this->assertSame($out, question_engine::sort_behaviours($in, '', 'b1,b2,b3,b4', 'b4'));
75
76 $out = array('b6' => 'Behave 6', 'b1' => 'Behave 1', 'b4' => 'Behave 4');
77 $this->assertSame($out, question_engine::sort_behaviours($in, 'b6,b1,b4', 'b2,b3,b4,b5', 'b4'));
78
79 $out = array('b6' => 'Behave 6', 'b5' => 'Behave 5', 'b4' => 'Behave 4');
80 $this->assertSame($out, question_engine::sort_behaviours($in, 'b6,b5,b4', 'b1,b2,b3', 'b4'));
81
82 $out = array('b6' => 'Behave 6', 'b5' => 'Behave 5', 'b4' => 'Behave 4');
83 $this->assertSame($out, question_engine::sort_behaviours($in, 'b1,b6,b5', 'b1,b2,b3,b4', 'b4'));
84
85 $out = array('b2' => 'Behave 2', 'b4' => 'Behave 4', 'b6' => 'Behave 6');
86 $this->assertSame($out, question_engine::sort_behaviours($in, 'b2,b4,b6', 'b1,b3,b5', 'b2'));
87
88 // Ignore unknown input in the order argument.
89 $this->assertSame($in, question_engine::sort_behaviours($in, 'unknown', '', ''));
90
91 // Ignore unknown input in the disabled argument.
92 $this->assertSame($in, question_engine::sort_behaviours($in, '', 'unknown', ''));
93 }
94}