19declare(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_ident' => [
'text',
'-'],
56 'tile_image_ident' => [
'text',
'-']
60 $logger->expects($this->atLeastOnce())
66 '<xml>Some Content</xml>',
67 md5(
'<xml>Some Content</xml>'),
79 $repository->save($template);
84 $logger = $this->getMockBuilder(ilLogger::class)
85 ->disableOriginalConstructor()
88 $database = $this->createMock(ilDBInterface::class);
94 'certificate_content' =>
'<xml>Some Content</xml>',
95 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
96 'template_values' =>
'[]',
98 'ilias_version' =>
'v5.4.0',
99 'created_timestamp' => 123_456_789,
100 'currently_active' =>
true,
101 'background_image_ident' =>
'-',
102 'tile_image_ident' =>
'-'
108 'certificate_content' =>
'<xml>Some Other Content</xml>',
109 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
110 'template_values' =>
'[]',
112 'ilias_version' =>
'v5.3.0',
113 'created_timestamp' => 123_456_789,
114 'currently_active' =>
false,
115 'background_image_ident' =>
'-',
116 'tile_image_ident' =>
'-'
119 $database->method(
'fetchAssoc')->willReturnCallback(
120 function () use (&$consecutive) {
121 return array_shift($consecutive);
125 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
126 ->disableOriginalConstructor()
129 $objectDataCache->method(
'lookUpType')->willReturn(
'crs');
133 $templates = $repository->fetchCertificateTemplatesByObjId(10);
135 $this->assertSame(1, $templates[0]->
getId());
136 $this->assertSame(30, $templates[1]->
getId());
141 $logger = $this->getMockBuilder(ilLogger::class)
142 ->disableOriginalConstructor()
145 $database = $this->createMock(ilDBInterface::class);
151 'certificate_content' =>
'<xml>Some Content</xml>',
152 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
153 'template_values' =>
'[]',
155 'ilias_version' =>
'v5.4.0',
156 'created_timestamp' => 123_456_789,
157 'currently_active' =>
true,
158 'background_image_ident' =>
'-',
159 'tile_image_ident' =>
'-'
165 'certificate_content' =>
'<xml>Some Other Content</xml>',
166 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
167 'template_values' =>
'[]',
169 'ilias_version' =>
'v5.3.0',
170 'created_timestamp' => 123_456_789,
171 'currently_active' =>
false,
172 'background_image_ident' =>
'-',
173 'tile_image_ident' =>
'-'
176 $database->method(
'fetchAssoc')->willReturnCallback(
177 function () use (&$consecutive) {
178 return array_shift($consecutive);
182 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
183 ->disableOriginalConstructor()
186 $objectDataCache->method(
'lookUpType')->willReturn(
'crs');
190 $template = $repository->fetchCurrentlyActiveCertificate(10);
192 $this->assertSame(1, $template->getId());
197 $logger = $this->getMockBuilder(ilLogger::class)
198 ->disableOriginalConstructor()
201 $database = $this->createMock(ilDBInterface::class);
207 'certificate_content' =>
'<xml>Some Content</xml>',
208 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
209 'template_values' =>
'[]',
211 'ilias_version' =>
'v5.4.0',
212 'created_timestamp' => 123_456_789,
213 'currently_active' =>
true,
214 'background_image_ident' =>
'-',
215 'tile_image_ident' =>
'-'
221 'certificate_content' =>
'<xml>Some Other Content</xml>',
222 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
223 'template_values' =>
'[]',
225 'ilias_version' =>
'v5.3.0',
226 'created_timestamp' => 123_456_789,
227 'currently_active' =>
false,
228 'background_image_ident' =>
'-',
229 'tile_image_ident' =>
'-'
232 $database->method(
'fetchAssoc')->willReturnCallback(
233 function () use (&$consecutive) {
234 return array_shift($consecutive);
238 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
239 ->disableOriginalConstructor()
242 $objectDataCache->method(
'lookUpType')->willReturn(
'crs');
246 $template = $repository->fetchPreviousCertificate(10);
248 $this->assertSame(30, $template->getId());
253 $database = $this->createMock(ilDBInterface::class);
255 $logger = $this->getMockBuilder(ilLogger::class)
256 ->disableOriginalConstructor()
259 $quote_consecutive = [
263 $database->method(
'quote')->willReturnCallback(
264 function (
int $v,
string $type) use (&$quote_consecutive) {
265 list($expected, $type) = array_shift($quote_consecutive);
266 $this->assertEquals(
'integer', $type);
267 $this->assertEquals($expected, $v);
268 return (
string) ($v);
273 $database->method(
'query')
275DELETE FROM il_cert_template
279 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
280 ->disableOriginalConstructor()
283 $objectDataCache->method(
'lookUpType')->willReturn(
'crs');
287 $repository->deleteTemplate(10, 200);
292 $logger = $this->getMockBuilder(ilLogger::class)
293 ->disableOriginalConstructor()
296 $database = $this->createMock(ilDBInterface::class);
298 $quote_consecutive = [
302 $database->method(
'quote')->willReturnCallback(
303 function (
int $v,
string $type) use (&$quote_consecutive) {
304 list($expected, $type) = array_shift($quote_consecutive);
305 $this->assertEquals(
'integer', $type);
306 $this->assertEquals($expected, $v);
307 return (
string) ($v);
316 'certificate_content' =>
'<xml>Some Content</xml>',
317 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
318 'template_values' =>
'[]',
320 'ilias_version' =>
'v5.4.0',
321 'created_timestamp' => 123_456_789,
322 'currently_active' =>
true,
323 'background_image_ident' =>
'-',
324 'tile_image_ident' =>
'-'
330 'certificate_content' =>
'<xml>Some Other Content</xml>',
331 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
332 'template_values' =>
'[]',
334 'ilias_version' =>
'v5.3.0',
335 'created_timestamp' => 123_456_789,
336 'currently_active' =>
false,
337 'background_image_ident' =>
'-',
338 'tile_image_ident' =>
'-'
341 $database->method(
'fetchAssoc')->willReturnCallback(
342 function () use (&$consecutive) {
343 return array_shift($consecutive);
347 $query_consecutive = [
348 "SELECT * FROM il_cert_template WHERE obj_id = 10 AND deleted = 0 ORDER BY version ASC",
349 'UPDATE il_cert_template SET currently_active = 1 WHERE id = 30'
351 $database->method(
'query')->willReturnCallback(
352 function (
string $v) use (&$query_consecutive) {
353 $expected = array_shift($query_consecutive);
354 $v = trim(str_replace(array(
"\n",
"\r"),
' ', $v)) ;
355 $this->assertEquals($expected, $v);
356 return $this->createMock(ilDBStatement::class);
360 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
361 ->disableOriginalConstructor()
364 $objectDataCache->method(
'lookUpType')->willReturn(
'crs');
368 $template = $repository->activatePreviousCertificate(10);
370 $this->assertSame(30, $template->getId());
375 $logger = $this->getMockBuilder(ilLogger::class)
376 ->disableOriginalConstructor()
379 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
380 ->disableOriginalConstructor()
384 $database = $this->createMock(ilDBInterface::class);
390 'certificate_content' =>
'<xml>Some Content</xml>',
391 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
392 'template_values' =>
'[]',
394 'ilias_version' =>
'v5.4.0',
395 'created_timestamp' => 123_456_789,
396 'currently_active' =>
true,
397 'background_image_ident' =>
'-',
398 'tile_image_ident' =>
'-'
404 'certificate_content' =>
'<xml>Some Other Content</xml>',
405 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
406 'template_values' =>
'[]',
408 'ilias_version' =>
'v5.3.0',
409 'created_timestamp' => 123_456_789,
410 'currently_active' =>
false,
411 'background_image_ident' =>
'-',
412 'tile_image_ident' =>
'-'
415 $database->method(
'fetchAssoc')->willReturnCallback(
416 function () use (&$consecutive) {
417 return array_shift($consecutive);
423 $templates = $repository->fetchActiveCertificateTemplatesForCoursesWithDisabledLearningProgress(
true);
425 $this->assertSame(10, $templates[0]->getObjId());
426 $this->assertSame(30, $templates[1]->getObjId());
431 $this->expectException(ilException::class);
433 $database = $this->createMock(ilDBInterface::class);
435 $logger = $this->getMockBuilder(ilLogger::class)
436 ->disableOriginalConstructor()
439 $database->method(
'quote')
440 ->with(10,
'integer')
443 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
444 ->disableOriginalConstructor()
447 $database->method(
'fetchAssoc')
450 $database->method(
'fetchAssoc')
455 $repository->fetchFirstCreatedTemplate(10);
462 $database = $this->createMock(ilDBInterface::class);
464 $logger = $this->getMockBuilder(ilLogger::class)
465 ->disableOriginalConstructor()
468 $database->method(
'quote')
469 ->with(10,
'integer')
472 $objectDataCache = $this->getMockBuilder(ilObjectDataCache::class)
473 ->disableOriginalConstructor()
476 $database->method(
'fetchAssoc')
479 $database->method(
'fetchAssoc')->willReturn(
484 'certificate_content' =>
'<xml>Some Content</xml>',
485 'certificate_hash' => md5(
'<xml>Some Content</xml>'),
486 'template_values' =>
'[]',
488 'ilias_version' =>
'v5.4.0',
489 'created_timestamp' => 123_456_789,
490 'currently_active' =>
true,
491 'background_image_ident' =>
'/some/where/background.jpg'
497 $firstTemplate = $repository->fetchFirstCreatedTemplate(10);
499 $this->assertSame(1, $firstTemplate->getId());
testFetchPreviousCertificate()
testFetchCertificateTemplatesByObjId()
testFetchFirstCreatedTemplateFailsBecauseNothingWasSaved()
testFetchAllObjectIdsByType()
fetchFirstCreateTemplate()
testCertificateWillBeSavedToTheDatabase()
testActivatePreviousCertificate()
testDeleteTemplateFromDatabase()
testFetchCurrentlyActiveCertificate()