ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ILIAS\Course\Certificate\ilCertificateCourseLearningProgressEvaluationTest Class Reference
+ Inheritance diagram for ILIAS\Course\Certificate\ilCertificateCourseLearningProgressEvaluationTest:
+ Collaboration diagram for ILIAS\Course\Certificate\ilCertificateCourseLearningProgressEvaluationTest:

Public Member Functions

 testOnlyOneCourseIsCompletedOnLPChange ()
 
 testAllCoursesAreCompletedOnLPChange ()
 
 testNoSubitemDefinedForEvaluation ()
 
 testRetrievingCertificateTemplatesForCoursesWorksAsExpectedWhenUsingNonCachingRepository (bool $isGlobalLpEnabled, array $template_recods)
 
 testRetrievingCertificateTemplatesForCoursesWillBeCachedWhenCachingRepositoryIsUsed ()
 

Static Public Member Functions

static globalLearningProgressStateProvder ()
 

Detailed Description

Member Function Documentation

◆ globalLearningProgressStateProvder()

static ILIAS\Course\Certificate\ilCertificateCourseLearningProgressEvaluationTest::globalLearningProgressStateProvder ( )
static

Definition at line 351 of file ilCertificateCourseLearningProgressEvaluationTest.php.

351 : array
352 {
353 return [
354 'LP globally enabled' => [true, []],
355 'LP globally disabled' => [true, [
356 [
357 'id' => 1,
358 'obj_id' => 10,
359 'obj_type' => 'crs',
360 'certificate_content' => '<xml>Some Content</xml>',
361 'certificate_hash' => md5('<xml>Some Content</xml>'),
362 'template_values' => '[]',
363 'version' => 1,
364 'ilias_version' => 'v5.4.0',
365 'created_timestamp' => 123_456_789,
366 'currently_active' => true,
367 'background_image_path' => '/some/where/background.jpg',
368 'thumbnail_image_path' => 'some/path/test.svg',
369 'background_image_ident' => '-',
370 'thumbnail_image_ident' => '-'
371 ],
372 [
373 'id' => 30,
374 'obj_id' => 10,
375 'obj_type' => 'tst',
376 'certificate_content' => '<xml>Some Other Content</xml>',
377 'certificate_hash' => md5('<xml>Some Content</xml>'),
378 'template_values' => '[]',
379 'version' => 55,
380 'ilias_version' => 'v5.3.0',
381 'created_timestamp' => 123_456_789,
382 'currently_active' => false,
383 'background_image_path' => '/some/where/else/background.jpg',
384 'thumbnail_image_path' => 'some/path/test.svg',
385 'background_image_ident' => '-',
386 'thumbnail_image_ident' => '-'
387 ]
388 ]],
389 ];
390 }

◆ testAllCoursesAreCompletedOnLPChange()

ILIAS\Course\Certificate\ilCertificateCourseLearningProgressEvaluationTest::testAllCoursesAreCompletedOnLPChange ( )

Definition at line 152 of file ilCertificateCourseLearningProgressEvaluationTest.php.

