ILIAS  release_7 Revision v7.30-3-g800a261c036
assLongMenuTest.php
Go to the documentation of this file.
1<?php
10{
11 protected $backupGlobals = false;
12
13
14 protected static function getMethod($name)
15 {
16 $class = new ReflectionClass('assLongMenu');
17 $method = $class->getMethod($name);
18 $method->setAccessible(true);
19 return $method;
20 }
21
22 protected function setUp() : void
23 {
24 $GLOBALS['DIC']['ilDB'] = 'test';
25
26 require_once './Modules/TestQuestionPool/classes/class.assLongMenu.php';
27 if (defined('ILIAS_PHPUNIT_CONTEXT')) {
28 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
29 ilUnitUtil::performInitialisation();
30 } else {
31 chdir(dirname(__FILE__));
32 chdir('../../../');
33 }
34 require_once './Services/Utilities/classes/class.ilUtil.php';
35 }
36
38 {
39 $instance = new assLongMenu();
40 $this->assertInstanceOf('assLongMenu', $instance);
41 }
42
44 {
45 $instance = new assLongMenu();
46 $this->assertEquals('qpl_qst_lome', $instance->getAdditionalTableName());
47 }
48
50 {
51 $instance = new assLongMenu();
52 $this->assertEquals('assLongMenu', $instance->getQuestionType());
53 }
54
56 {
57 $instance = new assLongMenu();
58 $this->assertEquals('qpl_a_lome', $instance->getAnswerTableName());
59 }
60
62 {
63 $method = self::getMethod('correctAnswerDoesNotExistInAnswerOptions');
64 $obj = new assLongMenu();
65 $value = $method->invokeArgs($obj, array(array(array(5),1,1), array(1,2,3,4)));
66 $this->assertEquals(true, $value);
67 }
68
70 {
71 $method = self::getMethod('correctAnswerDoesNotExistInAnswerOptions');
72 $obj = new assLongMenu();
73 $value = $method->invokeArgs($obj, array(array(array(1),1,1), array(1,2,3,4)));
74 $this->assertEquals(false, $value);
75 }
76
78 {
79 $obj = new assLongMenu();
80 $obj->setCorrectAnswers(array( 0 => array( 0 => array(0 => 'answer'),1 => '2', 2 => '1'),
81 1 => array( 0 => array(0 => 'answer'),1 => '2', 2 => '1')));
82 $value = $obj->getMaximumPoints();
83 $this->assertEquals(4, $value);
84 }
85
87 {
88 $obj = new assLongMenu();
89 $obj->setCorrectAnswers(array( 0 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1'),
90 1 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1')));
91 $value = $obj->getMaximumPoints();
92 $this->assertEquals(4.5, $value);
93 }
94
96 {
97 $obj = new assLongMenu();
98 $obj->setCorrectAnswers(array( 0 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1'),
99 1 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1')));
100 $obj->setAnswers(array(array(1,2,3,4)));
101 $this->assertEquals($obj->isComplete(), false);
102 }
103
104 /* Removed by @kergomard 17 NOV 2022, we should introduce this again
105 public function test_isComplete_shouldBeTrue()
106 {
107 $obj = new assLongMenu();
108 $obj->setCorrectAnswers(array( 0 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1'),
109 1 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1')));
110 $obj->setAnswers(array(array(1,2,3,4)));
111 $obj->setPoints(4.5);
112 $obj->setTitle('LongMenu Title');
113 $obj->setLongMenuTextValue('LongMenu Question');
114 $this->assertEquals($obj->isComplete(), true);
115 } */
116
118 {
119 $obj = new assLongMenu();
120 $this->assertEquals($obj->checkQuestionCustomPart(), false);
121 }
122
124 {
125 $obj = new assLongMenu();
126 $obj->setAnswers(array(array(1,2,3,4)));
127 $this->assertEquals($obj->checkQuestionCustomPart(), false);
128 }
129
131 {
132 $obj = new assLongMenu();
133 $obj->setCorrectAnswers(array( 0 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1'),
134 1 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1')));
135 $this->assertEquals($obj->checkQuestionCustomPart(), false);
136 }
138 {
139 $obj = new assLongMenu();
140 $obj->setCorrectAnswers(array( 0 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1'),
141 1 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1')));
142 $obj->setAnswers(array(array('answer')));
143 $this->assertEquals($obj->checkQuestionCustomPart(), false);
144 }
146 {
147 $obj = new assLongMenu();
148 $obj->setCorrectAnswers(array( 0 => array( 0 => array(0 => 'answer'),1 => '2.25', 2 => '1')));
149 $obj->setAnswers(array(array(1)));
150 $this->assertEquals($obj->checkQuestionCustomPart(), false);
151 }
152
154 {
155 $obj = new assLongMenu();
156 $obj->setCorrectAnswers(array( 0 => array( 0 => array(),1 => '2.25', 2 => '1')));
157 $obj->setAnswers(array(array('answer')));
158 $this->assertEquals($obj->checkQuestionCustomPart(), false);
159 }
160
162 {
163 $obj = new assLongMenu();
164 $obj->setCorrectAnswers(array( 0 => array( 0 => array())));
165 $obj->setAnswers(array(array('answer')));
166 $this->assertEquals($obj->checkQuestionCustomPart(), false);
167 }
168
170 {
171 $obj = new assLongMenu();
172 $obj->setCorrectAnswers(array( 0 => array( 0 => array('answer'),1 => 0, 2 => '1')));
173 $obj->setAnswers(array(array('answer')));
174 $this->assertEquals($obj->checkQuestionCustomPart(), false);
175 }
176
178 {
179 $obj = new assLongMenu();
180 $obj->setCorrectAnswers(array( 0 => array( 0 => array('answer'),1 => 1, 2 => '1')));
181 $obj->setAnswers(array(array('answer')));
182 $this->assertEquals($obj->checkQuestionCustomPart(), true);
183 }
184
186 {
187 $obj = new assLongMenu();
188 $array = array( 0 => 'squirrel', 1 => 'icebear');
189 $_POST['answer'] = $array;
190 $this->assertEquals($obj->getSolutionSubmit(), $array);
191 }
192
194 {
195 $obj = new assLongMenu();
196 $obj->setAnswerType(0);
197 $this->assertEquals(0, $obj->getAnswerType());
198 }
199
200 /* Removed by @kergomard 17 NOV 2022, we should introduce this again
201 public function test_setLongMenuTextValue_shouldReturnGetLongMenuTextValue()
202 {
203 $obj = new assLongMenu();
204 $this->assertEquals('', $obj->getLongMenuTextValue());
205 $obj->setLongMenuTextValue('dummy text');
206 $this->assertEquals('dummy text', $obj->getLongMenuTextValue());
207 } */
208
210 {
211 $obj = new assLongMenu();
212 $obj->setJsonStructure(json_encode(array(1 => 'bla')));
213 $this->assertEquals('{"1":"bla"}', $obj->getJsonStructure());
214 }
215
217 {
218 $obj = new assLongMenu();
219 $this->assertEquals(false, $obj->isShuffleAnswersEnabled());
220 $this->assertNotEquals(true, $obj->isShuffleAnswersEnabled());
221 }
222}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Class assBaseTestCase.
test_getAdditionalTableName_shouldReturnString()
test_getMaximumPoints_shouldBeFourPointFive()
test_getAnswerTableName_shouldReturnString()
static getMethod($name)
test_isShuffleAnswersEnabled_shouldReturnFalse()
test_checkQuestionCustomPart_shouldBeFalseBecauseToManyCorrectAnswers()
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerHasNoAnswers()
test_setAnswerType_shouldReturnGetAnswerType()
test_getSolutionSubmit_shouldReturnSolution()
test_checkQuestionCustomPart_shouldBeFalseBecauseOnlyCorrectAnswers()
test_instantiateObject_shouldReturnInstance()
test_correctAnswerDoesNotExistInAnswerOptions_shouldReturnTrue()
test_checkQuestionCustomPart_shouldBeFalseBecauseNoCustomPart()
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerPointsAreZero()
test_getMaximumPoints_shouldBeFour()
test_checkQuestionCustomPart_shouldBeFalseBecauseOnlyAnswers()
test_checkQuestionCustomPart_shouldBeTrue()
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerHasNoPoints()
test_getQuestionType_shouldReturnString()
test_correctAnswerDoesNotExistInAnswerOptions_shouldReturnFalse()
test_setJsonStructure_shouldReturnGetJsonStructure()
test_checkQuestionCustomPart_shouldBeFalseBecauseCorrectAnswerDoesNotExistsInAnswers()
if($format !==null) $name
Definition: metadata.php:230