ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 157 of file ilUserCertificateRepositoryTest.php.

157 : void
158 {
159 $database = $this->createMock(ilDBInterface::class);
160
161 $database->method('nextId')
162 ->willReturn(141);
163
164 $database->method('fetchAssoc')->willReturnOnConsecutiveCalls(
165 [
166 'id' => 141,
167 'pattern_certificate_id' => 1,
168 'obj_id' => 20,
169 'obj_type' => 'crs',
170 'usr_id' => 400,
171 'user_name' => 'Niels Theen',
172 'acquired_timestamp' => 123_456_789,
173 'certificate_content' => '<xml>Some Content</xml>',
174 'template_values' => '[]',
175 'valid_until' => null,
176 'version' => 1,
177 'ilias_version' => 'v5.4.0',
178 'currently_active' => true,
179 'background_image_ident' => '-',
180 'tile_image_ident' => '-',
181 'certificate_id' => '11111111-2222-3333-4444-555555555555'
182 ],
183 [
184 'id' => 142,
185 'pattern_certificate_id' => 5,
186 'obj_id' => 20,
187 'obj_type' => 'tst',
188 'usr_id' => 400,
189 'user_name' => 'Niels Theen',
190 'acquired_timestamp' => 987_654_321,
191 'certificate_content' => '<xml>Some Other Content</xml>',
192 'template_values' => '[]',
193 'valid_until' => null,
194 'version' => 1,
195 'ilias_version' => 'v5.3.0',
196 'currently_active' => true,
197 'background_image_ident' => '-',
198 'tile_image_ident' => '-',
199 'certificate_id' => '11111111-2222-3333-4444-555555555555'
200 ]
201 );
202
203 $logger = $this->getMockBuilder(ilLogger::class)
204 ->disableOriginalConstructor()
205 ->getMock();
206
207 $logger->expects($this->atLeastOnce())
208 ->method('debug');
209
210 $repository = new ilUserCertificateRepository(
211 $database,
212 $logger,
213 'someDefaultTitle'
214 );
215
216 $result = $repository->fetchActiveCertificate(400, 20);
217
218 $this->assertSame(141, $result->getId());
219 }

◆ testFetchActiveCertificatesByType()

ilUserCertificateRepositoryTest::testFetchActiveCertificatesByType ( )

Definition at line 246 of file ilUserCertificateRepositoryTest.php.

246 : void
247 {
248 $database = $this->createMock(ilDBInterface::class);
249
250 $database->method('nextId')
251 ->willReturn(141);
252
253 $database->method('fetchAssoc')->willReturnOnConsecutiveCalls(
254 [
255 'id' => 141,
256 'pattern_certificate_id' => 1,
257 'obj_id' => 20,
258 'obj_type' => 'crs',
259 'usr_id' => 400,
260 'user_name' => 'Niels Theen',
261 'acquired_timestamp' => 123_456_789,
262 'certificate_content' => '<xml>Some Content</xml>',
263 'template_values' => '[]',
264 'valid_until' => null,
265 'version' => 1,
266 'ilias_version' => 'v5.4.0',
267 'currently_active' => true,
268 'background_image_ident' => '-',
269 'tile_image_ident' => '-',
270 'title' => 'SomeTitle',
271 'someDescription' => 'SomeDescription',
272 'certificate_id' => '11111111-2222-3333-4444-555555555555'
273 ],
274 [
275 'id' => 142,
276 'pattern_certificate_id' => 5,
277 'obj_id' => 20,
278 'obj_type' => 'crs',
279 'usr_id' => 400,
280 'user_name' => 'Niels Theen',
281 'acquired_timestamp' => 987_654_321,
282 'certificate_content' => '<xml>Some Other Content</xml>',
283 'template_values' => '[]',
284 'valid_until' => null,
285 'version' => 1,
286 'ilias_version' => 'v5.3.0',
287 'currently_active' => true,
288 'background_image_ident' => '-',
289 'tile_image_ident' => '-',
290 'title' => 'SomeTitle',
291 'someDescription' => 'SomeDescription',
292 'certificate_id' => '11111111-2222-3333-4444-555555555555'
293 ],
294 null
295 );
296
297 $logger = $this->getMockBuilder(ilLogger::class)
298 ->disableOriginalConstructor()
299 ->getMock();
300
301 $logger->expects($this->atLeastOnce())
302 ->method('debug');
303
304 $repository = new ilUserCertificateRepository($database, $logger, 'someDefaultTitle');
305
306 $results = $repository->fetchActiveCertificatesByTypeForPresentation(400, 'crs');
307
308 $this->assertSame(141, $results[0]->getUserCertificate()->getId());
309 $this->assertSame(142, $results[1]->getUserCertificate()->getId());
310 }
$results

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

