19 declare(strict_types=1);
25 $database = $this->createMock(ilDBInterface::class);
27 $logger = $this->getMockBuilder(ilLogger::class)
28 ->disableOriginalConstructor()
31 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
32 ->disableOriginalConstructor()
35 $objectDataCache->method(
'lookUpType')->willReturn(
'crs');
37 $database->method(
'nextId')
40 $database->method(
'insert')
44 'id' => [
'integer', 10],
45 'obj_id' => [
'integer', 100],
46 'obj_type' => [
'text',
'crs'],
47 'certificate_content' => [
'clob',
'<xml>Some Content</xml>'],
48 'certificate_hash' => [
'text', md5(
'<xml>Some Content</xml>')],
49 'template_values' => [
'clob',
'[]'],
50 'version' => [
'integer', 1],
51 'ilias_version' => [
'text',
'v5.4.0'],
52 'created_timestamp' => [
'integer', 123_456_789],
53 'currently_active' => [
'integer',
true],
54 'deleted' => [
'integer', 0],
55 'background_image_path' => [
'text',
'/some/where/background.jpg'],
56 'tile_image_path' => [
'text',
'/some/path/test.svg'],
57 'background_image_ident' => [
'text',
'-'],
58 'tile_image_ident' => [
'text',
'-']
62 $database->method(
'tableColumnExists')->willReturnMap(
64 [
'il_cert_user_cert',
'background_image_path',
true],
65 [
'il_cert_user_cert',
'tile_image_path',
true],
69 $logger->expects($this->atLeastOnce())
75 '<xml>Some Content</xml>',
76 md5(
'<xml>Some Content</xml>'),
82 '/some/where/background.jpg',
83 '/some/path/test.svg',
90 $repository->save($template);
95 $logger = $this->getMockBuilder(ilLogger::class)
96 ->disableOriginalConstructor()
99 $database = $this->createMock(ilDBInterface::class);
105 'certificate_content' =>
'<xml>Some Content</xml>',
106 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
107 'template_values' =>
'[]',
109 'ilias_version' =>
'v5.4.0',
110 'created_timestamp' => 123_456_789,
111 'currently_active' =>
true,
112 'background_image_path' =>
'/some/where/background.jpg',
113 'tile_image_path' =>
'some/path/test.svg',
114 'background_image_ident' =>
'-',
115 'tile_image_ident' =>
'-' 121 'certificate_content' =>
'<xml>Some Other Content</xml>',
122 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
123 'template_values' =>
'[]',
125 'ilias_version' =>
'v5.3.0',
126 'created_timestamp' => 123_456_789,
127 'currently_active' =>
false,
128 'background_image_path' =>
'/some/where/else/background.jpg',
129 'tile_image_path' =>
'some/path/test.svg',
130 'background_image_ident' =>
'-',
131 'tile_image_ident' =>
'-' 134 $database->method(
'fetchAssoc')->willReturnCallback(
135 function () use (&$consecutive) {
136 return array_shift($consecutive);
140 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
141 ->disableOriginalConstructor()
144 $objectDataCache->method(
'lookUpType')->willReturn(
'crs');
148 $templates = $repository->fetchCertificateTemplatesByObjId(10);
150 $this->assertSame(1, $templates[0]->
getId());
151 $this->assertSame(30, $templates[1]->
getId());
156 $logger = $this->getMockBuilder(ilLogger::class)
157 ->disableOriginalConstructor()
160 $database = $this->createMock(ilDBInterface::class);
166 'certificate_content' =>
'<xml>Some Content</xml>',
167 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
168 'template_values' =>
'[]',
170 'ilias_version' =>
'v5.4.0',
171 'created_timestamp' => 123_456_789,
172 'currently_active' =>
true,
173 'background_image_path' =>
'/some/where/background.jpg',
174 'tile_image_path' =>
'some/path/test.svg',
175 'background_image_ident' =>
'-',
176 'tile_image_ident' =>
'-' 182 'certificate_content' =>
'<xml>Some Other Content</xml>',
183 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
184 'template_values' =>
'[]',
186 'ilias_version' =>
'v5.3.0',
187 'created_timestamp' => 123_456_789,
188 'currently_active' =>
false,
189 'background_image_path' =>
'/some/where/else/background.jpg',
190 'tile_image_path' =>
'some/path/test.svg',
191 'background_image_ident' =>
'-',
192 'tile_image_ident' =>
'-' 195 $database->method(
'fetchAssoc')->willReturnCallback(
196 function () use (&$consecutive) {
197 return array_shift($consecutive);
201 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
202 ->disableOriginalConstructor()
205 $objectDataCache->method(
'lookUpType')->willReturn(
'crs');
209 $template = $repository->fetchCurrentlyActiveCertificate(10);
211 $this->assertSame(1, $template->getId());
216 $logger = $this->getMockBuilder(ilLogger::class)
217 ->disableOriginalConstructor()
220 $database = $this->createMock(ilDBInterface::class);
226 'certificate_content' =>
'<xml>Some Content</xml>',
227 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
228 'template_values' =>
'[]',
230 'ilias_version' =>
'v5.4.0',
231 'created_timestamp' => 123_456_789,
232 'currently_active' =>
true,
233 'background_image_path' =>
'/some/where/background.jpg',
234 'tile_image_path' =>
'some/path/test.svg',
235 'background_image_ident' =>
'-',
236 'tile_image_ident' =>
'-' 242 'certificate_content' =>
'<xml>Some Other Content</xml>',
243 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
244 'template_values' =>
'[]',
246 'ilias_version' =>
'v5.3.0',
247 'created_timestamp' => 123_456_789,
248 'currently_active' =>
false,
249 'background_image_path' =>
'/some/where/else/background.jpg',
250 'tile_image_path' =>
'some/path/test.svg',
251 'background_image_ident' =>
'-',
252 'tile_image_ident' =>
'-' 255 $database->method(
'fetchAssoc')->willReturnCallback(
256 function () use (&$consecutive) {
257 return array_shift($consecutive);
261 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
262 ->disableOriginalConstructor()
265 $objectDataCache->method(
'lookUpType')->willReturn(
'crs');
269 $template = $repository->fetchPreviousCertificate(10);
271 $this->assertSame(30, $template->getId());
276 $database = $this->createMock(ilDBInterface::class);
278 $logger = $this->getMockBuilder(ilLogger::class)
279 ->disableOriginalConstructor()
282 $quote_consecutive = [
286 $database->method(
'quote')->willReturnCallback(
287 function (
int $v,
string $type) use (&$quote_consecutive) {
288 list($expected, $type) = array_shift($quote_consecutive);
289 $this->assertEquals(
'integer', $type);
290 $this->assertEquals($expected, $v);
291 return (
string) ($v);
296 $database->method(
'query')
298 DELETE FROM il_cert_template 302 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
303 ->disableOriginalConstructor()
306 $objectDataCache->method(
'lookUpType')->willReturn(
'crs');
310 $repository->deleteTemplate(10, 200);
315 $logger = $this->getMockBuilder(ilLogger::class)
316 ->disableOriginalConstructor()
319 $database = $this->createMock(ilDBInterface::class);
321 $quote_consecutive = [
325 $database->method(
'quote')->willReturnCallback(
326 function (
int $v,
string $type) use (&$quote_consecutive) {
327 list($expected, $type) = array_shift($quote_consecutive);
328 $this->assertEquals(
'integer', $type);
329 $this->assertEquals($expected, $v);
330 return (
string) ($v);
339 'certificate_content' =>
'<xml>Some Content</xml>',
340 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
341 'template_values' =>
'[]',
343 'ilias_version' =>
'v5.4.0',
344 'created_timestamp' => 123_456_789,
345 'currently_active' =>
true,
346 'background_image_path' =>
'/some/where/background.jpg',
347 'tile_image_path' =>
'some/path/test.svg',
348 'background_image_ident' =>
'-',
349 'tile_image_ident' =>
'-' 355 'certificate_content' =>
'<xml>Some Other Content</xml>',
356 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
357 'template_values' =>
'[]',
359 'ilias_version' =>
'v5.3.0',
360 'created_timestamp' => 123_456_789,
361 'currently_active' =>
false,
362 'background_image_path' =>
'/some/where/else/background.jpg',
363 'tile_image_path' =>
'some/path/test.svg',
364 'background_image_ident' =>
'-',
365 'tile_image_ident' =>
'-' 368 $database->method(
'fetchAssoc')->willReturnCallback(
369 function () use (&$consecutive) {
370 return array_shift($consecutive);
374 $query_consecutive = [
375 "SELECT * FROM il_cert_template WHERE obj_id = 10 AND deleted = 0 ORDER BY version ASC",
376 'UPDATE il_cert_template SET currently_active = 1 WHERE id = 30' 378 $database->method(
'query')->willReturnCallback(
379 function (
string $v) use (&$query_consecutive) {
380 $expected = array_shift($query_consecutive);
381 $v = trim(str_replace(array(
"\n",
"\r"),
' ', $v)) ;
382 $this->assertEquals($expected, $v);
383 return $this->createMock(ilDBStatement::class);
387 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
388 ->disableOriginalConstructor()
391 $objectDataCache->method(
'lookUpType')->willReturn(
'crs');
395 $template = $repository->activatePreviousCertificate(10);
397 $this->assertSame(30, $template->getId());
402 $logger = $this->getMockBuilder(ilLogger::class)
403 ->disableOriginalConstructor()
406 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
407 ->disableOriginalConstructor()
411 $database = $this->createMock(ilDBInterface::class);
417 'certificate_content' =>
'<xml>Some Content</xml>',
418 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
419 'template_values' =>
'[]',
421 'ilias_version' =>
'v5.4.0',
422 'created_timestamp' => 123_456_789,
423 'currently_active' =>
true,
424 'background_image_path' =>
'/some/where/background.jpg',
425 'tile_image_path' =>
'/some/where/tile_image.svg',
426 'background_image_ident' =>
'-',
427 'tile_image_ident' =>
'-' 433 'certificate_content' =>
'<xml>Some Other Content</xml>',
434 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
435 'template_values' =>
'[]',
437 'ilias_version' =>
'v5.3.0',
438 'created_timestamp' => 123_456_789,
439 'currently_active' =>
false,
440 'background_image_path' =>
'/some/where/else/background.jpg',
441 'tile_image_path' =>
'/some/where/tile_image.svg',
442 'background_image_ident' =>
'-',
443 'tile_image_ident' =>
'-' 446 $database->method(
'fetchAssoc')->willReturnCallback(
447 function () use (&$consecutive) {
448 return array_shift($consecutive);
454 $templates = $repository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(
true);
456 $this->assertSame(10, $templates[0]->getObjId());
457 $this->assertSame(30, $templates[1]->getObjId());
462 $this->expectException(ilException::class);
464 $database = $this->createMock(ilDBInterface::class);
466 $logger = $this->getMockBuilder(ilLogger::class)
467 ->disableOriginalConstructor()
470 $database->method(
'quote')
471 ->with(10,
'integer')
474 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
475 ->disableOriginalConstructor()
478 $database->method(
'fetchAssoc')
481 $database->method(
'fetchAssoc')
486 $repository->fetchFirstCreatedTemplate(10);
493 $database = $this->createMock(ilDBInterface::class);
495 $logger = $this->getMockBuilder(ilLogger::class)
496 ->disableOriginalConstructor()
499 $database->method(
'quote')
500 ->with(10,
'integer')
503 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
504 ->disableOriginalConstructor()
507 $database->method(
'fetchAssoc')
510 $database->method(
'fetchAssoc')->willReturn(
515 'certificate_content' =>
'<xml>Some Content</xml>',
516 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
517 'template_values' =>
'[]',
519 'ilias_version' =>
'v5.4.0',
520 'created_timestamp' => 123_456_789,
521 'currently_active' =>
true,
522 'background_image_ident' =>
'/some/where/background.jpg' 528 $firstTemplate = $repository->fetchFirstCreatedTemplate(10);
530 $this->assertSame(1, $firstTemplate->getId());
testFetchPreviousCertificate()
testActivatePreviousCertificate()
testFetchAllObjectIdsByType()
testDeleteTemplateFromDatabase()
testFetchFirstCreatedTemplateFailsBecauseNothingWasSaved()
testFetchCertificateTemplatesByObjId()
fetchFirstCreateTemplate()
testFetchCurrentlyActiveCertificate()
testCertificateWillBeSavedToTheDatabase()