19declare(strict_types=1);
32use PHPUnit\Framework\TestCase;
46 $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock();
48 $templateRepository->method(
'fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress')
54 '<xml>Some Content</xml>',
55 md5(
'<xml>Some Content</xml>'),
68 '<xml>Some Content</xml>',
69 md5(
'<xml>Some Content</xml>'),
82 $setting = $this->getMockBuilder(ilSetting::class)
83 ->disableOriginalConstructor()
87 [
'cert_subitems_5',
'[10,20]'],
88 [
'cert_subitems_6',
'[10,50]'],
93 function (
string $k) use (&$consecutive_get):
string {
94 list($expected, $ret) = array_shift($consecutive_get);
95 $this->assertEquals($expected, $k);
100 $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
103 $consecutive_lookup = [10, 20, 10, 50];
105 ->method(
'lookupObjId')
106 ->willReturnCallback(
107 function (
int $id) use (&$consecutive_lookup):
int {
108 $expected = array_shift($consecutive_lookup);
109 $this->assertEquals($expected,
$id);
115 $statusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
118 $consecutive_status = [
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);
135 $trackingHelper = $this->getMockBuilder(ilCertificateObjUserTrackingHelper::class)
137 $trackingHelper->method(
'enabledLearningProgress')->willReturn(
true);
147 $completedCourses = $evaluation->evaluate(10, 200);
149 $this->assertSame(5, $completedCourses[0]->getObjId());
154 $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock();
156 $templateRepository->method(
'fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress')
162 '<xml>Some Content</xml>',
163 md5(
'<xml>Some Content</xml>'),
176 '<xml>Some Content</xml>',
177 md5(
'<xml>Some Content</xml>'),
190 $setting = $this->getMockBuilder(ilSetting::class)
191 ->disableOriginalConstructor()
194 $setting = $this->getMockBuilder(ilSetting::class)
195 ->disableOriginalConstructor()
199 [
'cert_subitems_5',
'[10,20]'],
200 [
'cert_subitems_6',
'[10,500]'],
204 ->willReturnCallback(
205 function (
string $k) use (&$consecutive_get):
string {
206 list($expected, $ret) = array_shift($consecutive_get);
207 $this->assertEquals($expected, $k);
212 $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
215 $consecutive_lookup = [
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);
232 $statusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
235 $consecutive_status = [
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);
253 $trackingHelper = $this->getMockBuilder(ilCertificateObjUserTrackingHelper::class)
255 $trackingHelper->method(
'enabledLearningProgress')->willReturn(
false);
265 $completedCourses = $evaluation->evaluate(10, 200);
267 $this->assertSame(5, $completedCourses[0]->getObjId());
268 $this->assertSame(6, $completedCourses[1]->getObjId());
273 $templateRepository = $this->getMockBuilder(ilCertificateTemplateRepository::class)->getMock();
275 $templateRepository->method(
'fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress')
281 '<xml>Some Content</xml>',
282 md5(
'<xml>Some Content</xml>'),
295 '<xml>Some Content</xml>',
296 md5(
'<xml>Some Content</xml>'),
309 $setting = $this->getMockBuilder(ilSetting::class)
310 ->disableOriginalConstructor()
319 ->willReturnCallback(
320 function (
string $k) use (&$consecutive_get) {
321 $expected = array_shift($consecutive_get);
322 $this->assertEquals($expected, $k);
328 $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
331 $statusHelper = $this->getMockBuilder(ilCertificateLPStatusHelper::class)
334 $trackingHelper = $this->getMockBuilder(ilCertificateObjUserTrackingHelper::class)
336 $trackingHelper->method(
'enabledLearningProgress')->willReturn(
false);
346 $completedCourses = $evaluation->evaluate(10, 200);
348 $this->assertSame([], $completedCourses);
354 'LP globally enabled' => [
true, []],
355 'LP globally disabled' => [
true, [
360 'certificate_content' =>
'<xml>Some Content</xml>',
361 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
362 'template_values' =>
'[]',
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' =>
'-'
376 'certificate_content' =>
'<xml>Some Other Content</xml>',
377 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
378 'template_values' =>
'[]',
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' =>
'-'
395 #[\PHPUnit\Framework\Attributes\DataProvider('globalLearningProgressStateProvder')]
397 bool $isGlobalLpEnabled,
398 array $template_recods
400 $statement = $database = $this->getMockBuilder(
ilDBStatement::class)->getMock();
402 $database->method(
'fetch')->willReturnCallback(
static function () use (&$i, $template_recods): ?array {
403 $result = $template_recods[$i] ??
null;
409 $database = $this->createMock(ilDBInterface::class);
410 $database->expects($this->once())->method(
'queryF')->with(
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)),
419 )->willReturn($statement);
420 $database->expects($this->exactly(count($template_recods) + 1))
421 ->method(
'fetchAssoc')
423 ->willReturnCallback(
static function (
ilDBStatement $statement) {
424 return $statement->
fetch(PDO::FETCH_ASSOC);
427 $logger = $this->getMockBuilder(ilLogger::class)
428 ->disableOriginalConstructor()
431 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
432 ->disableOriginalConstructor()
441 $templates = $repository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(
444 $this->assertCount(count($template_recods), $templates);
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) {
462 '<xml>Some Content</xml>',
463 md5(
'<xml>Some Content</xml>'),
476 '<xml>Some Content</xml>',
477 md5(
'<xml>Some Content</xml>'),
491 $result1 = $templateRepository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(
true);
493 $result2 = $templateRepository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(
true);
495 $result3 = $templateRepository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(
false);
497 $result4 = $templateRepository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(
false);
499 $result5 = $templateRepository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(
true);
501 $this->assertSame($result1, $result2);
502 $this->assertSame($result1, $result5);
503 $this->assertCount(0, $result1);
505 $this->assertNotSame($result1, $result3);
506 $this->assertSame($result3, $result4);
507 $this->assertCount(2, $result3);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
testOnlyOneCourseIsCompletedOnLPChange()
testNoSubitemDefinedForEvaluation()
testRetrievingCertificateTemplatesForCoursesWorksAsExpectedWhenUsingNonCachingRepository(bool $isGlobalLpEnabled, array $template_recods)
static globalLearningProgressStateProvder()
testAllCoursesAreCompletedOnLPChange()
testRetrievingCertificateTemplatesForCoursesWillBeCachedWhenCachingRepositoryIsUsed()
A certicate template repository which caches results of query commands List of cached results (other ...
Abstract class ilLPStatus for all learning progress modes E.g ilLPStatusManual, ilLPStatusObjectives ...
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_IN_PROGRESS_NUM
Component logger with individual log levels by component id.
fetch(int $fetch_mode=ilDBConstants::FETCHMODE_ASSOC)