+ Here is the call graph for this function:

◆ testFetchAllActiveCertificateForUser()

ilUserCertificateRepositoryTest::testFetchAllActiveCertificateForUser ( )

Definition at line 89 of file ilUserCertificateRepositoryTest.php.

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

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

+ Here is the call graph for this function:

◆ testFetchCertificate()

ilUserCertificateRepositoryTest::testFetchCertificate ( )

Definition at line 312 of file ilUserCertificateRepositoryTest.php.

312 : void
313 {
314 $database = $this->createMock(ilDBInterface::class);
315
316 $database->method('nextId')
317 ->willReturn(141);
318
319 $database->method('fetchAssoc')->willReturn(
320 [
321 'id' => 141,
322 'pattern_certificate_id' => 1,
323 'obj_id' => 20,
324 'obj_type' => 'crs',
325 'usr_id' => 400,
326 'user_name' => 'Niels Theen',
327 'acquired_timestamp' => 123_456_789,
328 'certificate_content' => '<xml>Some Content</xml>',
329 'template_values' => '[]',
330 'valid_until' => null,
331 'version' => 1,
332 'ilias_version' => 'v5.4.0',
333 'currently_active' => true,
334 'background_image_ident' => '-',
335 'tile_image_ident' => '-',
336 'title' => 'SomeTitle',
337 'someDescription' => 'SomeDescription',
338 'certificate_id' => '11111111-2222-3333-4444-555555555555'
339 ]
340 );
341
342 $logger = $this->getMockBuilder(ilLogger::class)
343 ->disableOriginalConstructor()
344 ->getMock();
345
346 $logger->expects($this->atLeastOnce())
347 ->method('debug');
348
349 $repository = new ilUserCertificateRepository($database, $logger, 'someTitle');
350
351 $result = $repository->fetchCertificate(141);
352
353 $this->assertSame(141, $result->getId());
354 }

◆ testFetchNoActiveCertificateLeadsToException()

ilUserCertificateRepositoryTest::testFetchNoActiveCertificateLeadsToException ( )

Definition at line 221 of file ilUserCertificateRepositoryTest.php.

221 : never
222 {
223 $this->expectException(ilException::class);
224
225 $database = $this->createMock(ilDBInterface::class);
226
227 $database->method('nextId')
228 ->willReturn(141);
229
230 $database->method('fetchAssoc')->willReturn([]);
231
232 $logger = $this->getMockBuilder(ilLogger::class)
233 ->disableOriginalConstructor()
234 ->getMock();
235
236 $logger->expects($this->atLeastOnce())
237 ->method('debug');
238
239 $repository = new ilUserCertificateRepository($database, $logger, 'someDefaultTitle');
240
241 $repository->fetchActiveCertificate(400, 20);
242
243 $this->fail('Should never happen. Certificate Found?');
244 }

◆ testFetchObjectWithCertificateForUser()

ilUserCertificateRepositoryTest::testFetchObjectWithCertificateForUser ( )

Definition at line 382 of file ilUserCertificateRepositoryTest.php.

