ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilCertificateCronTest.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 {
9  public function testGetTitle()
10  {
11  $queueRepository = $this->getMockBuilder('ilCertificateQueueRepository')
12  ->disableOriginalConstructor()
13  ->getMock();
14 
15  $templateRepository = $this->getMockBuilder('ilCertificateTemplateRepository')
16  ->disableOriginalConstructor()
17  ->getMock();
18 
19  $userRepository = $this->getMockBuilder('ilUserCertificateRepository')
20  ->disableOriginalConstructor()
21  ->getMock();
22 
23  $valueReplacement = $this->getMockBuilder('ilCertificateValueReplacement')
24  ->disableOriginalConstructor()
25  ->getMock();
26 
27  $logger = $this->getMockBuilder('ilLogger')
28  ->disableOriginalConstructor()
29  ->getMock();
30 
31  $languageMock = $this->getMockBuilder('ilLanguage')
32  ->disableOriginalConstructor()
33  ->getMock();
34 
35  $languageMock
36  ->expects($this->atLeastOnce())
37  ->method('txt')
38  ->willReturn('SomeTitle');
39 
40  $dic = $this->getMockBuilder('\ILIAS\DI\Container')
41  ->disableOriginalConstructor()
42  ->getMock();
43 
44  $dic->method('language')
45  ->willReturn($languageMock);
46 
47  $configValues = array('lng');
48 
49  $dic->expects($this->any())
50  ->method('offsetGet')
51  ->will($this->returnCallback(
52  function ($key) use ($configValues) {
53  return $configValues[$key];
54  }
55  ));
56 
57  $dic['lng'] = $languageMock;
58 
60  $queueRepository,
61  $templateRepository,
62  $userRepository,
63  $valueReplacement,
64  $logger,
65  $dic,
66  $languageMock
67  );
68 
69  $title = $cron->getTitle();
70 
71  $this->assertEquals('SomeTitle', $title);
72  }
73 
74  public function testGetDescription()
75  {
76  $queueRepository = $this->getMockBuilder('ilCertificateQueueRepository')
77  ->disableOriginalConstructor()
78  ->getMock();
79 
80  $templateRepository = $this->getMockBuilder('ilCertificateTemplateRepository')
81  ->disableOriginalConstructor()
82  ->getMock();
83 
84  $userRepository = $this->getMockBuilder('ilUserCertificateRepository')
85  ->disableOriginalConstructor()
86  ->getMock();
87 
88  $valueReplacement = $this->getMockBuilder('ilCertificateValueReplacement')
89  ->disableOriginalConstructor()
90  ->getMock();
91 
92  $logger = $this->getMockBuilder('ilLogger')
93  ->disableOriginalConstructor()
94  ->getMock();
95 
96  $languageMock = $this->getMockBuilder('ilLanguage')
97  ->disableOriginalConstructor()
98  ->getMock();
99 
100  $languageMock
101  ->expects($this->atLeastOnce())
102  ->method('txt')
103  ->willReturn('SomeDescription');
104 
105  $dic = $this->getMockBuilder('\ILIAS\DI\Container')
106  ->disableOriginalConstructor()
107  ->getMock();
108 
109  $dic->method('language')
110  ->willReturn($languageMock);
111 
112  $configValues = array('lng');
113 
114  $dic->expects($this->any())
115  ->method('offsetGet')
116  ->will($this->returnCallback(
117  function ($key) use ($configValues) {
118  return $configValues[$key];
119  }
120  ));
121 
122  $dic['lng'] = $languageMock;
123 
124  $cron = new ilCertificateCron(
125  $queueRepository,
126  $templateRepository,
127  $userRepository,
128  $valueReplacement,
129  $logger,
130  $dic,
131  $languageMock
132  );
133 
134  $title = $cron->getDescription();
135 
136  $this->assertEquals('SomeDescription', $title);
137  }
138 
139  public function testGetId()
140  {
141  $database = $this->getMockBuilder('ilDBInterface')
142  ->disableOriginalConstructor()
143  ->getMock();
144 
145  $queueRepository = $this->getMockBuilder('ilCertificateQueueRepository')
146  ->disableOriginalConstructor()
147  ->getMock();
148 
149  $templateRepository = $this->getMockBuilder('ilCertificateTemplateRepository')
150  ->disableOriginalConstructor()
151  ->getMock();
152 
153  $userRepository = $this->getMockBuilder('ilUserCertificateRepository')
154  ->disableOriginalConstructor()
155  ->getMock();
156 
157  $valueReplacement = $this->getMockBuilder('ilCertificateValueReplacement')
158  ->disableOriginalConstructor()
159  ->getMock();
160 
161  $logger = $this->getMockBuilder('ilLogger')
162  ->disableOriginalConstructor()
163  ->getMock();
164 
165  $languageMock = $this->getMockBuilder('ilLanguage')
166  ->disableOriginalConstructor()
167  ->getMock();
168 
169  $dic = $this->getMockBuilder('\ILIAS\DI\Container')
170  ->disableOriginalConstructor()
171  ->getMock();
172 
173  $dic->method('language')
174  ->willReturn($languageMock);
175 
176  $dic->method('database')
177  ->willReturn($database);
178 
179  $configValues = array('lng');
180 
181  $dic->expects($this->any())
182  ->method('offsetGet')
183  ->will($this->returnCallback(
184  function ($key) use ($configValues) {
185  return $configValues[$key];
186  }
187  ));
188 
189  $dic['lng'] = $languageMock;
190 
191  $objectMock = $this->getMockBuilder('ilObject')
192  ->disableOriginalConstructor()
193  ->getMock();
194 
195  $userMock = $this->getMockBuilder('ilObjUser')
196  ->disableOriginalConstructor()
197  ->getMock();
198 
199  $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
200  ->disableOriginalConstructor()
201  ->getMock();
202 
203  $objectHelper->method('getInstanceByObjId')
204  ->willReturnOnConsecutiveCalls(
205  $objectMock,
206  $userMock
207  );
208 
209  $cron = new ilCertificateCron(
210  $queueRepository,
211  $templateRepository,
212  $userRepository,
213  $valueReplacement,
214  $logger,
215  $dic,
216  $languageMock,
217  $objectHelper
218  );
219 
220  $id = $cron->getId();
221 
222  $this->assertEquals('certificate', $id);
223  }
224 
225  public function testActivation()
226  {
227  $database = $this->getMockBuilder('ilDBInterface')
228  ->disableOriginalConstructor()
229  ->getMock();
230 
231  $queueRepository = $this->getMockBuilder('ilCertificateQueueRepository')
232  ->disableOriginalConstructor()
233  ->getMock();
234 
235  $templateRepository = $this->getMockBuilder('ilCertificateTemplateRepository')
236  ->disableOriginalConstructor()
237  ->getMock();
238 
239  $userRepository = $this->getMockBuilder('ilUserCertificateRepository')
240  ->disableOriginalConstructor()
241  ->getMock();
242 
243  $valueReplacement = $this->getMockBuilder('ilCertificateValueReplacement')
244  ->disableOriginalConstructor()
245  ->getMock();
246 
247  $logger = $this->getMockBuilder('ilLogger')
248  ->disableOriginalConstructor()
249  ->getMock();
250 
251  $languageMock = $this->getMockBuilder('ilLanguage')
252  ->disableOriginalConstructor()
253  ->getMock();
254 
255  $dic = $this->getMockBuilder('\ILIAS\DI\Container')
256  ->disableOriginalConstructor()
257  ->getMock();
258 
259  $dic->method('language')
260  ->willReturn($languageMock);
261 
262  $dic->method('database')
263  ->willReturn($database);
264 
265  $configValues = array('lng');
266 
267  $dic->expects($this->any())
268  ->method('offsetGet')
269  ->will($this->returnCallback(
270  function ($key) use ($configValues) {
271  return $configValues[$key];
272  }
273  ));
274 
275  $dic['lng'] = $languageMock;
276 
277  $objectMock = $this->getMockBuilder('ilObject')
278  ->disableOriginalConstructor()
279  ->getMock();
280 
281  $userMock = $this->getMockBuilder('ilObjUser')
282  ->disableOriginalConstructor()
283  ->getMock();
284 
285  $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
286  ->disableOriginalConstructor()
287  ->getMock();
288 
289  $objectHelper->method('getInstanceByObjId')
290  ->willReturnOnConsecutiveCalls(
291  $objectMock,
292  $userMock
293  );
294 
295  $cron = new ilCertificateCron(
296  $queueRepository,
297  $templateRepository,
298  $userRepository,
299  $valueReplacement,
300  $logger,
301  $dic,
302  $languageMock,
303  $objectHelper
304  );
305 
306  $activation = $cron->hasAutoActivation();
307 
308  $this->assertTrue($activation);
309  }
310 
311  public function testFlexibleActivation()
312  {
313  $database = $this->getMockBuilder('ilDBInterface')
314  ->disableOriginalConstructor()
315  ->getMock();
316 
317  $queueRepository = $this->getMockBuilder('ilCertificateQueueRepository')
318  ->disableOriginalConstructor()
319  ->getMock();
320 
321  $templateRepository = $this->getMockBuilder('ilCertificateTemplateRepository')
322  ->disableOriginalConstructor()
323  ->getMock();
324 
325  $userRepository = $this->getMockBuilder('ilUserCertificateRepository')
326  ->disableOriginalConstructor()
327  ->getMock();
328 
329  $valueReplacement = $this->getMockBuilder('ilCertificateValueReplacement')
330  ->disableOriginalConstructor()
331  ->getMock();
332 
333  $logger = $this->getMockBuilder('ilLogger')
334  ->disableOriginalConstructor()
335  ->getMock();
336 
337  $languageMock = $this->getMockBuilder('ilLanguage')
338  ->disableOriginalConstructor()
339  ->getMock();
340 
341  $dic = $this->getMockBuilder('\ILIAS\DI\Container')
342  ->disableOriginalConstructor()
343  ->getMock();
344 
345  $dic->method('language')
346  ->willReturn($languageMock);
347 
348  $dic->method('database')
349  ->willReturn($database);
350 
351  $configValues = array('lng');
352 
353  $dic->expects($this->any())
354  ->method('offsetGet')
355  ->will($this->returnCallback(
356  function ($key) use ($configValues) {
357  return $configValues[$key];
358  }
359  ));
360 
361  $dic['lng'] = $languageMock;
362 
363  $objectMock = $this->getMockBuilder('ilObject')
364  ->disableOriginalConstructor()
365  ->getMock();
366 
367  $userMock = $this->getMockBuilder('ilObjUser')
368  ->disableOriginalConstructor()
369  ->getMock();
370 
371  $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
372  ->disableOriginalConstructor()
373  ->getMock();
374 
375  $objectHelper->method('getInstanceByObjId')
376  ->willReturnOnConsecutiveCalls(
377  $objectMock,
378  $userMock
379  );
380 
381  $cron = new ilCertificateCron(
382  $queueRepository,
383  $templateRepository,
384  $userRepository,
385  $valueReplacement,
386  $logger,
387  $dic,
388  $languageMock,
389  $objectHelper
390  );
391 
392  $flexibleSchedule = $cron->hasFlexibleSchedule();
393 
394  $this->assertTrue($flexibleSchedule);
395  }
396 
397  public function testGetDefaultScheduleType()
398  {
399  $database = $this->getMockBuilder('ilDBInterface')
400  ->disableOriginalConstructor()
401  ->getMock();
402 
403  $queueRepository = $this->getMockBuilder('ilCertificateQueueRepository')
404  ->disableOriginalConstructor()
405  ->getMock();
406 
407  $templateRepository = $this->getMockBuilder('ilCertificateTemplateRepository')
408  ->disableOriginalConstructor()
409  ->getMock();
410 
411  $userRepository = $this->getMockBuilder('ilUserCertificateRepository')
412  ->disableOriginalConstructor()
413  ->getMock();
414 
415  $valueReplacement = $this->getMockBuilder('ilCertificateValueReplacement')
416  ->disableOriginalConstructor()
417  ->getMock();
418 
419  $logger = $this->getMockBuilder('ilLogger')
420  ->disableOriginalConstructor()
421  ->getMock();
422 
423  $languageMock = $this->getMockBuilder('ilLanguage')
424  ->disableOriginalConstructor()
425  ->getMock();
426 
427  $dic = $this->getMockBuilder('\ILIAS\DI\Container')
428  ->disableOriginalConstructor()
429  ->getMock();
430 
431  $dic->method('language')
432  ->willReturn($languageMock);
433 
434  $dic->method('database')
435  ->willReturn($database);
436 
437  $configValues = array('lng');
438 
439  $dic->expects($this->any())
440  ->method('offsetGet')
441  ->will($this->returnCallback(
442  function ($key) use ($configValues) {
443  return $configValues[$key];
444  }
445  ));
446 
447  $dic['lng'] = $languageMock;
448 
449  $objectMock = $this->getMockBuilder('ilObject')
450  ->disableOriginalConstructor()
451  ->getMock();
452 
453  $userMock = $this->getMockBuilder('ilObjUser')
454  ->disableOriginalConstructor()
455  ->getMock();
456 
457  $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
458  ->disableOriginalConstructor()
459  ->getMock();
460 
461  $objectHelper->method('getInstanceByObjId')
462  ->willReturnOnConsecutiveCalls(
463  $objectMock,
464  $userMock
465  );
466 
467  $cron = new ilCertificateCron(
468  $queueRepository,
469  $templateRepository,
470  $userRepository,
471  $valueReplacement,
472  $logger,
473  $dic,
474  $languageMock,
475  $objectHelper
476  );
477 
478  $flexibleSchedule = $cron->getDefaultScheduleType();
479 
480  $this->assertEquals(2, $flexibleSchedule);
481  }
482 
483  public function testGetDefaultScheduleValue()
484  {
485  $database = $this->getMockBuilder('ilDBInterface')
486  ->disableOriginalConstructor()
487  ->getMock();
488 
489  $queueRepository = $this->getMockBuilder('ilCertificateQueueRepository')
490  ->disableOriginalConstructor()
491  ->getMock();
492 
493  $templateRepository = $this->getMockBuilder('ilCertificateTemplateRepository')
494  ->disableOriginalConstructor()
495  ->getMock();
496 
497  $userRepository = $this->getMockBuilder('ilUserCertificateRepository')
498  ->disableOriginalConstructor()
499  ->getMock();
500 
501  $valueReplacement = $this->getMockBuilder('ilCertificateValueReplacement')
502  ->disableOriginalConstructor()
503  ->getMock();
504 
505  $logger = $this->getMockBuilder('ilLogger')
506  ->disableOriginalConstructor()
507  ->getMock();
508 
509  $languageMock = $this->getMockBuilder('ilLanguage')
510  ->disableOriginalConstructor()
511  ->getMock();
512 
513  $dic = $this->getMockBuilder('\ILIAS\DI\Container')
514  ->disableOriginalConstructor()
515  ->getMock();
516 
517  $dic->method('language')
518  ->willReturn($languageMock);
519 
520  $dic->method('database')
521  ->willReturn($database);
522 
523  $configValues = array('lng');
524 
525  $dic->expects($this->any())
526  ->method('offsetGet')
527  ->will($this->returnCallback(
528  function ($key) use ($configValues) {
529  return $configValues[$key];
530  }
531  ));
532 
533  $dic['lng'] = $languageMock;
534 
535  $objectMock = $this->getMockBuilder('ilObject')
536  ->disableOriginalConstructor()
537  ->getMock();
538 
539  $userMock = $this->getMockBuilder('ilObjUser')
540  ->disableOriginalConstructor()
541  ->getMock();
542 
543  $objectHelper = $this->getMockBuilder('ilCertificateObjectHelper')
544  ->disableOriginalConstructor()
545  ->getMock();
546 
547  $objectHelper->method('getInstanceByObjId')
548  ->willReturnOnConsecutiveCalls(
549  $objectMock,
550  $userMock
551  );
552 
553  $cron = new ilCertificateCron(
554  $queueRepository,
555  $templateRepository,
556  $userRepository,
557  $valueReplacement,
558  $logger,
559  $dic,
560  $languageMock,
561  $objectHelper
562  );
563 
564  $scheduleValue = $cron->getDefaultScheduleValue();
565 
566  $this->assertEquals(1, $scheduleValue);
567  }
568 }
if(!array_key_exists('StateId', $_REQUEST)) $id
$cron
Definition: cron.php:16
$key
Definition: croninfo.php:18