ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilassMarkSchemaTest.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 {
35  protected $backupGlobals = FALSE;
36 
37  protected function setUp()
38  {
39  if (defined('ILIAS_PHPUNIT_CONTEXT'))
40  {
41  include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
42  ilUnitUtil::performInitialisation();
43  }
44  else
45  {
46  chdir( dirname( __FILE__ ) );
47  chdir('../../../');
48  }
49  // Arrange
50  include_once './Modules/Test/classes/class.assMarkSchema.php';
51  $this->ass_mark_schema = new ASS_MarkSchema();
52  }
53 
57  public function testConstructor()
58  {
59  // Arrange
60  $expected = is_array(array());
61 
62  // Act
63  $actual = is_array($this->ass_mark_schema->mark_steps);
64 
65  // Assert
66  $this->assertEquals(
67  $actual,
68  $expected,
69  "Constructor failed, mark_steps not an array."
70  );
71 
72  }
73 
78  {
79  // Arrange
80 
81 
82  $txt_failed_short = "failed";
83  $txt_failed_official = "failed";
84  $percentage_failed = 0;
85  $failed_passed = 0;
86  $txt_passed_short = "passed";
87  $txt_passed_official = "passed";
88  $percentage_passed = 50;
89  $passed_passed = 1;
90 
91  // Act
92  $this->ass_mark_schema->createSimpleSchema();
93  $marks = $this->ass_mark_schema->mark_steps;
94 
95  $failed = $marks[0];
96  $passed = $marks[1];
97 
98  // Assert
99  $this->assertEquals(
100  $failed->getShortName(),
101  $txt_failed_short,
102  'Failed on $txt_failed_short'
103  );
104  $this->assertEquals(
105  $failed->getOfficialName(),
106  $txt_failed_official,
107  'Failed on $txt_failed_official'
108  );
109  $this->assertEquals(
110  $failed->getMinimumLevel(),
111  $percentage_failed,
112  'Failed on $percentage_failed'
113  );
114  $this->assertEquals(
115  $failed->getPassed(),
116  $failed_passed,
117  'Failed on $failed_passed'
118  );
119 
120  $this->assertEquals(
121  $passed->getShortName(),
122  $txt_passed_short,
123  'Failed on $txt_passed_short'
124  );
125  $this->assertEquals(
126  $passed->getOfficialName(),
127  $txt_passed_official,
128  'Failed on $txt_passed_official'
129  );
130  $this->assertEquals(
131  $passed->getMinimumLevel(),
132  $percentage_passed,
133  'Failed on $percetage_passed'
134  );
135  $this->assertEquals(
136  $passed->getPassed(),
137  $passed_passed,
138  'Failed on $passed_passed'
139  );
140 
141  }
142 
147  {
148  // Arrange
149  $txt_failed_short = "failed";
150  $txt_failed_official = "failed";
151  $percentage_failed = 0;
152  $failed_passed = 0;
153  $txt_passed_short = "passed";
154  $txt_passed_official = "passed";
155  $percentage_passed = 50;
156  $passed_passed = 1;
157 
158  // Act
159  $this->ass_mark_schema->createSimpleSchema(
160  $txt_failed_short,
161  $txt_failed_official,
162  $percentage_failed,
163  $failed_passed,
164  $txt_passed_short,
165  $txt_passed_official,
166  $percentage_passed,
167  $passed_passed
168  );
169 
170  $marks = $this->ass_mark_schema->mark_steps;
171 
172  $failed = $marks[0];
173  $passed = $marks[1];
174 
175  // Assert
176  $this->assertEquals(
177  $failed->getShortName(),
178  $txt_failed_short,
179  'Failed on $txt_failed_short'
180  );
181  $this->assertEquals(
182  $failed->getOfficialName(),
183  $txt_failed_official,
184  'Failed on $txt_failed_official'
185  );
186  $this->assertEquals(
187  $failed->getMinimumLevel(),
188  $percentage_failed,
189  'Failed on $percentage_failed'
190  );
191  $this->assertEquals(
192  $failed->getPassed(),
193  $failed_passed,
194  'Failed on $failed_passed'
195  );
196 
197  $this->assertEquals(
198  $passed->getShortName(),
199  $txt_passed_short,
200  'Failed on $txt_passed_short'
201  );
202  $this->assertEquals(
203  $passed->getOfficialName(),
204  $txt_passed_official,
205  'Failed on $txt_passed_official'
206  );
207  $this->assertEquals(
208  $passed->getMinimumLevel(),
209  $percentage_passed,
210  'Failed on $percetage_passed'
211  );
212  $this->assertEquals(
213  $passed->getPassed(),
214  $passed_passed,
215  'Failed on $passed_passed'
216  );
217  }
218 
222  public function testFlush()
223  {
224  // Arrange
225  $expected = is_array(array());
226  $this->ass_mark_schema->mark_steps = "a string";
227  $this->assertEquals($this->ass_mark_schema->mark_steps, "a string");
228  $this->ass_mark_schema->flush();
229 
230  // Act
231  $actual = is_array($this->ass_mark_schema->mark_steps);
232 
233  // Assert
234  $this->assertEquals(
235  $actual,
236  $expected,
237  "Method failed, mark_steps not an array."
238  );
239 
240  }
241 
245  public function testAddMarkStep()
246  {
247  // Arrange
248  $this->ass_mark_schema->flush();
249  $txt_short = "";
250  $txt_official = "";
251  $percentage = 0;
252  $passed = 0;
253 
254  // Act
255  $this->ass_mark_schema->addMarkStep();
256  $mark_schema = $this->ass_mark_schema->mark_steps;
257  $mark_step = $mark_schema[0];
258 
259  // Assert
260  $this->assertEquals(
261  $mark_step->getShortName(),
262  $txt_short,
263  'Failed on $txt_failed_short'
264  );
265  $this->assertEquals(
266  $mark_step->getOfficialName(),
267  $txt_official,
268  'Failed on $txt_failed_official'
269  );
270  $this->assertEquals(
271  $mark_step->getMinimumLevel(),
272  $percentage,
273  'Failed on $percentage_failed'
274  );
275  $this->assertEquals(
276  $mark_step->getPassed(),
277  $passed,
278  'Failed on $failed_passed'
279  );
280  }
281 
283  {
284  /*
285  // Arrange
286  require_once 'Services/Database/classes/class.ilDB.php';
287  $ildb_stub = $this->getMock('ilDB');
288 
289  $ildb_stub->expects($this->any())
290  ->method('query')
291  ->will($this->returnValue('foo'));
292 
293  $ildb_stub->expects($this->any())
294  ->method('numRows')
295  ->will($this->returnValue(1));
296 
297  $db_result_1 = array('cmi_node_id' => 8);
298  $db_result_2 = array('cmi_node_id' => 10);
299  $db_result_3 = array('cmi_node_id' => 12);
300  $db_result_4 = array('cmi_node_id' => 14);
301 
302  $ildb_stub->expects($this->any())
303  ->method('fetchAssoc')
304  ->will($this->onConsecutiveCalls($db_result_1, $db_result_2, $db_result_3, $db_result_4));
305  */
306  }
307 }