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

Public Member Functions

 testOnlyOneCourseIsCompletedOnLPChange ()
 
 testAllCoursesAreCompletedOnLPChange ()
 
 testNoSubitemDefinedForEvaluation ()
 
 globalLearningProgressStateProvder ()
 
 testRetrievingCertificateTemplatesForCoursesWorksAsExpectedWhenUsingNonCachingRepository (bool $isGlobalLpEnabled, array $template_recods)
 @dataProvider globalLearningProgressStateProvder More...
 
 testRetrievingCertificateTemplatesForCoursesWillBeCachedWhenCachingRepositoryIsUsed ()
 

Detailed Description

Member Function Documentation

◆ globalLearningProgressStateProvder()

ilCertificateCourseLearningProgressEvaluationTest::globalLearningProgressStateProvder ( )

Definition at line 301 of file ilCertificateCourseLearningProgressEvaluationTest.php.

301 : array
302 {
303 return [
304 'LP globally enabled' => [true, []],
305 'LP globally disabled' => [true, [
306 [
307 'id' => 1,
308 'obj_id' => 10,
309 'obj_type' => 'crs',
310 'certificate_content' => '<xml>Some Content</xml>',
311 'certificate_hash' => md5('<xml>Some Content</xml>'),
312 'template_values' => '[]',
313 'version' => 1,
314 'ilias_version' => 'v5.4.0',
315 'created_timestamp' => 123456789,
316 'currently_active' => true,
317 'background_image_path' => '/some/where/background.jpg',
318 'thumbnail_image_path' => 'some/path/test.svg'
319 ],
320 [
321 'id' => 30,
322 'obj_id' => 10,
323 'obj_type' => 'tst',
324 'certificate_content' => '<xml>Some Other Content</xml>',
325 'certificate_hash' => md5('<xml>Some Content</xml>'),
326 'template_values' => '[]',
327 'version' => 55,
328 'ilias_version' => 'v5.3.0',
329 'created_timestamp' => 123456789,
330 'currently_active' => false,
331 'background_image_path' => '/some/where/else/background.jpg',
332 'thumbnail_image_path' => 'some/path/test.svg'
333 ]
334 ]],
335 ];
336 }

◆ testAllCoursesAreCompletedOnLPChange()

ilCertificateCourseLearningProgressEvaluationTest::testAllCoursesAreCompletedOnLPChange ( )

Definition at line 125 of file ilCertificateCourseLearningProgressEvaluationTest.php.

125 : void
126 {
127 $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock();
128
129 $templateRepository->method('fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress')
130 ->willReturn(
131 [
133 5,
134 'crs',
135 '<xml>Some Content</xml>',
136 md5('<xml>Some Content</xml>'),
137 '[]',
138 1,
139 'v5.4.0',
140 123456789,
141 true,
142 '/some/where/background.jpg',
143 '/some/where/thumbnail.svg',
144 1
145 ),
147 6,
148 'crs',
149 '<xml>Some Content</xml>',
150 md5('<xml>Some Content</xml>'),
151 '[]',
152 1,
153 'v5.4.0',
154 123456789,
155 true,
156 '/some/where/background.jpg',
157 '/some/where/thumbnail.svg',
158 5
159 ),
160 ]
161 );
162
163 $setting = $this->getMockBuilder(ilSetting::class)
164 ->disableOriginalConstructor()
165 ->getMock();
166
167 $setting
168 ->method('get')
169 ->withConsecutive(
170 ['cert_subitems_5'],
171 ['cert_subitems_6']
172 )
173 ->willReturnOnConsecutiveCalls(
174 '[10,20]',
175 '[10,500]'
176 );
177
178 $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
179 ->getMock();
180
181 $objectHelper->method('lookupObjId')
182 ->withConsecutive(
183 [10],
184 [20],
185 [10],
186 [500]
187 )
188 ->willReturnOnConsecutiveCalls(100, 200, 100, 500);
189
190 $statusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
191 ->getMock();
192
193 $statusHelper->method('lookUpStatus')
194 ->withConsecutive(
195 [100],
196 [200],
197 [100],
198 [500]
199 )
200 ->willReturnOnConsecutiveCalls(
205 );
206
207 $trackingHelper = $this->getMockBuilder(ilCertificateObjUserTrackingHelper::class)
208 ->getMock();
209 $trackingHelper->method('enabledLearningProgress')->willReturn(false);
210
212 $templateRepository,
213 $setting,
214 $objectHelper,
215 $statusHelper,
216 $trackingHelper
217 );
218
219 $completedCourses = $evaluation->evaluate(10, 200);
220
221 $this->assertSame(5, $completedCourses[0]->getObjId());
222 $this->assertSame(6, $completedCourses[1]->getObjId());
223 }
const LP_STATUS_COMPLETED_NUM

