ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilUserCertificateTableProviderTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
10 {
11 $database = $this->getMockBuilder('ilDBInterface')
12 ->disableOriginalConstructor()
13 ->getMock();
14
15 $database
16 ->expects($this->atLeastOnce())
17 ->method('quote');
18
19 $database->method('fetchAssoc')
20 ->willReturnOnConsecutiveCalls(
21 array(
22 'id' => 600,
23 'obj_id' => 100,
24 'title' => 'CourseTest',
25 'obj_type' => 'crs',
26 'acquired_timestamp' => 1539867618,
27 'thumbnail_image_path' => 'some/path/test.svg',
28 'description' => 'some description',
29 'firstname' => 'ilyas',
30 'lastname' => 'homer',
31 ),
32 null
33 );
34
35 $logger = $this->getMockBuilder('ilLogger')
36 ->disableOriginalConstructor()
37 ->getMock();
38
39 $logger
40 ->expects($this->once())
41 ->method('info');
42
43 $controller = $this->getMockBuilder('ilCtrl')
44 ->getMock();
45
46 $controller->method('getLinkTargetByClass')
47 ->willReturn('something');
48
49 $objectMock = $this->getMockBuilder('ilObject')
50 ->disableOriginalConstructor()
51 ->getMock();
52
53 $objectMock->method('getTitle')
54 ->willReturn('CourseTest');
55
56 $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
57 ->disableOriginalConstructor()
58 ->getMock();
59
60 $objectHelper->method('getInstanceByObjId')
61 ->willReturn($objectMock);
62
64 $database,
65 $logger,
66 $controller,
67 'default_title',
68 $objectHelper
69 );
70
71 $dataSet = $provider->fetchDataSet(100, array(), array());
72
73 $expected = array();
74
75 $expected['items'][] = array(
76 'id' => 600,
77 'title' => 'CourseTest',
78 'obj_id' => 100,
79 'obj_type' => 'crs',
80 'date' => 1539867618,
81 'thumbnail_image_path' => 'some/path/test.svg',
82 'description' => 'some description',
83 'firstname' => 'ilyas',
84 'lastname' => 'homer',
85 );
86
87 $expected['cnt'] = 1;
88
89 $this->assertEquals($expected, $dataSet);
90 }
91
93 {
94 $database = $this->getMockBuilder('ilDBInterface')
95 ->disableOriginalConstructor()
96 ->getMock();
97
98 $database
99 ->expects($this->atLeastOnce())
100 ->method('quote');
101
102 $database->method('fetchAssoc')
103 ->willReturnOnConsecutiveCalls(
104 array(
105 'id' => 600,
106 'obj_id' => 100,
107 'title' => 'CourseTest',
108 'obj_type' => 'crs',
109 'acquired_timestamp' => 1539867618,
110 'thumbnail_image_path' => 'some/path/test.svg',
111 'description' => 'some description',
112 'firstname' => 'ilyas',
113 'lastname' => 'homer',
114 ),
115 null,
116 array(
117 'cnt' => 5,
118 ),
119 null
120 );
121
122 $logger = $this->getMockBuilder('ilLogger')
123 ->disableOriginalConstructor()
124 ->getMock();
125
126 $logger
127 ->expects($this->atLeastOnce())
128 ->method('info');
129
130 $controller = $this->getMockBuilder('ilCtrl')
131 ->getMock();
132
133 $controller->method('getLinkTargetByClass')
134 ->willReturn('something');
135
136 $objectMock = $this->getMockBuilder('ilObject')
137 ->disableOriginalConstructor()
138 ->getMock();
139
140 $objectMock->method('getTitle')
141 ->willReturn('CourseTest');
142
143 $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
144 ->disableOriginalConstructor()
145 ->getMock();
146
147 $objectHelper->method('getInstanceByObjId')
148 ->willReturn($objectMock);
149
151 $database,
152 $logger,
153 $controller,
154 'default_title',
155 $objectHelper
156 );
157
158 $dataSet = $provider->fetchDataSet(100, array('limit' => 2), array());
159
160 $expected = array();
161
162 $expected['items'][] = array(
163 'id' => 600,
164 'title' => 'CourseTest',
165 'obj_id' => 100,
166 'obj_type' => 'crs',
167 'date' => 1539867618,
168 'thumbnail_image_path' => 'some/path/test.svg',
169 'description' => 'some description',
170 'firstname' => 'ilyas',
171 'lastname' => 'homer',
172 );
173
174 $expected['cnt'] = 5;
175
176 $this->assertEquals($expected, $dataSet);
177 }
178
180 {
181 $database = $this->getMockBuilder('ilDBInterface')
182 ->disableOriginalConstructor()
183 ->getMock();
184
185 $database
186 ->expects($this->atLeastOnce())
187 ->method('quote');
188
189 $database->method('fetchAssoc')
190 ->willReturnOnConsecutiveCalls(
191 array(
192 'id' => 600,
193 'obj_id' => 100,
194 'title' => 'CourseTest',
195 'obj_type' => 'crs',
196 'acquired_timestamp' => 1539867618,
197 'thumbnail_image_path' => 'some/path/test.svg',
198 'description' => 'some description',
199 'firstname' => 'ilyas',
200 'lastname' => 'homer',
201 ),
202 null,
203 array(
204 'cnt' => 5,
205 ),
206 null
207 );
208
209 $logger = $this->getMockBuilder('ilLogger')
210 ->disableOriginalConstructor()
211 ->getMock();
212
213 $logger
214 ->expects($this->atLeastOnce())
215 ->method('info');
216
217 $controller = $this->getMockBuilder('ilCtrl')
218 ->getMock();
219
220 $controller->method('getLinkTargetByClass')
221 ->willReturn('something');
222
223 $objectMock = $this->getMockBuilder('ilObject')
224 ->disableOriginalConstructor()
225 ->getMock();
226
227 $objectMock->method('getTitle')
228 ->willReturn('CourseTest');
229
230 $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
231 ->disableOriginalConstructor()
232 ->getMock();
233
234 $objectHelper->method('getInstanceByObjId')
235 ->willReturn($objectMock);
236
238 $database,
239 $logger,
240 $controller,
241 'default_title',
242 $objectHelper
243 );
244
245 $dataSet = $provider->fetchDataSet(100, array('limit' => 2, 'order_field' => 'date'), array());
246
247 $expected = array();
248
249 $expected['items'][] = array(
250 'id' => 600,
251 'title' => 'CourseTest',
252 'obj_id' => 100,
253 'obj_type' => 'crs',
254 'date' => 1539867618,
255 'thumbnail_image_path' => 'some/path/test.svg',
256 'description' => 'some description',
257 'firstname' => 'ilyas',
258 'lastname' => 'homer',
259 );
260
261 $expected['cnt'] = 5;
262
263 $this->assertEquals($expected, $dataSet);
264 }
265
270 {
271 $database = $this->getMockBuilder('ilDBInterface')
272 ->disableOriginalConstructor()
273 ->getMock();
274
275 $database
276 ->expects($this->atLeastOnce())
277 ->method('quote');
278
279 $database->method('fetchAssoc')
280 ->willReturnOnConsecutiveCalls(
281 array(
282 'id' => 600,
283 'obj_id' => 100,
284 'title' => 'CourseTest',
285 'obj_type' => 'crs',
286 'acquired_timestamp' => 1539867618
287 ),
288 null,
289 array(
290 'cnt' => 5,
291 ),
292 null
293 );
294
295 $logger = $this->getMockBuilder('ilLogger')
296 ->disableOriginalConstructor()
297 ->getMock();
298
299 $logger
300 ->expects($this->atLeastOnce())
301 ->method('info');
302
303 $controller = $this->getMockBuilder('ilCtrl')
304 ->getMock();
305
306 $controller->method('getLinkTargetByClass')
307 ->willReturn('something');
308
309 $objectMock = $this->getMockBuilder('ilObject')
310 ->disableOriginalConstructor()
311 ->getMock();
312
313 $objectMock->method('getTitle')
314 ->willReturn('CourseTest');
315
316 $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
317 ->disableOriginalConstructor()
318 ->getMock();
319
320 $objectHelper->method('getInstanceByObjId')
321 ->willReturn($objectMock);
322
324 $database,
325 $logger,
326 $controller,
327 'default_title',
328 $objectHelper
329 );
330
331 $dataSet = $provider->fetchDataSet(100, array('limit' => 2, 'order_field' => 'something'), array());
332
333 $this->fail('Should never happen');
334 }
335
340 {
341 $database = $this->getMockBuilder('ilDBInterface')
342 ->disableOriginalConstructor()
343 ->getMock();
344
345 $database
346 ->expects($this->atLeastOnce())
347 ->method('quote');
348
349 $database->method('fetchAssoc')
350 ->willReturnOnConsecutiveCalls(
351 array(
352 'id' => 600,
353 'obj_id' => 100,
354 'title' => 'CourseTest',
355 'obj_type' => 'crs',
356 'acquired_timestamp' => 1539867618
357 ),
358 null,
359 array(
360 'cnt' => 5,
361 ),
362 null
363 );
364
365 $logger = $this->getMockBuilder('ilLogger')
366 ->disableOriginalConstructor()
367 ->getMock();
368
369 $logger
370 ->expects($this->atLeastOnce())
371 ->method('info');
372
373 $controller = $this->getMockBuilder('ilCtrl')
374 ->getMock();
375
376 $controller->method('getLinkTargetByClass')
377 ->willReturn('something');
378
379 $objectMock = $this->getMockBuilder('ilObject')
380 ->disableOriginalConstructor()
381 ->getMock();
382
383 $objectMock->method('getTitle')
384 ->willReturn('CourseTest');
385
386 $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
387 ->disableOriginalConstructor()
388 ->getMock();
389
390 $objectHelper->method('getInstanceByObjId')
391 ->willReturn($objectMock);
392
394 $database,
395 $logger,
396 $controller,
397 'default_title',
398 $objectHelper
399 );
400
401 $dataSet = $provider->fetchDataSet(100, array('limit' => 2, 'order_field' => false), array());
402
403 $this->fail('Should never happen');
404 }
405
410 {
411 $database = $this->getMockBuilder('ilDBInterface')
412 ->disableOriginalConstructor()
413 ->getMock();
414
415 $database
416 ->expects($this->atLeastOnce())
417 ->method('quote');
418
419 $database->method('fetchAssoc')
420 ->willReturnOnConsecutiveCalls(
421 array(
422 'id' => 600,
423 'obj_id' => 100,
424 'title' => 'CourseTest',
425 'obj_type' => 'crs',
426 'acquired_timestamp' => 1539867618
427 ),
428 null,
429 array(
430 'cnt' => 5,
431 ),
432 null
433 );
434
435 $logger = $this->getMockBuilder('ilLogger')
436 ->disableOriginalConstructor()
437 ->getMock();
438
439 $logger
440 ->expects($this->atLeastOnce())
441 ->method('info');
442
443 $controller = $this->getMockBuilder('ilCtrl')
444 ->getMock();
445
446 $controller->method('getLinkTargetByClass')
447 ->willReturn('something');
448
449 $objectMock = $this->getMockBuilder('ilObject')
450 ->disableOriginalConstructor()
451 ->getMock();
452
453 $objectMock->method('getTitle')
454 ->willReturn('CourseTest');
455
456 $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
457 ->disableOriginalConstructor()
458 ->getMock();
459
460 $objectHelper->method('getInstanceByObjId')
461 ->willReturn($objectMock);
462
464 $database,
465 $logger,
466 $controller,
467 'default_title',
468 $objectHelper
469 );
470
471 $dataSet = $provider->fetchDataSet(
472 600,
473 array(
474 'limit' => 2,
475 'order_field' => 'date',
476 'order_direction' => 'mac'
477 ),
478 array()
479 );
480
481 $this->fail('Should never happen');
482 }
483
488 {
489 $database = $this->getMockBuilder('ilDBInterface')
490 ->disableOriginalConstructor()
491 ->getMock();
492
493 $database
494 ->expects($this->atLeastOnce())
495 ->method('quote');
496
497 $database->method('fetchAssoc')
498 ->willReturnOnConsecutiveCalls(
499 array(
500 'id' => 600,
501 'obj_id' => 100,
502 'title' => 'CourseTest',
503 'obj_type' => 'crs',
504 'acquired_timestamp' => 1539867618
505 ),
506 null,
507 array(
508 'cnt' => 5,
509 ),
510 null
511 );
512
513 $logger = $this->getMockBuilder('ilLogger')
514 ->disableOriginalConstructor()
515 ->getMock();
516
517 $logger
518 ->expects($this->atLeastOnce())
519 ->method('info');
520
521 $controller = $this->getMockBuilder('ilCtrl')
522 ->getMock();
523
524 $controller->method('getLinkTargetByClass')
525 ->willReturn('something');
526
527 $objectMock = $this->getMockBuilder('ilObject')
528 ->disableOriginalConstructor()
529 ->getMock();
530
531 $objectMock->method('getTitle')
532 ->willReturn('CourseTest');
533
534 $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
535 ->disableOriginalConstructor()
536 ->getMock();
537
538 $objectHelper->method('getInstanceByObjId')
539 ->willReturn($objectMock);
540
542 $database,
543 $logger,
544 $controller,
545 'default_title',
546 $objectHelper
547 );
548
549 $dataSet = $provider->fetchDataSet(
550 600,
551 array(
552 'limit' => 'something',
553 'order_field' => 'date',
554 'order_direction' => 'mac'
555 ),
556 array()
557 );
558
559 $this->fail('Should never happen');
560 }
561
566 {
567 $database = $this->getMockBuilder('ilDBInterface')
568 ->disableOriginalConstructor()
569 ->getMock();
570
571 $database
572 ->expects($this->atLeastOnce())
573 ->method('quote');
574
575 $database->method('fetchAssoc')
576 ->willReturnOnConsecutiveCalls(
577 array(
578 'id' => 600,
579 'obj_id' => 100,
580 'title' => 'CourseTest',
581 'obj_type' => 'crs',
582 'acquired_timestamp' => 1539867618
583 ),
584 null,
585 array(
586 'cnt' => 5,
587 ),
588 null
589 );
590
591 $logger = $this->getMockBuilder('ilLogger')
592 ->disableOriginalConstructor()
593 ->getMock();
594
595 $logger
596 ->expects($this->atLeastOnce())
597 ->method('info');
598
599 $controller = $this->getMockBuilder('ilCtrl')
600 ->getMock();
601
602 $controller->method('getLinkTargetByClass')
603 ->willReturn('something');
604
605 $objectMock = $this->getMockBuilder('ilObject')
606 ->disableOriginalConstructor()
607 ->getMock();
608
609 $objectMock->method('getTitle')
610 ->willReturn('CourseTest');
611
612 $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
613 ->disableOriginalConstructor()
614 ->getMock();
615
616 $objectHelper->method('getInstanceByObjId')
617 ->willReturn($objectMock);
618
620 $database,
621 $logger,
622 $controller,
623 'default_title',
624 $objectHelper
625 );
626
627 $dataSet = $provider->fetchDataSet(
628 600,
629 array(
630 'limit' => 3,
631 'order_field' => 'date',
632 'order_direction' => 'mac',
633 'offset' => 'something'
634 ),
635 array()
636 );
637
638 $this->fail('Should never happen');
639 }
640}
An exception for terminatinating execution or to throw for unit testing.
testFetchingDataWithInvalidOffsetParameterWillResultInException()
@expectedException InvalidArgumentException
testFetchingDataWithEmptyOrderFieldWillResultInException()
@expectedException InvalidArgumentException
testFetchingDataWithInvalidOrderFieldWillResultInException()
@expectedException InvalidArgumentException
testFetchingDataWithInvalidLimitParameterWillResultInException()
@expectedException InvalidArgumentException
testFetchingDataWithWrongOrderDirectionWillResultInException()
@expectedException InvalidArgumentException
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.