ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilUserCertificateRepositoryTest Class Reference
+ Inheritance diagram for ilUserCertificateRepositoryTest:
+ Collaboration diagram for ilUserCertificateRepositoryTest:

Public Member Functions

 testSaveOfUserCertificateToDatabase ()
 
 testFetchAllActiveCertificateForUser ()
 
 testFetchActiveCertificateForUserObjectCombination ()
 
 testFetchNoActiveCertificateLeadsToException ()
 
 testFetchActiveCertificatesByType ()
 
 testFetchCertificate ()
 
 testNoCertificateInFetchtCertificateLeadsToException ()
 
 testFetchObjectWithCertificateForUser ()
 
 testFetchUserIdsWithCertificateForObject ()
 

Additional Inherited Members

- Protected Member Functions inherited from ilCertificateBaseTestCase
 setUp ()
 
 tearDown ()
 
 assertDoesNotThrow (callable $cb, string $message='')
 
 assertThrows (callable $cb, ?string $expected_class=null, ?string $expected_message=null)
 @template T of Throwable More...
 
 setGlobalVariable (string $name, mixed $value)
 
- Protected Attributes inherited from ilCertificateBaseTestCase
Container $dic
 

Detailed Description

Definition at line 23 of file ilUserCertificateRepositoryTest.php.

Member Function Documentation

◆ testFetchActiveCertificateForUserObjectCombination()

ilUserCertificateRepositoryTest::testFetchActiveCertificateForUserObjectCombination ( )

Definition at line 172 of file ilUserCertificateRepositoryTest.php.

172 : void
173 {
174 $database = $this->createMock(ilDBInterface::class);
175
176 $database->method('nextId')
177 ->willReturn(141);
178
179 $database->method('fetchAssoc')->willReturnOnConsecutiveCalls(
180 [
181 'id' => 141,
182 'pattern_certificate_id' => 1,
183 'obj_id' => 20,
184 'obj_type' => 'crs',
185 'usr_id' => 400,
186 'user_name' => 'Niels Theen',
187 'acquired_timestamp' => 123_456_789,
188 'certificate_content' => '<xml>Some Content</xml>',
189 'template_values' => '[]',
190 'valid_until' => null,
191 'version' => 1,
192 'ilias_version' => 'v5.4.0',
193 'currently_active' => true,
194 'background_image_path' => '/some/where/background.jpg',
195 'tile_image_path' => '/some/where/tile_image.svg',
196 'background_image_ident' => '-',
197 'tile_image_ident' => '-',
198 'certificate_id' => '11111111-2222-3333-4444-555555555555'
199 ],
200 [
201 'id' => 142,
202 'pattern_certificate_id' => 5,
203 'obj_id' => 20,
204 'obj_type' => 'tst',
205 'usr_id' => 400,
206 'user_name' => 'Niels Theen',
207 'acquired_timestamp' => 987_654_321,
208 'certificate_content' => '<xml>Some Other Content</xml>',
209 'template_values' => '[]',
210 'valid_until' => null,
211 'version' => 1,
212 'ilias_version' => 'v5.3.0',
213 'currently_active' => true,
214 'background_image_path' => '/some/where/else/background.jpg',
215 'tile_image_path' => '/some/where/tile_image.svg',
216 'background_image_ident' => '-',
217 'tile_image_ident' => '-',
218 'certificate_id' => '11111111-2222-3333-4444-555555555555'
219 ]
220 );
221
222 $logger = $this->getMockBuilder(ilLogger::class)
223 ->disableOriginalConstructor()
224 ->getMock();
225
226 $logger->expects($this->atLeastOnce())
227 ->method('debug');
228
229 $repository = new ilUserCertificateRepository(
230 $database,
231 $logger,
232 'someDefaultTitle'
233 );
234
235 $result = $repository->fetchActiveCertificate(400, 20);
236
237 $this->assertSame(141, $result->getId());
238 }

◆ testFetchActiveCertificatesByType()

ilUserCertificateRepositoryTest::testFetchActiveCertificatesByType ( )

Definition at line 265 of file ilUserCertificateRepositoryTest.php.