References ilLPStatus\LP_STATUS_COMPLETED_NUM.

◆ testNoSubitemDefinedForEvaluation()

ilCertificateCourseLearningProgressEvaluationTest::testNoSubitemDefinedForEvaluation ( )

Definition at line 225 of file ilCertificateCourseLearningProgressEvaluationTest.php.

225 : void
226 {
227 $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock();
228
229 $templateRepository->method('fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress')
230 ->willReturn(
231 [
233 5,
234 'crs',
235 '<xml>Some Content</xml>',
236 md5('<xml>Some Content</xml>'),
237 '[]',
238 1,
239 'v5.4.0',
240 123456789,
241 true,
242 '/some/where/background.jpg',
243 '/some/where/thumbnail.svg',
244 1
245 ),
247 6,
248 'crs',
249 '<xml>Some Content</xml>',
250 md5('<xml>Some Content</xml>'),
251 '[]',
252 1,
253 'v5.4.0',
254 123456789,
255 true,
256 '/some/where/background.jpg',
257 '/some/where/thumbnail.svg',
258 5
259 ),
260 ]
261 );
262
263 $setting = $this->getMockBuilder(ilSetting::class)
264 ->disableOriginalConstructor()
265 ->getMock();
266
267 $setting
268 ->method('get')
269 ->withConsecutive(
270 ['cert_subitems_5'],
271 ['cert_subitems_6']
272 )
273 ->willReturnOnConsecutiveCalls(
274 null,
275 null
276 );
277
278 $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
279 ->getMock();
280
281 $statusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
282 ->getMock();
283
284 $trackingHelper = $this->getMockBuilder(ilCertificateObjUserTrackingHelper::class)
285 ->getMock();
286 $trackingHelper->method('enabledLearningProgress')->willReturn(false);
287
289 $templateRepository,
290 $setting,
291 $objectHelper,
292 $statusHelper,
293 $trackingHelper
294 );
295
296 $completedCourses = $evaluation->evaluate(10, 200);
297
298 $this->assertSame([], $completedCourses);
299 }

◆ testOnlyOneCourseIsCompletedOnLPChange()

ilCertificateCourseLearningProgressEvaluationTest::testOnlyOneCourseIsCompletedOnLPChange ( )

Definition at line 26 of file ilCertificateCourseLearningProgressEvaluationTest.php.

26 : void
27 {
28 $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock();
29
30 $templateRepository->method('fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress')
31 ->willReturn(
32 [
34 5,
35 'crs',
36 '<xml>Some Content</xml>',
37 md5('<xml>Some Content</xml>'),
38 '[]',
39 1,
40 'v5.4.0',
41 123456789,
42 true,
43 '/some/where/background.jpg',
44 '/some/where/thumbnail.svg',
45 1
46 ),
48 6,
49 'crs',
50 '<xml>Some Content</xml>',
51 md5('<xml>Some Content</xml>'),
52 '[]',
53 1,
54 'v5.4.0',
55 123456789,
56 true,
57 '/some/where/background.jpg',
58 '/some/where/thumbnail.svg',
59 5
60 ),
61 ]
62 );
63
64 $setting = $this->getMockBuilder(ilSetting::class)
65 ->disableOriginalConstructor()
66 ->getMock();
67
68 $setting
69 ->method('get')
70 ->withConsecutive(
71 ['cert_subitems_5'],
72 ['cert_subitems_6']
73 )
74 ->willReturnOnConsecutiveCalls(
75 '[10,20]',
76 '[10,50]'
77 );
78
79 $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
80 ->getMock();
81
82 $objectHelper->method('lookupObjId')
83 ->withConsecutive(
84 [10],
85 [20],
86 [10],
87 [50]
88 )
89 ->willReturnOnConsecutiveCalls(100, 200, 100, 500);
90
91 $statusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
92 ->getMock();
93
94 $statusHelper->method('lookUpStatus')
95 ->withConsecutive(
96 [100],
97 [200],
98 [100],
99 [500]
100 )
101 ->willReturnOnConsecutiveCalls(
106 );
107
108 $trackingHelper = $this->getMockBuilder(ilCertificateObjUserTrackingHelper::class)
109 ->getMock();
110 $trackingHelper->method('enabledLearningProgress')->willReturn(true);
111
113 $templateRepository,
114 $setting,
115 $objectHelper,
116 $statusHelper,
117 $trackingHelper
118 );
119
120 $completedCourses = $evaluation->evaluate(10, 200);
121
122 $this->assertSame(5, $completedCourses[0]->getObjId());
123 }
const LP_STATUS_IN_PROGRESS_NUM

