ILIAS  release_8 Revision v8.24
ilUserCertificateRepositoryTest Class Reference
+ Inheritance diagram for ilUserCertificateRepositoryTest:
+ Collaboration diagram for ilUserCertificateRepositoryTest:

Public Member Functions

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

Detailed Description

Member Function Documentation

◆ testFetchActiveCertificateForUserObjectCombination()

ilUserCertificateRepositoryTest::testFetchActiveCertificateForUserObjectCombination ( )

Definition at line 152 of file ilUserCertificateRepositoryTest.php.

152 : void
153 {
154 $database = $this->createMock(ilDBInterface::class);
155
156 $database->method('nextId')
157 ->willReturn(141);
158
159 $database->method('fetchAssoc')->willReturnOnConsecutiveCalls(
160 [
161 'id' => 141,
162 'pattern_certificate_id' => 1,
163 'obj_id' => 20,
164 'obj_type' => 'crs',
165 'usr_id' => 400,
166 'user_name' => 'Niels Theen',
167 'acquired_timestamp' => 123456789,
168 'certificate_content' => '<xml>Some Content</xml>',
169 'template_values' => '[]',
170 'valid_until' => null,
171 'version' => 1,
172 'ilias_version' => 'v5.4.0',
173 'currently_active' => true,
174 'background_image_path' => '/some/where/background.jpg',
175 'thumbnail_image_path' => '/some/where/thumbnail.svg',
176 ],
177 [
178 'id' => 142,
179 'pattern_certificate_id' => 5,
180 'obj_id' => 20,
181 'obj_type' => 'tst',
182 'usr_id' => 400,
183 'user_name' => 'Niels Theen',
184 'acquired_timestamp' => 987654321,
185 'certificate_content' => '<xml>Some Other Content</xml>',
186 'template_values' => '[]',
187 'valid_until' => null,
188 'version' => 1,
189 'ilias_version' => 'v5.3.0',
190 'currently_active' => true,
191 'background_image_path' => '/some/where/else/background.jpg',
192 'thumbnail_image_path' => '/some/where/thumbnail.svg',
193 ]
194 );
195
196 $logger = $this->getMockBuilder(ilLogger::class)
197 ->disableOriginalConstructor()
198 ->getMock();
199
200 $logger->expects($this->atLeastOnce())
201 ->method('debug');
202
203 $repository = new ilUserCertificateRepository(
204 $database,
205 $logger,
206 'someDefaultTitle'
207 );
208
209 $result = $repository->fetchActiveCertificate(400, 20);
210
211 $this->assertSame(141, $result->getId());
212 }

◆ testFetchActiveCertificatesByType()

ilUserCertificateRepositoryTest::testFetchActiveCertificatesByType ( )

Definition at line 242 of file ilUserCertificateRepositoryTest.php.

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

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

+ Here is the call graph for this function:

◆ testFetchAllActiveCertificateForUser()

ilUserCertificateRepositoryTest::testFetchAllActiveCertificateForUser ( )

Definition at line 87 of file ilUserCertificateRepositoryTest.php.

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

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

+ Here is the call graph for this function:

◆ testFetchCertificate()

ilUserCertificateRepositoryTest::testFetchCertificate ( )

Definition at line 305 of file ilUserCertificateRepositoryTest.php.