265 : void
266 {
267 $database = $this->createMock(ilDBInterface::class);
268
269 $database->method('nextId')
270 ->willReturn(141);
271
272 $database->method('fetchAssoc')->willReturnOnConsecutiveCalls(
273 [
274 'id' => 141,
275 'pattern_certificate_id' => 1,
276 'obj_id' => 20,
277 'obj_type' => 'crs',
278 'usr_id' => 400,
279 'user_name' => 'Niels Theen',
280 'acquired_timestamp' => 123_456_789,
281 'certificate_content' => '<xml>Some Content</xml>',
282 'template_values' => '[]',
283 'valid_until' => null,
284 'version' => 1,
285 'ilias_version' => 'v5.4.0',
286 'currently_active' => true,
287 'background_image_path' => '/some/where/background.jpg',
288 'tile_image_path' => '/some/where/else/tile_image.svg',
289 'background_image_ident' => '-',
290 'tile_image_ident' => '-',
291 'title' => 'SomeTitle',
292 'someDescription' => 'SomeDescription',
293 'certificate_id' => '11111111-2222-3333-4444-555555555555'
294 ],
295 [
296 'id' => 142,
297 'pattern_certificate_id' => 5,
298 'obj_id' => 20,
299 'obj_type' => 'crs',
300 'usr_id' => 400,
301 'user_name' => 'Niels Theen',
302 'acquired_timestamp' => 987_654_321,
303 'certificate_content' => '<xml>Some Other Content</xml>',
304 'template_values' => '[]',
305 'valid_until' => null,
306 'version' => 1,
307 'ilias_version' => 'v5.3.0',
308 'currently_active' => true,
309 'background_image_path' => '/some/where/else/background.jpg',
310 'tile_image_path' => '/some/where/else/tile_image.svg',
311 'background_image_ident' => '-',
312 'tile_image_ident' => '-',
313 'title' => 'SomeTitle',
314 'someDescription' => 'SomeDescription',
315 'certificate_id' => '11111111-2222-3333-4444-555555555555'
316 ],
317 null
318 );
319
320 $logger = $this->getMockBuilder(ilLogger::class)
321 ->disableOriginalConstructor()
322 ->getMock();
323
324 $logger->expects($this->atLeastOnce())
325 ->method('debug');
326
327 $repository = new ilUserCertificateRepository($database, $logger, 'someDefaultTitle');
328
329 $results = $repository->fetchActiveCertificatesByTypeForPresentation(400, 'crs');
330
331 $this->assertSame(141, $results[0]->getUserCertificate()->getId());
332 $this->assertSame(142, $results[1]->getUserCertificate()->getId());
333 }
$results

References $results, and ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ testFetchAllActiveCertificateForUser()

ilUserCertificateRepositoryTest::testFetchAllActiveCertificateForUser ( )

Definition at line 100 of file ilUserCertificateRepositoryTest.php.

100 : void
101 {
102 $database = $this->createMock(ilDBInterface::class);
103
104 $database->method('nextId')
105 ->willReturn(141);
106
107 $database->method('fetchAssoc')->willReturnOnConsecutiveCalls(
108 [
109 'id' => 141,
110 'pattern_certificate_id' => 1,
111 'obj_id' => 20,
112 'obj_type' => 'crs',
113 'usr_id' => 400,
114 'user_name' => 'Niels Theen',
115 'acquired_timestamp' => 123_456_789,
116 'certificate_content' => '<xml>Some Content</xml>',
117 'template_values' => '[]',
118 'valid_until' => null,
119 'version' => 1,
120 'ilias_version' => 'v5.4.0',
121 'currently_active' => true,
122 'background_image_path' => '/some/where/background.jpg',
123 'tile_image_path' => '/some/where/tile_image.svg',
124 'background_image_ident' => '-',
125 'tile_image_ident' => '-',
126 'title' => 'Some Title',
127 'certificate_id' => '11111111-2222-3333-4444-555555555555'
128 ],
129 [
130 'id' => 142,
131 'pattern_certificate_id' => 5,
132 'obj_id' => 3123,
133 'obj_type' => 'tst',
134 'usr_id' => 400,
135 'user_name' => 'Niels Theen',
136 'acquired_timestamp' => 987_654_321,
137 'certificate_content' => '<xml>Some Other Content</xml>',
138 'template_values' => '[]',
139 'valid_until' => null,
140 'version' => 1,
141 'ilias_version' => 'v5.3.0',
142 'currently_active' => true,
143 'background_image_path' => '/some/where/else/background.jpg',
144 'tile_image_path' => '/some/where/tile_image.svg',
145 'background_image_ident' => '-',
146 'tile_image_ident' => '-',
147 'title' => 'Someother Title',
148 'certificate_id' => '11111111-2222-3333-4444-555555555555'
149 ],
150 null
151 );
152
153 $logger = $this->getMockBuilder(ilLogger::class)
154 ->disableOriginalConstructor()
155 ->getMock();
156
157 $logger->expects($this->atLeastOnce())
158 ->method('debug');
159
160 $repository = new ilUserCertificateRepository(
161 $database,
162 $logger,
163 'someDefaultTitle'
164 );
165
166 $results = $repository->fetchActiveCertificates(400);
167
168 $this->assertSame(141, $results[0]->getUserCertificate()->getId());
169 $this->assertSame(142, $results[1]->getUserCertificate()->getId());
170 }

