ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilassMarkSchemaTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4use PHPUnit\Framework\TestCase;
5
15class ilassMarkSchemaTest extends TestCase
16{
17 protected $backupGlobals = false;
18
19 protected function setUp() : void
20 {
21 if (defined('ILIAS_PHPUNIT_CONTEXT')) {
22 include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
23 ilUnitUtil::performInitialisation();
24 } else {
25 chdir(dirname(__FILE__));
26 chdir('../../../');
27 }
28 // Arrange
29 include_once './Modules/Test/classes/class.assMarkSchema.php';
30 $this->ass_mark_schema = new ASS_MarkSchema();
31 }
32
36 public function testConstructor()
37 {
38 // Arrange
39 $expected = is_array(array());
40
41 // Act
42 $actual = is_array($this->ass_mark_schema->mark_steps);
43
44 // Assert
45 $this->assertEquals(
46 $actual,
47 $expected,
48 "Constructor failed, mark_steps not an array."
49 );
50 }
51
56 {
57 // Arrange
58
59
60 $txt_failed_short = "failed";
61 $txt_failed_official = "failed";
62 $percentage_failed = 0;
63 $failed_passed = 0;
64 $txt_passed_short = "passed";
65 $txt_passed_official = "passed";
66 $percentage_passed = 50;
67 $passed_passed = 1;
68
69 // Act
70 $this->ass_mark_schema->createSimpleSchema();
71 $marks = $this->ass_mark_schema->mark_steps;
72
73 $failed = $marks[0];
74 $passed = $marks[1];
75
76 // Assert
77 $this->assertEquals(
78 $failed->getShortName(),
79 $txt_failed_short,
80 'Failed on $txt_failed_short'
81 );
82 $this->assertEquals(
83 $failed->getOfficialName(),
84 $txt_failed_official,
85 'Failed on $txt_failed_official'
86 );
87 $this->assertEquals(
88 $failed->getMinimumLevel(),
89 $percentage_failed,
90 'Failed on $percentage_failed'
91 );
92 $this->assertEquals(
93 $failed->getPassed(),
94 $failed_passed,
95 'Failed on $failed_passed'
96 );
97
98 $this->assertEquals(
99 $passed->getShortName(),
100 $txt_passed_short,
101 'Failed on $txt_passed_short'
102 );
103 $this->assertEquals(
104 $passed->getOfficialName(),
105 $txt_passed_official,
106 'Failed on $txt_passed_official'
107 );
108 $this->assertEquals(
109 $passed->getMinimumLevel(),
110 $percentage_passed,
111 'Failed on $percetage_passed'
112 );
113 $this->assertEquals(
114 $passed->getPassed(),
115 $passed_passed,
116 'Failed on $passed_passed'
117 );
118 }
119
124 {
125 // Arrange
126 $txt_failed_short = "failed";
127 $txt_failed_official = "failed";
128 $percentage_failed = 0;
129 $failed_passed = 0;
130 $txt_passed_short = "passed";
131 $txt_passed_official = "passed";
132 $percentage_passed = 50;
133 $passed_passed = 1;
134
135 // Act
136 $this->ass_mark_schema->createSimpleSchema(
137 $txt_failed_short,
138 $txt_failed_official,
139 $percentage_failed,
140 $failed_passed,
141 $txt_passed_short,
142 $txt_passed_official,
143 $percentage_passed,
144 $passed_passed
145 );
146
147 $marks = $this->ass_mark_schema->mark_steps;
148
149 $failed = $marks[0];
150 $passed = $marks[1];
151
152 // Assert
153 $this->assertEquals(
154 $failed->getShortName(),
155 $txt_failed_short,
156 'Failed on $txt_failed_short'
157 );
158 $this->assertEquals(
159 $failed->getOfficialName(),
160 $txt_failed_official,
161 'Failed on $txt_failed_official'
162 );
163 $this->assertEquals(
164 $failed->getMinimumLevel(),
165 $percentage_failed,
166 'Failed on $percentage_failed'
167 );
168 $this->assertEquals(
169 $failed->getPassed(),
170 $failed_passed,
171 'Failed on $failed_passed'
172 );
173
174 $this->assertEquals(
175 $passed->getShortName(),
176 $txt_passed_short,
177 'Failed on $txt_passed_short'
178 );
179 $this->assertEquals(
180 $passed->getOfficialName(),
181 $txt_passed_official,
182 'Failed on $txt_passed_official'
183 );
184 $this->assertEquals(
185 $passed->getMinimumLevel(),
186 $percentage_passed,
187 'Failed on $percetage_passed'
188 );
189 $this->assertEquals(
190 $passed->getPassed(),
191 $passed_passed,
192 'Failed on $passed_passed'
193 );
194 }
195
199 public function testFlush()
200 {
201 // Arrange
202 $expected = is_array(array());
203 $this->ass_mark_schema->mark_steps = "a string";
204 $this->assertEquals($this->ass_mark_schema->mark_steps, "a string");
205 $this->ass_mark_schema->flush();
206
207 // Act
208 $actual = is_array($this->ass_mark_schema->mark_steps);
209
210 // Assert
211 $this->assertEquals(
212 $actual,
213 $expected,
214 "Method failed, mark_steps not an array."
215 );
216 }
217
221 public function testAddMarkStep()
222 {
223 // Arrange
224 $this->ass_mark_schema->flush();
225 $txt_short = "";
226 $txt_official = "";
227 $percentage = 0;
228 $passed = 0;
229
230 // Act
231 $this->ass_mark_schema->addMarkStep();
232 $mark_schema = $this->ass_mark_schema->mark_steps;
233 $mark_step = $mark_schema[0];
234
235 // Assert
236 $this->assertEquals(
237 $mark_step->getShortName(),
238 $txt_short,
239 'Failed on $txt_failed_short'
240 );
241 $this->assertEquals(
242 $mark_step->getOfficialName(),
243 $txt_official,
244 'Failed on $txt_failed_official'
245 );
246 $this->assertEquals(
247 $mark_step->getMinimumLevel(),
248 $percentage,
249 'Failed on $percentage_failed'
250 );
251 $this->assertEquals(
252 $mark_step->getPassed(),
253 $passed,
254 'Failed on $failed_passed'
255 );
256 }
257
261 public function testSaveToDb_regular()
262 {
263 /*
264 // Arrange
265 $ildb_stub = $this->createMock('ilDBInterface');
266
267 $ildb_stub->expects($this->any())
268 ->method('query')
269 ->will($this->returnValue('foo'));
270
271 $ildb_stub->expects($this->any())
272 ->method('numRows')
273 ->will($this->returnValue(1));
274
275 $db_result_1 = array('cmi_node_id' => 8);
276 $db_result_2 = array('cmi_node_id' => 10);
277 $db_result_3 = array('cmi_node_id' => 12);
278 $db_result_4 = array('cmi_node_id' => 14);
279
280 $ildb_stub->expects($this->any())
281 ->method('fetchAssoc')
282 ->will($this->onConsecutiveCalls($db_result_1, $db_result_2, $db_result_3, $db_result_4));
283 */
284 }
285}
$failed
Definition: Utf8Test.php:85
A class defining mark schemas for assessment test objects.
An exception for terminatinating execution or to throw for unit testing.
Unit tests for single choice questions.
testCreateSimpleSchemaDefaults()
Test for createSimpleSchema using defaults.
testSaveToDb_regular()
@doesNotPerformAssertions
testCreateSimpleSchemaCustom()
Test for createSimpleSchema using custom values.
testFlush()
Test for flush()
testAddMarkStep()
Test for addMarkStep()
testConstructor()
Test constructor.