ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilCertificateTemplateRepositoryTest.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  $logger = $this->getMockBuilder('ilLogger')
16  ->disableOriginalConstructor()
17  ->getMock();
18 
19  $objectDataCache = $this->getMockBuilder('ilObjectDataCache')
20  ->disableOriginalConstructor()
21  ->getMock();
22 
23  $objectDataCache->method('lookUpType')->willReturn('crs');
24 
25  $database->method('nextId')
26  ->willReturn(10);
27 
28  $database->method('insert')
29  ->with(
30  'il_cert_template',
31  array(
32  'id' => array('integer', 10),
33  'obj_id' => array('integer', 100),
34  'obj_type' => array('text', 'crs'),
35  'certificate_content' => array('clob', '<xml>Some Content</xml>'),
36  'certificate_hash' => array('text', md5('<xml>Some Content</xml>')),
37  'template_values' => array('clob', '[]'),
38  'version' => array('integer', 1),
39  'ilias_version' => array('text', 'v5.4.0'),
40  'created_timestamp' => array('integer', 123456789),
41  'currently_active' => array('integer', true),
42  'background_image_path' => array('text', '/some/where/background.jpg'),
43  'deleted' => array('integer', 0),
44  'thumbnail_image_path' => array('text', 'some/path/test.svg')
45  )
46  );
47 
48  $logger->expects($this->atLeastOnce())
49  ->method('info');
50 
52  100,
53  'crs',
54  '<xml>Some Content</xml>',
55  md5('<xml>Some Content</xml>'),
56  '[]',
57  '1',
58  'v5.4.0',
59  123456789,
60  true,
61  $backgroundImagePath = '/some/where/background.jpg',
62  'some/path/test.svg'
63  );
64 
65  $repository = new ilCertificateTemplateRepository($database, $logger, $objectDataCache);
66 
67  $repository->save($template);
68  }
69 
71  {
72  $database = $this->getMockBuilder('ilDBInterface')
73  ->disableOriginalConstructor()
74  ->getMock();
75 
76  $logger = $this->getMockBuilder('ilLogger')
77  ->disableOriginalConstructor()
78  ->getMock();
79 
80  $database->method('fetchAssoc')
81  ->willReturnOnConsecutiveCalls(
82  array(
83  'id' => 1,
84  'obj_id' => 10,
85  'obj_type' => 'crs',
86  'certificate_content' => '<xml>Some Content</xml>',
87  'certificate_hash' => md5('<xml>Some Content</xml>'),
88  'template_values' => '[]',
89  'version' => 1,
90  'ilias_version' => 'v5.4.0',
91  'created_timestamp' => 123456789,
92  'currently_active' => true,
93  'background_image_path' => '/some/where/background.jpg',
94  'thumbnail_image_path' => 'some/path/test.svg'
95  ),
96  array(
97  'id' => 30,
98  'obj_id' => 10,
99  'obj_type' => 'tst',
100  'certificate_content' => '<xml>Some Other Content</xml>',
101  'certificate_hash' => md5('<xml>Some Content</xml>'),
102  'template_values' => '[]',
103  'version' => 55,
104  'ilias_version' => 'v5.3.0',
105  'created_timestamp' => 123456789,
106  'currently_active' => false,
107  'background_image_path' => '/some/where/else/background.jpg',
108  'thumbnail_image_path' => 'some/path/test.svg'
109  )
110  );
111 
112  $objectDataCache = $this->getMockBuilder('ilObjectDataCache')
113  ->disableOriginalConstructor()
114  ->getMock();
115 
116  $objectDataCache->method('lookUpType')->willReturn('crs');
117 
118  $repository = new ilCertificateTemplateRepository($database, $logger, $objectDataCache);
119 
120  $templates = $repository->fetchCertificateTemplatesByObjId(10);
121 
122  $this->assertEquals(1, $templates[0]->getId());
123  $this->assertEquals(30, $templates[1]->getId());
124  }
125 
127  {
128  $database = $this->getMockBuilder('ilDBInterface')
129  ->disableOriginalConstructor()
130  ->getMock();
131 
132  $logger = $this->getMockBuilder('ilLogger')
133  ->disableOriginalConstructor()
134  ->getMock();
135 
136  $database->method('fetchAssoc')
137  ->willReturnOnConsecutiveCalls(
138  array(
139  'id' => 1,
140  'obj_id' => 10,
141  'obj_type' => 'crs',
142  'certificate_content' => '<xml>Some Content</xml>',
143  'certificate_hash' => md5('<xml>Some Content</xml>'),
144  'template_values' => '[]',
145  'version' => 1,
146  'ilias_version' => 'v5.4.0',
147  'created_timestamp' => 123456789,
148  'currently_active' => true,
149  'background_image_path' => '/some/where/background.jpg',
150  'thumbnail_image_path' => 'some/path/test.svg'
151  ),
152  array(
153  'id' => 30,
154  'obj_id' => 10,
155  'obj_type' => 'tst',
156  'certificate_content' => '<xml>Some Other Content</xml>',
157  'certificate_hash' => md5('<xml>Some Content</xml>'),
158  'template_values' => '[]',
159  'version' => 55,
160  'ilias_version' => 'v5.3.0',
161  'created_timestamp' => 123456789,
162  'currently_active' => false,
163  'background_image_path' => '/some/where/else/background.jpg',
164  'thumbnail_image_path' => 'some/path/test.svg'
165  )
166  );
167 
168  $objectDataCache = $this->getMockBuilder('ilObjectDataCache')
169  ->disableOriginalConstructor()
170  ->getMock();
171 
172  $objectDataCache->method('lookUpType')->willReturn('crs');
173 
174  $repository = new ilCertificateTemplateRepository($database, $logger, $objectDataCache);
175 
176  $template = $repository->fetchCurrentlyActiveCertificate(10);
177 
178  $this->assertEquals(1, $template->getId());
179  }
180 
182  {
183  $database = $this->getMockBuilder('ilDBInterface')
184  ->disableOriginalConstructor()
185  ->getMock();
186 
187  $logger = $this->getMockBuilder('ilLogger')
188  ->disableOriginalConstructor()
189  ->getMock();
190 
191  $database->method('fetchAssoc')
192  ->willReturnOnConsecutiveCalls(
193  array(
194  'id' => 1,
195  'obj_id' => 10,
196  'obj_type' => 'crs',
197  'certificate_content' => '<xml>Some Content</xml>',
198  'certificate_hash' => md5('<xml>Some Content</xml>'),
199  'template_values' => '[]',
200  'version' => 1,
201  'ilias_version' => 'v5.4.0',
202  'created_timestamp' => 123456789,
203  'currently_active' => true,
204  'background_image_path' => '/some/where/background.jpg',
205  'thumbnail_image_path' => 'some/path/test.svg'
206  ),
207  array(
208  'id' => 30,
209  'obj_id' => 10,
210  'obj_type' => 'tst',
211  'certificate_content' => '<xml>Some Other Content</xml>',
212  'certificate_hash' => md5('<xml>Some Content</xml>'),
213  'template_values' => '[]',
214  'version' => 55,
215  'ilias_version' => 'v5.3.0',
216  'created_timestamp' => 123456789,
217  'currently_active' => false,
218  'background_image_path' => '/some/where/else/background.jpg',
219  'thumbnail_image_path' => 'some/path/test.svg'
220  )
221  );
222 
223  $objectDataCache = $this->getMockBuilder('ilObjectDataCache')
224  ->disableOriginalConstructor()
225  ->getMock();
226 
227  $objectDataCache->method('lookUpType')->willReturn('crs');
228 
229  $repository = new ilCertificateTemplateRepository($database, $logger, $objectDataCache);
230 
231  $template = $repository->fetchPreviousCertificate(10);
232 
233  $this->assertEquals(30, $template->getId());
234  }
235 
237  {
238  $database = $this->getMockBuilder('ilDBInterface')
239  ->disableOriginalConstructor()
240  ->getMock();
241 
242  $logger = $this->getMockBuilder('ilLogger')
243  ->disableOriginalConstructor()
244  ->getMock();
245 
246  $database->method('quote')
247  ->withConsecutive(array(10, 'integer'), array(200, 'integer'))
248  ->willReturnOnConsecutiveCalls(10, 200);
249 
250  $database->method('query')
251  ->with('
252 DELETE FROM il_cert_template
253 WHERE id = 10
254 AND obj_id = 200');
255 
256  $objectDataCache = $this->getMockBuilder('ilObjectDataCache')
257  ->disableOriginalConstructor()
258  ->getMock();
259 
260  $objectDataCache->method('lookUpType')->willReturn('crs');
261 
262  $repository = new ilCertificateTemplateRepository($database, $logger, $objectDataCache);
263 
264  $repository->deleteTemplate(10, 200);
265  }
266 
268  {
269  $database = $this->getMockBuilder('ilDBInterface')
270  ->disableOriginalConstructor()
271  ->getMock();
272 
273  $logger = $this->getMockBuilder('ilLogger')
274  ->disableOriginalConstructor()
275  ->getMock();
276 
277  $database->method('quote')
278  ->withConsecutive(array(10, 'integer'), array(30, 'integer'))
279  ->willReturnOnConsecutiveCalls(10, 30);
280 
281  $database->method('fetchAssoc')->willReturnOnConsecutiveCalls(
282  array(
283  'id' => 1,
284  'obj_id' => 10,
285  'obj_type' => 'crs',
286  'certificate_content' => '<xml>Some Content</xml>',
287  'certificate_hash' => md5('<xml>Some Content</xml>'),
288  'template_values' => '[]',
289  'version' => 1,
290  'ilias_version' => 'v5.4.0',
291  'created_timestamp' => 123456789,
292  'currently_active' => true,
293  'background_image_path' => '/some/where/background.jpg',
294  'thumbnail_image_path' => 'some/path/test.svg'
295  ),
296  array(
297  'id' => 30,
298  'obj_id' => 10,
299  'obj_type' => 'tst',
300  'certificate_content' => '<xml>Some Other Content</xml>',
301  'certificate_hash' => md5('<xml>Some Content</xml>'),
302  'template_values' => '[]',
303  'version' => 55,
304  'ilias_version' => 'v5.3.0',
305  'created_timestamp' => 123456789,
306  'currently_active' => false,
307  'background_image_path' => '/some/where/else/background.jpg',
308  'thumbnail_image_path' => 'some/path/test.svg'
309  )
310  );
311 
312  $database->method('query')
313  ->withConsecutive(
314  array($this->anything()),
315  array('UPDATE il_cert_template
316 SET currently_active = 1
317 WHERE id = 30')
318  );
319 
320  $objectDataCache = $this->getMockBuilder('ilObjectDataCache')
321  ->disableOriginalConstructor()
322  ->getMock();
323 
324  $objectDataCache->method('lookUpType')->willReturn('crs');
325 
326  $repository = new ilCertificateTemplateRepository($database, $logger, $objectDataCache);
327 
328  $template = $repository->activatePreviousCertificate(10, 200);
329 
330  $this->assertEquals(30, $template->getId());
331  }
332 
333  public function testFetchAllObjectIdsByType()
334  {
335  $database = $this->getMockBuilder('ilDBInterface')
336  ->disableOriginalConstructor()
337  ->getMock();
338 
339  $logger = $this->getMockBuilder('ilLogger')
340  ->disableOriginalConstructor()
341  ->getMock();
342 
343  $database->method('quote')
344  ->with('crs')
345  ->willReturn('crs');
346 
347  $objectDataCache = $this->getMockBuilder('ilObjectDataCache')
348  ->disableOriginalConstructor()
349  ->getMock();
350 
351  $database->method('fetchAssoc')->willReturnOnConsecutiveCalls(
352  array(
353  'id' => 1,
354  'obj_id' => 10,
355  'obj_type' => 'crs',
356  'certificate_content' => '<xml>Some Content</xml>',
357  'certificate_hash' => md5('<xml>Some Content</xml>'),
358  'template_values' => '[]',
359  'version' => 1,
360  'ilias_version' => 'v5.4.0',
361  'created_timestamp' => 123456789,
362  'currently_active' => true,
363  'background_image_path' => '/some/where/background.jpg',
364  'thumbnail_image_path' => '/some/where/thumbnail.svg'
365  ),
366  array(
367  'id' => 30,
368  'obj_id' => 30,
369  'obj_type' => 'crs',
370  'certificate_content' => '<xml>Some Other Content</xml>',
371  'certificate_hash' => md5('<xml>Some Content</xml>'),
372  'template_values' => '[]',
373  'version' => 55,
374  'ilias_version' => 'v5.3.0',
375  'created_timestamp' => 123456789,
376  'currently_active' => false,
377  'background_image_path' => '/some/where/else/background.jpg',
378  'thumbnail_image_path' => '/some/where/thumbnail.svg'
379  )
380  );
381 
382  $repository = new ilCertificateTemplateRepository($database, $logger, $objectDataCache);
383 
384  $templates = $repository->fetchActiveTemplatesByType('crs');
385 
386  $this->assertEquals(10, $templates[0]->getObjId());
387  $this->assertEquals(30, $templates[1]->getObjId());
388  }
389 
394  {
395  $database = $this->getMockBuilder('ilDBInterface')
396  ->disableOriginalConstructor()
397  ->getMock();
398 
399  $logger = $this->getMockBuilder('ilLogger')
400  ->disableOriginalConstructor()
401  ->getMock();
402 
403  $database->method('quote')
404  ->with(10, 'integer')
405  ->willReturn(10);
406 
407  $objectDataCache = $this->getMockBuilder('ilObjectDataCache')
408  ->disableOriginalConstructor()
409  ->getMock();
410 
411  $database->method('fetchAssoc')
412  ->willReturn(array());
413 
414  $database->method('fetchAssoc')
415  ->willReturn(array());
416 
417  $repository = new ilCertificateTemplateRepository($database, $logger, $objectDataCache);
418 
419  $repository->fetchFirstCreatedTemplate(10);
420 
421  $this->fail();
422  }
423 
424  public function fetchFirstCreateTemplate()
425  {
426  $database = $this->getMockBuilder('ilDBInterface')
427  ->disableOriginalConstructor()
428  ->getMock();
429 
430  $logger = $this->getMockBuilder('ilLogger')
431  ->disableOriginalConstructor()
432  ->getMock();
433 
434  $database->method('quote')
435  ->with(10, 'integer')
436  ->willReturn(10);
437 
438  $objectDataCache = $this->getMockBuilder('ilObjectDataCache')
439  ->disableOriginalConstructor()
440  ->getMock();
441 
442  $database->method('fetchAssoc')
443  ->willReturn(array());
444 
445  $database->method('fetchAssoc')->willReturn(
446  array(
447  'id' => 1,
448  'obj_id' => 10,
449  'obj_type' => 'crs',
450  'certificate_content' => '<xml>Some Content</xml>',
451  'certificate_hash' => md5('<xml>Some Content</xml>'),
452  'template_values' => '[]',
453  'version' => 1,
454  'ilias_version' => 'v5.4.0',
455  'created_timestamp' => 123456789,
456  'currently_active' => true,
457  'background_image_path' => '/some/where/background.jpg'
458  )
459  );
460 
461  $repository = new ilCertificateTemplateRepository($database, $logger, $objectDataCache);
462 
463  $firstTemplate = $repository->fetchFirstCreatedTemplate(10);
464 
465  $this->assertEquals(1, $firstTemplate->getId());
466  }
467 }
$template