305 : void
306 {
307 $database = $this->createMock(ilDBInterface::class);
308
309 $database->method('nextId')
310 ->willReturn(141);
311
312 $database->method('fetchAssoc')->willReturn(
313 [
314 'id' => 141,
315 'pattern_certificate_id' => 1,
316 'obj_id' => 20,
317 'obj_type' => 'crs',
318 'usr_id' => 400,
319 'user_name' => 'Niels Theen',
320 'acquired_timestamp' => 123456789,
321 'certificate_content' => '<xml>Some Content</xml>',
322 'template_values' => '[]',
323 'valid_until' => null,
324 'version' => 1,
325 'ilias_version' => 'v5.4.0',
326 'currently_active' => true,
327 'background_image_path' => '/some/where/background.jpg',
328 'thumbnail_image_path' => '/some/where/else/thumbnail.svg',
329 'title' => 'SomeTitle',
330 'someDescription' => 'SomeDescription'
331 ]
332 );
333
334 $logger = $this->getMockBuilder(ilLogger::class)
335 ->disableOriginalConstructor()
336 ->getMock();
337
338 $logger->expects($this->atLeastOnce())
339 ->method('debug');
340
341 $repository = new ilUserCertificateRepository($database, $logger, 'someTitle');
342
343 $result = $repository->fetchCertificate(141);
344
345 $this->assertSame(141, $result->getId());
346 }

◆ testFetchNoActiveCertificateLeadsToException()

ilUserCertificateRepositoryTest::testFetchNoActiveCertificateLeadsToException ( )

Definition at line 217 of file ilUserCertificateRepositoryTest.php.

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

◆ testFetchObjectWithCertificateForUser()

ilUserCertificateRepositoryTest::testFetchObjectWithCertificateForUser ( )

Definition at line 374 of file ilUserCertificateRepositoryTest.php.

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

References $results.

◆ testFetchUserIdsWithCertificateForObject()

ilUserCertificateRepositoryTest::testFetchUserIdsWithCertificateForObject ( )

Definition at line 415 of file ilUserCertificateRepositoryTest.php.

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

References $results.

◆ testNoCertificateInFetchtCertificateLeadsToException()

ilUserCertificateRepositoryTest::testNoCertificateInFetchtCertificateLeadsToException ( )

Definition at line 348 of file ilUserCertificateRepositoryTest.php.

348 : void
349 {
350 $this->expectException(ilException::class);
351
352 $database = $this->createMock(ilDBInterface::class);
353
354 $database->method('nextId')
355 ->willReturn(141);
356
357 $database->method('fetchAssoc')
358 ->willReturn([]);
359
360 $logger = $this->getMockBuilder(ilLogger::class)
361 ->disableOriginalConstructor()
362 ->getMock();
363
364 $logger->expects($this->atLeastOnce())
365 ->method('debug');
366
367 $repository = new ilUserCertificateRepository($database, $logger, 'someTitle');
368
369 $repository->fetchCertificate(141);
370
371 $this->fail('Should never happen. Certificate Found?');
372 }

◆ testSaveOfUserCertificateToDatabase()

ilUserCertificateRepositoryTest::testSaveOfUserCertificateToDatabase ( )

Definition at line 26 of file ilUserCertificateRepositoryTest.php.

26 : void
27 {
28 $database = $this->createMock(ilDBInterface::class);
29
30 $database->method('nextId')
31 ->willReturn(141);
32
33 $database->method('insert')->with(
34 'il_cert_user_cert',
35 [
36 'id' => ['integer', 141],
37 'pattern_certificate_id' => ['integer', 1],
38 'obj_id' => ['integer', 20],
39 'obj_type' => ['text', 'crs'],
40 'usr_id' => ['integer', 400],
41 'user_name' => ['text', 'Niels Theen'],
42 'acquired_timestamp' => ['integer', 123456789],
43 'certificate_content' => ['clob', '<xml>Some Content</xml>'],
44 'template_values' => ['clob', '[]'],
45 'valid_until' => ['integer', null],
46 'version' => ['integer', 1],
47 'ilias_version' => ['text', 'v5.4.0'],
48 'currently_active' => ['integer', true],
49 'background_image_path' => ['text', '/some/where/background.jpg'],
50 'thumbnail_image_path' => ['text', '/some/where/thumbnail.svg'],
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 123456789,
74 '<xml>Some Content</xml>',
75 '[]',
76 null,
77 1,
78 'v5.4.0',
79 true,
80 '/some/where/background.jpg',
81 '/some/where/thumbnail.svg'
82 );
83
84 $repository->save($userCertificate);
85 }

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