ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilCertificateCourseLearningProgressEvaluationTest Class Reference
+ Inheritance diagram for ilCertificateCourseLearningProgressEvaluationTest:
+ Collaboration diagram for ilCertificateCourseLearningProgressEvaluationTest:

Public Member Functions

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

Additional Inherited Members

- Protected Member Functions inherited from ilCertificateBaseTestCase
 setUp ()
 
 setGlobalVariable (string $name, $value)
 

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' => 123_456_789,
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' => 123_456_789,
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.

References ilLPStatus\LP_STATUS_COMPLETED_NUM.

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  123_456_789,
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  123_456_789,
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

◆ 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  123_456_789,
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  123_456_789,
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.

References ilLPStatus\LP_STATUS_COMPLETED_NUM, and ilLPStatus\LP_STATUS_IN_PROGRESS_NUM.

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  123_456_789,
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  123_456_789,
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_COMPLETED_NUM
const LP_STATUS_IN_PROGRESS_NUM

◆ testRetrievingCertificateTemplatesForCoursesWillBeCachedWhenCachingRepositoryIsUsed()

ilCertificateCourseLearningProgressEvaluationTest::testRetrievingCertificateTemplatesForCoursesWillBeCachedWhenCachingRepositoryIsUsed ( )

Definition at line 393 of file ilCertificateCourseLearningProgressEvaluationTest.php.

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

◆ testRetrievingCertificateTemplatesForCoursesWorksAsExpectedWhenUsingNonCachingRepository()

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

globalLearningProgressStateProvder

Parameters
array[]$template_recods

Definition at line 342 of file ilCertificateCourseLearningProgressEvaluationTest.php.

References ilDBStatement\fetch().

345  : void {
346  $statement = $database = $this->getMockBuilder(ilDBStatement::class)->getMock();
347  $i = 0;
348  $database->method('fetch')->willReturnCallback(static function () use (&$i, $template_recods): ?array {
349  $result = $template_recods[$i] ?? null;
350  ++$i;
351 
352  return $result;
353  });
354 
355  $database = $this->createMock(ilDBInterface::class);
356  $database->expects($this->once())->method('queryF')->with(
357  $isGlobalLpEnabled
358  ? $this->logicalAnd(
359  $this->stringContains('LEFT JOIN ut_lp_settings', false),
360  $this->stringContains('uls.u_mode', false),
361  ) : $this->logicalAnd(
362  $this->logicalNot($this->stringContains('LEFT JOIN ut_lp_settings', false)),
363  $this->logicalNot($this->stringContains('uls.u_mode', false)),
364  )
365  )->willReturn($statement);
366  $database->expects($this->exactly(count($template_recods) + 1))
367  ->method('fetchAssoc')
368  ->with($statement)
369  ->willReturnCallback(static function (ilDBStatement $statement) {
370  return $statement->fetch(PDO::FETCH_ASSOC);
371  });
372 
373  $logger = $this->getMockBuilder(ilLogger::class)
374  ->disableOriginalConstructor()
375  ->getMock();
376 
377  $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
378  ->disableOriginalConstructor()
379  ->getMock();
380 
381  $repository = new ilCertificateTemplateDatabaseRepository(
382  $database,
383  $logger,
384  $objectDataCache
385  );
386 
387  $templates = $repository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(
388  $isGlobalLpEnabled
389  );
390  $this->assertCount(count($template_recods), $templates);
391  }
fetch(int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)
+ Here is the call graph for this function:

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