ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilUserCertificateRepositoryTest.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  ->getMock();
13 
14  $database->method('nextId')
15  ->willReturn(141);
16 
17  $database->method('insert')->with(
18  'il_cert_user_cert',
19  array(
20  'id' => array('integer', 141),
21  'pattern_certificate_id' => array('integer', 1),
22  'obj_id' => array('integer', 20),
23  'obj_type' => array('text', 'crs'),
24  'user_id' => array('integer', 400),
25  'user_name' => array('text', 'Niels Theen'),
26  'acquired_timestamp' => array('integer', 123456789),
27  'certificate_content' => array('clob', '<xml>Some Content</xml>'),
28  'template_values' => array('clob', '[]'),
29  'valid_until' => array('integer', null),
30  'version' => array('integer', 1),
31  'ilias_version' => array('text', 'v5.4.0'),
32  'currently_active' => array('integer', true),
33  'background_image_path' => array('text', '/some/where/background.jpg'),
34  'thumbnail_image_path' => array('text', '/some/where/thumbnail.svg'),
35  )
36  );
37 
38  $logger = $this->getMockBuilder('ilLogger')
39  ->disableOriginalConstructor()
40  ->getMock();
41 
42  $logger->expects($this->atLeastOnce())
43  ->method('info');
44 
45  $repository = new ilUserCertificateRepository(
46  $database,
47  $logger,
48  'someDefaultTitle'
49  );
50 
51  $userCertificate = new ilUserCertificate(
52  1,
53  20,
54  'crs',
55  400,
56  'Niels Theen',
57  123456789,
58  '<xml>Some Content</xml>',
59  '[]',
60  null,
61  1,
62  'v5.4.0',
63  true,
64  '/some/where/background.jpg',
65  '/some/where/thumbnail.svg'
66  );
67 
68  $repository->save($userCertificate);
69  }
70 
72  {
73  $database = $this->getMockBuilder('ilDBInterface')
74  ->getMock();
75 
76  $database->method('nextId')
77  ->willReturn(141);
78 
79  $database->method('fetchAssoc')->willReturnOnConsecutiveCalls(
80  array(
81  'id' => 141,
82  'pattern_certificate_id' => 1,
83  'obj_id' => 20,
84  'obj_type' => 'crs',
85  'user_id' => 400,
86  'user_name' => 'Niels Theen',
87  'acquired_timestamp' => 123456789,
88  'certificate_content' => '<xml>Some Content</xml>',
89  'template_values' => '[]',
90  'valid_until' => null,
91  'version' => 1,
92  'ilias_version' => 'v5.4.0',
93  'currently_active' => true,
94  'background_image_path' => '/some/where/background.jpg',
95  'thumbnail_image_path' => array('clob', '/some/where/thumbnail.svg'),
96  'title' => 'Some Title'
97  ),
98  array(
99  'id' => 142,
100  'pattern_certificate_id' => 5,
101  'obj_id' => 3123,
102  'obj_type' => 'tst',
103  'user_id' => 400,
104  'user_name' => 'Niels Theen',
105  'acquired_timestamp' => 987654321,
106  'certificate_content' => '<xml>Some Other Content</xml>',
107  'template_values' => '[]',
108  'valid_until' => null,
109  'version' => 1,
110  'ilias_version' => 'v5.3.0',
111  'currently_active' => true,
112  'background_image_path' => '/some/where/else/background.jpg',
113  'thumbnail_image_path' => array('clob', '/some/where/thumbnail.svg'),
114  'title' => 'Someother Title'
115  )
116  );
117 
118  $logger = $this->getMockBuilder('ilLogger')
119  ->disableOriginalConstructor()
120  ->getMock();
121 
122  $logger->expects($this->atLeastOnce())
123  ->method('info');
124 
125  $repository = new ilUserCertificateRepository(
126  $database,
127  $logger,
128  'someDefaultTitle',
129  'someDefaultDescription'
130  );
131 
132  $results = $repository->fetchActiveCertificates(400);
133 
134  $this->assertEquals(141, $results[0]->getUserCertificate()->getId());
135  $this->assertEquals(142, $results[1]->getUserCertificate()->getId());
136  }
137 
139  {
140  $database = $this->getMockBuilder('ilDBInterface')
141  ->getMock();
142 
143  $database->method('nextId')
144  ->willReturn(141);
145 
146  $database->method('fetchAssoc')->willReturnOnConsecutiveCalls(
147  array(
148  'id' => 141,
149  'pattern_certificate_id' => 1,
150  'obj_id' => 20,
151  'obj_type' => 'crs',
152  'user_id' => 400,
153  'user_name' => 'Niels Theen',
154  'acquired_timestamp' => 123456789,
155  'certificate_content' => '<xml>Some Content</xml>',
156  'template_values' => '[]',
157  'valid_until' => null,
158  'version' => 1,
159  'ilias_version' => 'v5.4.0',
160  'currently_active' => true,
161  'background_image_path' => '/some/where/background.jpg',
162  'thumbnail_image_path' => array('clob', '/some/where/thumbnail.svg'),
163  ),
164  array(
165  'id' => 142,
166  'pattern_certificate_id' => 5,
167  'obj_id' => 20,
168  'obj_type' => 'tst',
169  'user_id' => 400,
170  'user_name' => 'Niels Theen',
171  'acquired_timestamp' => 987654321,
172  'certificate_content' => '<xml>Some Other Content</xml>',
173  'template_values' => '[]',
174  'valid_until' => null,
175  'version' => 1,
176  'ilias_version' => 'v5.3.0',
177  'currently_active' => true,
178  'background_image_path' => '/some/where/else/background.jpg',
179  'thumbnail_image_path' => array('clob', '/some/where/thumbnail.svg'),
180  )
181  );
182 
183  $logger = $this->getMockBuilder('ilLogger')
184  ->disableOriginalConstructor()
185  ->getMock();
186 
187  $logger->expects($this->atLeastOnce())
188  ->method('info');
189 
190  $repository = new ilUserCertificateRepository(
191  $database,
192  $logger,
193  'someDefaultTitle'
194  );
195 
196  $result = $repository->fetchActiveCertificate(400, 20);
197 
198  $this->assertEquals(141, $result->getId());
199  }
200 
205  {
206  $database = $this->getMockBuilder('ilDBInterface')
207  ->getMock();
208 
209  $database->method('nextId')
210  ->willReturn(141);
211 
212  $database->method('fetchAssoc')->willReturn(array());
213 
214  $logger = $this->getMockBuilder('ilLogger')
215  ->disableOriginalConstructor()
216  ->getMock();
217 
218  $logger->expects($this->atLeastOnce())
219  ->method('info');
220 
221  $repository = new ilUserCertificateRepository($database, $logger, 'someDefaultTitle');
222 
223  $repository->fetchActiveCertificate(400, 20);
224 
225  $this->fail('Should never happen. Certificate Found?');
226  }
227 
229  {
230  $database = $this->getMockBuilder('ilDBInterface')
231  ->getMock();
232 
233  $database->method('nextId')
234  ->willReturn(141);
235 
236  $database->method('fetchAssoc')->willReturnOnConsecutiveCalls(
237  array(
238  'id' => 141,
239  'pattern_certificate_id' => 1,
240  'obj_id' => 20,
241  'obj_type' => 'crs',
242  'user_id' => 400,
243  'user_name' => 'Niels Theen',
244  'acquired_timestamp' => 123456789,
245  'certificate_content' => '<xml>Some Content</xml>',
246  'template_values' => '[]',
247  'valid_until' => null,
248  'version' => 1,
249  'ilias_version' => 'v5.4.0',
250  'currently_active' => true,
251  'background_image_path' => '/some/where/background.jpg',
252  'thumbnail_image_path' => '/some/where/else/thumbnail.svg',
253  'title' => 'SomeTitle',
254  'someDescription' => 'SomeDescription'
255  ),
256  array(
257  'id' => 142,
258  'pattern_certificate_id' => 5,
259  'obj_id' => 20,
260  'obj_type' => 'crs',
261  'user_id' => 400,
262  'user_name' => 'Niels Theen',
263  'acquired_timestamp' => 987654321,
264  'certificate_content' => '<xml>Some Other Content</xml>',
265  'template_values' => '[]',
266  'valid_until' => null,
267  'version' => 1,
268  'ilias_version' => 'v5.3.0',
269  'currently_active' => true,
270  'background_image_path' => '/some/where/else/background.jpg',
271  'thumbnail_image_path' => '/some/where/else/thumbnail.svg',
272  'title' => 'SomeTitle',
273  'someDescription' => 'SomeDescription'
274  )
275  );
276 
277  $logger = $this->getMockBuilder('ilLogger')
278  ->disableOriginalConstructor()
279  ->getMock();
280 
281  $logger->expects($this->atLeastOnce())
282  ->method('info');
283 
284  $repository = new ilUserCertificateRepository($database, $logger, 'someDefaultTitle');
285 
286  $results = $repository->fetchActiveCertificatesByTypeForPresentation(400, 'crs');
287 
288  $this->assertEquals(141, $results[0]->getUserCertificate()->getId());
289  $this->assertEquals(142, $results[1]->getUserCertificate()->getId());
290  }
291 
292  public function testFetchCertificate()
293  {
294  $database = $this->getMockBuilder('ilDBInterface')
295  ->getMock();
296 
297  $database->method('nextId')
298  ->willReturn(141);
299 
300  $database->method('fetchAssoc')->willReturn(
301  array(
302  'id' => 141,
303  'pattern_certificate_id' => 1,
304  'obj_id' => 20,
305  'obj_type' => 'crs',
306  'user_id' => 400,
307  'user_name' => 'Niels Theen',
308  'acquired_timestamp' => 123456789,
309  'certificate_content' => '<xml>Some Content</xml>',
310  'template_values' => '[]',
311  'valid_until' => null,
312  'version' => 1,
313  'ilias_version' => 'v5.4.0',
314  'currently_active' => true,
315  'background_image_path' => '/some/where/background.jpg',
316  'thumbnail_image_path' => '/some/where/else/thumbnail.svg',
317  'title' => 'SomeTitle',
318  'someDescription' => 'SomeDescription'
319  )
320  );
321 
322  $logger = $this->getMockBuilder('ilLogger')
323  ->disableOriginalConstructor()
324  ->getMock();
325 
326  $logger->expects($this->atLeastOnce())
327  ->method('info');
328 
329  $repository = new ilUserCertificateRepository($database, $logger, 'someTitle');
330 
331  $result = $repository->fetchCertificate(141);
332 
333  $this->assertEquals(141, $result->getId());
334  }
335 
340  {
341  $database = $this->getMockBuilder('ilDBInterface')
342  ->getMock();
343 
344  $database->method('nextId')
345  ->willReturn(141);
346 
347  $database->method('fetchAssoc')
348  ->willReturn(array());
349 
350  $logger = $this->getMockBuilder('ilLogger')
351  ->disableOriginalConstructor()
352  ->getMock();
353 
354  $logger->expects($this->atLeastOnce())
355  ->method('info');
356 
357  $repository = new ilUserCertificateRepository($database, $logger, 'someTitle');
358 
359  $repository->fetchCertificate(141);
360 
361  $this->fail('Should never happen. Certificate Found?');
362  }
363 
365  {
366  $database = $this->getMockBuilder('ilDBInterface')
367  ->getMock();
368 
369  $database
370  ->expects($this->once())
371  ->method('query');
372 
373  $database
374  ->expects($this->once())
375  ->method('in');
376 
377  $database
378  ->expects($this->exactly(3))
379  ->method('fetchAssoc')
380  ->willReturnOnConsecutiveCalls(
381  array('obj_id' => 100),
382  array('obj_id' => 300),
383  array()
384  );
385 
386  $database->method('fetchAssoc')
387  ->willReturn(array());
388 
389  $logger = $this->getMockBuilder('ilLogger')
390  ->disableOriginalConstructor()
391  ->getMock();
392 
393  $logger->expects($this->atLeastOnce())
394  ->method('info');
395 
396  $repository = new ilUserCertificateRepository($database, $logger, 'someTitle');
397 
398  $userId = 10;
399  $objectIds = array(200, 300, 400);
400 
401  $results = $repository->fetchObjectIdsWithCertificateForUser($userId, $objectIds);
402 
403  $this->assertEquals(array(100, 300), $results);
404  }
405 
407  {
408  $database = $this->getMockBuilder('ilDBInterface')
409  ->getMock();
410 
411  $database
412  ->expects($this->once())
413  ->method('query');
414 
415  $database
416  ->expects($this->exactly(3))
417  ->method('fetchAssoc')
418  ->willReturnOnConsecutiveCalls(
419  array('user_id' => 100),
420  array('user_id' => 300),
421  array()
422  );
423 
424  $database->method('fetchAssoc')
425  ->willReturn(array());
426 
427  $logger = $this->getMockBuilder('ilLogger')
428  ->disableOriginalConstructor()
429  ->getMock();
430 
431  $logger->expects($this->atLeastOnce())
432  ->method('info');
433 
434  $repository = new ilUserCertificateRepository($database, $logger, 'someTitle');
435 
436  $objectId = 10;
437 
438  $results = $repository->fetchUserIdsWithCertificateForObject($objectId);
439 
440  $this->assertEquals(array(100, 300), $results);
441  }
442 }
$result
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
$results
Definition: svg-scanner.php:47