382 : void
383 {
384 $database = $this->createMock(ilDBInterface::class);
385
386 $database
387 ->expects($this->once())
388 ->method('query');
389
390 $database
391 ->expects($this->once())
392 ->method('in');
393
394 $database
395 ->expects($this->exactly(3))
396 ->method('fetchAssoc')
397 ->willReturnOnConsecutiveCalls(
398 ['obj_id' => 100],
399 ['obj_id' => 300],
400 []
401 );
402
403 $database->method('fetchAssoc')
404 ->willReturn([]);
405
406 $logger = $this->getMockBuilder(ilLogger::class)
407 ->disableOriginalConstructor()
408 ->getMock();
409
410 $logger->expects($this->atLeastOnce())
411 ->method('debug');
412
413 $repository = new ilUserCertificateRepository($database, $logger, 'someTitle');
414
415 $userId = 10;
416 $objectIds = [200, 300, 400];
417
418 $results = $repository->fetchObjectIdsWithCertificateForUser($userId, $objectIds);
419
420 $this->assertSame([100, 300], $results);
421 }

References $results.

◆ testFetchUserIdsWithCertificateForObject()

ilUserCertificateRepositoryTest::testFetchUserIdsWithCertificateForObject ( )

Definition at line 423 of file ilUserCertificateRepositoryTest.php.

423 : void
424 {
425 $database = $this->createMock(ilDBInterface::class);
426
427 $database
428 ->expects($this->once())
429 ->method('query');
430
431 $database
432 ->expects($this->exactly(3))
433 ->method('fetchAssoc')
434 ->willReturnOnConsecutiveCalls(
435 ['usr_id' => 100],
436 ['usr_id' => 300],
437 []
438 );
439
440 $database->method('fetchAssoc')
441 ->willReturn([]);
442
443 $logger = $this->getMockBuilder(ilLogger::class)
444 ->disableOriginalConstructor()
445 ->getMock();
446
447 $logger->expects($this->atLeastOnce())
448 ->method('debug');
449
450 $repository = new ilUserCertificateRepository($database, $logger, 'someTitle');
451
452 $objectId = 10;
453
454 $results = $repository->fetchUserIdsWithCertificateForObject($objectId);
455
456 $this->assertSame([100, 300], $results);
457 }

References $results.

◆ testNoCertificateInFetchtCertificateLeadsToException()

ilUserCertificateRepositoryTest::testNoCertificateInFetchtCertificateLeadsToException ( )

Definition at line 356 of file ilUserCertificateRepositoryTest.php.

356 : never
357 {
358 $this->expectException(ilException::class);
359
360 $database = $this->createMock(ilDBInterface::class);
361
362 $database->method('nextId')
363 ->willReturn(141);
364
365 $database->method('fetchAssoc')
366 ->willReturn([]);
367
368 $logger = $this->getMockBuilder(ilLogger::class)
369 ->disableOriginalConstructor()
370 ->getMock();
371
372 $logger->expects($this->atLeastOnce())
373 ->method('debug');
374
375 $repository = new ilUserCertificateRepository($database, $logger, 'someTitle');
376
377 $repository->fetchCertificate(141);
378
379 $this->fail('Should never happen. Certificate Found?');
380 }

◆ 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_ident' => ['text', '-'],
49 'tile_image_ident' => ['text', '-'],
50 'certificate_id' => ['text', '11111111-2222-3333-4444-555555555555'],
51 ]
52 );
53
54 $logger = $this->getMockBuilder(ilLogger::class)
55 ->disableOriginalConstructor()
56 ->getMock();
57
58 $logger->expects($this->atLeastOnce())
59 ->method('debug');
60
61 $repository = new ilUserCertificateRepository(
62 $database,
63 $logger,
64 'someDefaultTitle'
65 );
66
67 $userCertificate = new ilUserCertificate(
68 1,
69 20,
70 'crs',
71 400,
72 'Niels Theen',
73 123_456_789,
74 '<xml>Some Content</xml>',
75 '[]',
76 null,
77 1,
78 'v5.4.0',
79 true,
80 new CertificateId('11111111-2222-3333-4444-555555555555'),
81 '-',
82 '-',
83 null
84 );
85
86 $repository->save($userCertificate);
87 }

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