References $results, and ILIAS\Survey\Mode\getId().

+ Here is the call graph for this function:

◆ testFetchCertificate()

ilUserCertificateRepositoryTest::testFetchCertificate ( )

Definition at line 335 of file ilUserCertificateRepositoryTest.php.

335 : void
336 {
337 $database = $this->createMock(ilDBInterface::class);
338
339 $database->method('nextId')
340 ->willReturn(141);
341
342 $database->method('fetchAssoc')->willReturn(
343 [
344 'id' => 141,
345 'pattern_certificate_id' => 1,
346 'obj_id' => 20,
347 'obj_type' => 'crs',
348 'usr_id' => 400,
349 'user_name' => 'Niels Theen',
350 'acquired_timestamp' => 123_456_789,
351 'certificate_content' => '<xml>Some Content</xml>',
352 'template_values' => '[]',
353 'valid_until' => null,
354 'version' => 1,
355 'ilias_version' => 'v5.4.0',
356 'currently_active' => true,
357 'background_image_path' => '/some/where/background.jpg',
358 'tile_image_path' => '/some/where/else/tile_image.svg',
359 'background_image_ident' => '-',
360 'tile_image_ident' => '-',
361 'title' => 'SomeTitle',
362 'someDescription' => 'SomeDescription',
363 'certificate_id' => '11111111-2222-3333-4444-555555555555'
364 ]
365 );
366
367 $logger = $this->getMockBuilder(ilLogger::class)
368 ->disableOriginalConstructor()
369 ->getMock();
370
371 $logger->expects($this->atLeastOnce())
372 ->method('debug');
373
374 $repository = new ilUserCertificateRepository($database, $logger, 'someTitle');
375
376 $result = $repository->fetchCertificate(141);
377
378 $this->assertSame(141, $result->getId());
379 }

◆ testFetchNoActiveCertificateLeadsToException()

ilUserCertificateRepositoryTest::testFetchNoActiveCertificateLeadsToException ( )

Definition at line 240 of file ilUserCertificateRepositoryTest.php.

240 : never
241 {
242 $this->expectException(ilException::class);
243
244 $database = $this->createMock(ilDBInterface::class);
245
246 $database->method('nextId')
247 ->willReturn(141);
248
249 $database->method('fetchAssoc')->willReturn([]);
250
251 $logger = $this->getMockBuilder(ilLogger::class)
252 ->disableOriginalConstructor()
253 ->getMock();
254
255 $logger->expects($this->atLeastOnce())
256 ->method('debug');
257
258 $repository = new ilUserCertificateRepository($database, $logger, 'someDefaultTitle');
259
260 $repository->fetchActiveCertificate(400, 20);
261
262 $this->fail('Should never happen. Certificate Found?');
263 }

◆ testFetchObjectWithCertificateForUser()

ilUserCertificateRepositoryTest::testFetchObjectWithCertificateForUser ( )

Definition at line 407 of file ilUserCertificateRepositoryTest.php.

407 : void
408 {
409 $database = $this->createMock(ilDBInterface::class);
410
411 $database
412 ->expects($this->once())
413 ->method('query');
414
415 $database
416 ->expects($this->once())
417 ->method('in');
418
419 $database
420 ->expects($this->exactly(3))
421 ->method('fetchAssoc')
422 ->willReturnOnConsecutiveCalls(
423 ['obj_id' => 100],
424 ['obj_id' => 300],
425 []
426 );
427
428 $database->method('fetchAssoc')
429 ->willReturn([]);
430
431 $logger = $this->getMockBuilder(ilLogger::class)
432 ->disableOriginalConstructor()
433 ->getMock();
434
435 $logger->expects($this->atLeastOnce())
436 ->method('debug');
437
438 $repository = new ilUserCertificateRepository($database, $logger, 'someTitle');
439
440 $userId = 10;
441 $objectIds = [200, 300, 400];
442
443 $results = $repository->fetchObjectIdsWithCertificateForUser($userId, $objectIds);
444
445 $this->assertSame([100, 300], $results);
446 }

References $results.

◆ testFetchUserIdsWithCertificateForObject()

ilUserCertificateRepositoryTest::testFetchUserIdsWithCertificateForObject ( )