152 : void
153 {
154 $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock();
155
156 $templateRepository->method('fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress')
157 ->willReturn(
158 [
160 5,
161 'crs',
162 '<xml>Some Content</xml>',
163 md5('<xml>Some Content</xml>'),
164 '[]',
165 1,
166 'v5.4.0',
167 123_456_789,
168 true,
169 '-',
170 '-',
171 1
172 ),
174 6,
175 'crs',
176 '<xml>Some Content</xml>',
177 md5('<xml>Some Content</xml>'),
178 '[]',
179 1,
180 'v5.4.0',
181 123_456_789,
182 true,
183 '-',
184 '-',
185 5
186 ),
187 ]
188 );
189
190 $setting = $this->getMockBuilder(ilSetting::class)
191 ->disableOriginalConstructor()
192 ->getMock();
193
194 $setting = $this->getMockBuilder(ilSetting::class)
195 ->disableOriginalConstructor()
196 ->getMock();
197
198 $consecutive_get = [
199 ['cert_subitems_5', '[10,20]'],
200 ['cert_subitems_6', '[10,500]'],
201 ];
203 ->method('get')
204 ->willReturnCallback(
205 function (string $k) use (&$consecutive_get): string {
206 list($expected, $ret) = array_shift($consecutive_get);
207 $this->assertEquals($expected, $k);
208 return $ret;
209 }
210 );
211
212 $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
213 ->getMock();
214
215 $consecutive_lookup = [
216 [10, 100],
217 [20, 200],
218 [10, 100],
219 [500, 500],
220 ];
221 $objectHelper
222 ->method('lookupObjId')
223 ->willReturnCallback(
224 function (int $id) use (&$consecutive_lookup): int {
225 list($expected, $ret) = array_shift($consecutive_lookup);
226 $this->assertEquals($expected, $id);
227
228 return $ret;
229 }
230 );
231
232 $statusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
233 ->getMock();
234
235 $consecutive_status = [
240 ];
241
242 $statusHelper
243 ->method('lookUpStatus')
244 ->willReturnCallback(
245 function (int $id) use (&$consecutive_status): int {
246 list($expected, $ret) = array_shift($consecutive_status);
247 $this->assertEquals($expected, $id);
248
249 return $ret;
250 }
251 );
252
253 $trackingHelper = $this->getMockBuilder(ilCertificateObjUserTrackingHelper::class)
254 ->getMock();
255 $trackingHelper->method('enabledLearningProgress')->willReturn(false);
256
257 $evaluation = new CertificateCourseLearningProgressEvaluation(
258 $templateRepository,
259 $setting,
260 $objectHelper,
261 $statusHelper,
262 $trackingHelper
263 );
264
265 $completedCourses = $evaluation->evaluate(10, 200);
266
267 $this->assertSame(5, $completedCourses[0]->getObjId());
268 $this->assertSame(6, $completedCourses[1]->getObjId());
269 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
ilSetting $setting
Definition: class.ilias.php:68
const LP_STATUS_COMPLETED_NUM

References $id, ILIAS\$setting, and ilLPStatus\LP_STATUS_COMPLETED_NUM.

◆ testNoSubitemDefinedForEvaluation()

ILIAS\Course\Certificate\ilCertificateCourseLearningProgressEvaluationTest::testNoSubitemDefinedForEvaluation ( )

Definition at line 271 of file ilCertificateCourseLearningProgressEvaluationTest.php.

271 : void
272 {
273 $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock();
274
275 $templateRepository->method('fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress')
276 ->willReturn(
277 [
279 5,
280 'crs',
281 '<xml>Some Content</xml>',
282 md5('<xml>Some Content</xml>'),
283 '[]',
284 1,
285 'v5.4.0',
286 123_456_789,
287 true,
288 '-',
289 '-',
290 1
291 ),
293 6,
294 'crs',
295 '<xml>Some Content</xml>',
296 md5('<xml>Some Content</xml>'),
297 '[]',
298 1,
299 'v5.4.0',
300 123_456_789,
301 true,
302 '-',
303 '-',
304 5
305 ),
306 ]
307 );
308
309 $setting = $this->getMockBuilder(ilSetting::class)
310 ->disableOriginalConstructor()
311 ->getMock();
312
313 $consecutive_get = [
314 'cert_subitems_5',
315 'cert_subitems_6',
316 ];
318 ->method('get')
319 ->willReturnCallback(
320 function (string $k) use (&$consecutive_get) {
321 $expected = array_shift($consecutive_get);
322 $this->assertEquals($expected, $k);
323
324 return null;
325 }
326 );
327
328 $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
329 ->getMock();
330
331 $statusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
332 ->getMock();
333
334 $trackingHelper = $this->getMockBuilder(ilCertificateObjUserTrackingHelper::class)
335 ->getMock();
336 $trackingHelper->method('enabledLearningProgress')->willReturn(false);
337
338 $evaluation = new CertificateCourseLearningProgressEvaluation(
339 $templateRepository,
340 $setting,
341 $objectHelper,
342 $statusHelper,
343 $trackingHelper
344 );
345
346 $completedCourses = $evaluation->evaluate(10, 200);
347
348 $this->assertSame([], $completedCourses);
349 }

References ILIAS\$setting.

◆ testOnlyOneCourseIsCompletedOnLPChange()

ILIAS\Course\Certificate\ilCertificateCourseLearningProgressEvaluationTest::testOnlyOneCourseIsCompletedOnLPChange ( )

Definition at line 44 of file ilCertificateCourseLearningProgressEvaluationTest.php.

44 : void
45 {
46 $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock();
47
48 $templateRepository->method('fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress')
49 ->willReturn(
50 [
52 5,
53 'crs',
54 '<xml>Some Content</xml>',
55 md5('<xml>Some Content</xml>'),
56 '[]',
57 1,
58 'v5.4.0',
59 123_456_789,
60 true,
61 '-',
62 '-',
63 1
64 ),
66 6,
67 'crs',
68 '<xml>Some Content</xml>',
69 md5('<xml>Some Content</xml>'),
70 '[]',
71 1,
72 'v5.4.0',
73 123_456_789,
74 true,
75 '-',
76 '-',
77 5
78 ),
79 ]
80 );
81
82 $setting = $this->getMockBuilder(ilSetting::class)
83 ->disableOriginalConstructor()
84 ->getMock();
85
86 $consecutive_get = [
87 ['cert_subitems_5', '[10,20]'],
88 ['cert_subitems_6', '[10,50]'],
89 ];
91 ->method('get')
92 ->willReturnCallback(
93 function (string $k) use (&$consecutive_get): string {
94 list($expected, $ret) = array_shift($consecutive_get);
95 $this->assertEquals($expected, $k);
96 return $ret;
97 }
98 );
99
100 $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
101 ->getMock();
102
103 $consecutive_lookup = [10, 20, 10, 50];
104 $objectHelper
105 ->method('lookupObjId')
106 ->willReturnCallback(
107 function (int $id) use (&$consecutive_lookup): int {
108 $expected = array_shift($consecutive_lookup);
109 $this->assertEquals($expected, $id);
110
111 return $id * 10;
112 }
113 );
114
115 $statusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
116 ->getMock();
117
118 $consecutive_status = [
123 ];
124 $statusHelper
125 ->method('lookUpStatus')
126 ->willReturnCallback(
127 function (int $id) use (&$consecutive_status): int {
128 list($expected, $ret) = array_shift($consecutive_status);
129 $this->assertEquals($expected, $id);
130
131 return $ret;
132 }
133 );
134
135 $trackingHelper = $this->getMockBuilder(ilCertificateObjUserTrackingHelper::class)
136 ->getMock();
137 $trackingHelper->method('enabledLearningProgress')->willReturn(true);
138
139 $evaluation = new CertificateCourseLearningProgressEvaluation(
140 $templateRepository,
141 $setting,
142 $objectHelper,
143 $statusHelper,
144 $trackingHelper
145 );
146
147 $completedCourses = $evaluation->evaluate(10, 200);
148
149 $this->assertSame(5, $completedCourses[0]->getObjId());
150 }
const LP_STATUS_IN_PROGRESS_NUM

References $id, ILIAS\$setting, ilLPStatus\LP_STATUS_COMPLETED_NUM, and ilLPStatus\LP_STATUS_IN_PROGRESS_NUM.

◆ testRetrievingCertificateTemplatesForCoursesWillBeCachedWhenCachingRepositoryIsUsed()

ILIAS\Course\Certificate\ilCertificateCourseLearningProgressEvaluationTest::testRetrievingCertificateTemplatesForCoursesWillBeCachedWhenCachingRepositoryIsUsed ( )

Definition at line 447 of file ilCertificateCourseLearningProgressEvaluationTest.php.

447 : void
448 {
449 $wrappedTemplateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock();
450 $wrappedTemplateRepository
451 ->expects($this->exactly(2))
452 ->method('fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress')
453 ->willReturnCallback(static function (bool $isGlobalLpEnabled): array {
454 if ($isGlobalLpEnabled) {
455 return [];
456 }
457
458 return [
460 5,
461 'crs',
462 '<xml>Some Content</xml>',
463 md5('<xml>Some Content</xml>'),
464 '[]',
465 1,
466 'v5.4.0',
467 123_456_789,
468 true,
469 '-',
470 '-',
471 1
472 ),
474 6,
475 'crs',
476 '<xml>Some Content</xml>',
477 md5('<xml>Some Content</xml>'),
478 '[]',
479 1,
480 'v5.4.0',
481 123_456_789,
482 true,
483 '-',
484 '-',
485 5
486 ),
487 ];
488 });
489 $templateRepository = new ilCachedCertificateTemplateRepository($wrappedTemplateRepository);
490
491 $result1 = $templateRepository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(true);
492 // Do not delegate to wrapped repository again
493 $result2 = $templateRepository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(true);
494 // Should be delegated
495 $result3 = $templateRepository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(false);
496 // Do not delegate to wrapped repository again
497 $result4 = $templateRepository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(false);
498 // Do not delegate to wrapped repository again
499 $result5 = $templateRepository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(true);
500
501 $this->assertSame($result1, $result2);
502 $this->assertSame($result1, $result5);
503 $this->assertCount(0, $result1);
504
505 $this->assertNotSame($result1, $result3);
506 $this->assertSame($result3, $result4);
507 $this->assertCount(2, $result3);
508 }
A certicate template repository which caches results of query commands List of cached results (other ...

◆ testRetrievingCertificateTemplatesForCoursesWorksAsExpectedWhenUsingNonCachingRepository()

ILIAS\Course\Certificate\ilCertificateCourseLearningProgressEvaluationTest::testRetrievingCertificateTemplatesForCoursesWorksAsExpectedWhenUsingNonCachingRepository ( bool  $isGlobalLpEnabled,
array  $template_recods 
)
Parameters
array[]$template_recods

Definition at line 396 of file ilCertificateCourseLearningProgressEvaluationTest.php.

399 : void {
400 $statement = $database = $this->getMockBuilder(ilDBStatement::class)->getMock();
401 $i = 0;
402 $database->method('fetch')->willReturnCallback(static function () use (&$i, $template_recods): ?array {
403 $result = $template_recods[$i] ?? null;
404 ++$i;
405
406 return $result;
407 });
408
409 $database = $this->createMock(ilDBInterface::class);
410 $database->expects($this->once())->method('queryF')->with(
411 $isGlobalLpEnabled
412 ? $this->logicalAnd(
413 $this->stringContains('LEFT JOIN ut_lp_settings', false),
414 $this->stringContains('uls.u_mode', false),
415 ) : $this->logicalAnd(
416 $this->logicalNot($this->stringContains('LEFT JOIN ut_lp_settings', false)),
417 $this->logicalNot($this->stringContains('uls.u_mode', false)),
418 )
419 )->willReturn($statement);
420 $database->expects($this->exactly(count($template_recods) + 1))
421 ->method('fetchAssoc')
422 ->with($statement)
423 ->willReturnCallback(static function (ilDBStatement $statement) {
424 return $statement->fetch(PDO::FETCH_ASSOC);
425 });
426
427 $logger = $this->getMockBuilder(ilLogger::class)
428 ->disableOriginalConstructor()
429 ->getMock();
430
431 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
432 ->disableOriginalConstructor()
433 ->getMock();
434
436 $database,
437 $logger,
438 $objectDataCache
439 );
440
441 $templates = $repository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(
442 $isGlobalLpEnabled
443 );
444 $this->assertCount(count($template_recods), $templates);
445 }
Interface ilDBStatement.
fetch(int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)

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