References ilLPStatus\LP_STATUS_COMPLETED_NUM, and ilLPStatus\LP_STATUS_IN_PROGRESS_NUM.

◆ testRetrievingCertificateTemplatesForCoursesWillBeCachedWhenCachingRepositoryIsUsed()

ilCertificateCourseLearningProgressEvaluationTest::testRetrievingCertificateTemplatesForCoursesWillBeCachedWhenCachingRepositoryIsUsed ( )

Definition at line 394 of file ilCertificateCourseLearningProgressEvaluationTest.php.

394 : void
395 {
396 $wrappedTemplateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock();
397 $wrappedTemplateRepository
398 ->expects($this->exactly(2))
399 ->method('fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress')
400 ->willReturnCallback(static function (bool $isGlobalLpEnabled): array {
401 if ($isGlobalLpEnabled) {
402 return [];
403 }
404
405 return [
407 5,
408 'crs',
409 '<xml>Some Content</xml>',
410 md5('<xml>Some Content</xml>'),
411 '[]',
412 1,
413 'v5.4.0',
414 123456789,
415 true,
416 '/some/where/background.jpg',
417 '/some/where/thumbnail.svg',
418 1
419 ),
421 6,
422 'crs',
423 '<xml>Some Content</xml>',
424 md5('<xml>Some Content</xml>'),
425 '[]',
426 1,
427 'v5.4.0',
428 123456789,
429 true,
430 '/some/where/background.jpg',
431 '/some/where/thumbnail.svg',
432 5
433 ),
434 ];
435 });
436 $templateRepository = new ilCachedCertificateTemplateRepository($wrappedTemplateRepository);
437
438 $result1 = $templateRepository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(true);
439 // Do not delegate to wrapped repository again
440 $result2 = $templateRepository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(true);
441 // Should be delegated
442 $result3 = $templateRepository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(false);
443 // Do not delegate to wrapped repository again
444 $result4 = $templateRepository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(false);
445 // Do not delegate to wrapped repository again
446 $result5 = $templateRepository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(true);
447
448 $this->assertSame($result1, $result2);
449 $this->assertSame($result1, $result5);
450 $this->assertCount(0, $result1);
451
452 $this->assertNotSame($result1, $result3);
453 $this->assertSame($result3, $result4);
454 $this->assertCount(2, $result3);
455 }
A certicate template repository which caches results of query commands List of cached results (other ...

◆ testRetrievingCertificateTemplatesForCoursesWorksAsExpectedWhenUsingNonCachingRepository()

ilCertificateCourseLearningProgressEvaluationTest::testRetrievingCertificateTemplatesForCoursesWorksAsExpectedWhenUsingNonCachingRepository ( bool  $isGlobalLpEnabled,
array  $template_recods 
)

@dataProvider globalLearningProgressStateProvder

Parameters
bool$isGlobalLpEnabled
ilCertificateTemplate[]$template_recods

Definition at line 343 of file ilCertificateCourseLearningProgressEvaluationTest.php.

346 : void {
347 $statement = $database = $this->getMockBuilder(ilDBStatement::class)->getMock();
348 $i = 0;
349 $database->method('fetch')->willReturnCallback(static function () use (&$i, $template_recods) {
350 $result = $template_recods[$i] ?? null;
351 ++$i;
352
353 return $result;
354 });
355
356 $database = $this->createMock(ilDBInterface::class);
357 $database->expects($this->once())->method('queryF')->with(
358 $isGlobalLpEnabled
359 ? $this->logicalAnd(
360 $this->stringContains('LEFT JOIN ut_lp_settings', false),
361 $this->stringContains('uls.u_mode', false),
362 ) : $this->logicalAnd(
363 $this->logicalNot($this->stringContains('LEFT JOIN ut_lp_settings', false)),
364 $this->logicalNot($this->stringContains('uls.u_mode', false)),
365 )
366 )->willReturn($statement);
367 $database->expects($this->exactly(count($template_recods) + 1))
368 ->method('fetchAssoc')
369 ->with($statement)
370 ->willReturnCallback(static function (ilDBStatement $statement) {
371 return $statement->fetch(PDO::FETCH_ASSOC);
372 });
373
374 $logger = $this->getMockBuilder(ilLogger::class)
375 ->disableOriginalConstructor()
376 ->getMock();
377
378 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
379 ->disableOriginalConstructor()
380 ->getMock();
381
383 $database,
384 $logger,
385 $objectDataCache
386 );
387
388 $templates = $repository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(
389 $isGlobalLpEnabled
390 );
391 $this->assertCount(count($template_recods), $templates);
392 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fetch(int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
$i
Definition: metadata.php:41

References $i.


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