Definition at line 448 of file ilUserCertificateRepositoryTest.php.

448 : void
449 {
450 $database = $this->createMock(ilDBInterface::class);
451
452 $database
453 ->expects($this->once())
454 ->method('query');
455
456 $database
457 ->expects($this->exactly(3))
458 ->method('fetchAssoc')
459 ->willReturnOnConsecutiveCalls(
460 ['usr_id' => 100],
461 ['usr_id' => 300],
462 []
463 );
464
465 $database->method('fetchAssoc')
466 ->willReturn([]);
467
468 $logger = $this->getMockBuilder(ilLogger::class)
469 ->disableOriginalConstructor()
470 ->getMock();
471
472 $logger->expects($this->atLeastOnce())
473 ->method('debug');
474
475 $repository = new ilUserCertificateRepository($database, $logger, 'someTitle');
476
477 $objectId = 10;
478
479 $results = $repository->fetchUserIdsWithCertificateForObject($objectId);
480
481 $this->assertSame([100, 300], $results);
482 }

References $results.

◆ testNoCertificateInFetchtCertificateLeadsToException()

ilUserCertificateRepositoryTest::testNoCertificateInFetchtCertificateLeadsToException ( )

Definition at line 381 of file ilUserCertificateRepositoryTest.php.

381 : never
382 {
383 $this->expectException(ilException::class);
384
385 $database = $this->createMock(ilDBInterface::class);
386
387 $database->method('nextId')
388 ->willReturn(141);
389
390 $database->method('fetchAssoc')
391 ->willReturn([]);
392
393 $logger = $this->getMockBuilder(ilLogger::class)
394 ->disableOriginalConstructor()
395 ->getMock();
396
397 $logger->expects($this->atLeastOnce())
398 ->method('debug');
399
400 $repository = new ilUserCertificateRepository($database, $logger, 'someTitle');
401
402 $repository->fetchCertificate(141);
403
404 $this->fail('Should never happen. Certificate Found?');
405 }

◆ testSaveOfUserCertificateToDatabase()

ilUserCertificateRepositoryTest::testSaveOfUserCertificateToDatabase ( )

Definition at line 25 of file ilUserCertificateRepositoryTest.php.

25 : void
26 {
27 $database = $this->createMock(ilDBInterface::class);
28
29 $database->method('nextId')
30 ->willReturn(141);
31
32 $database->method('insert')->with(
33 'il_cert_user_cert',
34 [
35 'id' => ['integer', 141],
36 'pattern_certificate_id' => ['integer', 1],
37 'obj_id' => ['integer', 20],
38 'obj_type' => ['text', 'crs'],
39 'usr_id' => ['integer', 400],
40 'user_name' => ['text', 'Niels Theen'],
41 'acquired_timestamp' => ['integer', 123_456_789],
42 'certificate_content' => ['clob', '<xml>Some Content</xml>'],
43 'template_values' => ['clob', '[]'],
44 'valid_until' => ['integer', null],
45 'version' => ['integer', 1],
46 'ilias_version' => ['text', 'v5.4.0'],
47 'currently_active' => ['integer', true],
48 'background_image_path' => ['text', '/some/where/background.jpg'],
49 'tile_image_path' => ['text', '/some/where/tile_image.svg'],
50 'background_image_ident' => ['text', '-'],
51 'tile_image_ident' => ['text', '-'],
52 'certificate_id' => ['text', '11111111-2222-3333-4444-555555555555'],
53 ]
54 );
55
56 $database->method('tableColumnExists')->willReturnMap(
57 [
58 ['il_cert_user_cert', 'background_image_path', true],
59 ['il_cert_user_cert', 'tile_image_path', true],
60 ]
61 );
62
63 $logger = $this->getMockBuilder(ilLogger::class)
64 ->disableOriginalConstructor()
65 ->getMock();
66
67 $logger->expects($this->atLeastOnce())
68 ->method('debug');
69
70 $repository = new ilUserCertificateRepository(
71 $database,
72 $logger,
73 'someDefaultTitle'
74 );
75
76 $userCertificate = new ilUserCertificate(
77 1,
78 20,
79 'crs',
80 400,
81 'Niels Theen',
82 123_456_789,
83 '<xml>Some Content</xml>',
84 '[]',
85 null,
86 1,
87 'v5.4.0',
88 true,
89 new CertificateId('11111111-2222-3333-4444-555555555555'),
90 '/some/where/background.jpg',
91 '/some/where/tile_image.svg',
92 '-',
93 '-',
94 null
95 );
96
97 $repository->save($userCertificate);
98 }

The documentation for this class was generated from the following file: