19 declare(strict_types=1);
    30         $database = $this->createMock(ilDBInterface::class);
    32         $database->method(
'nextId')
    35         $database->method(
'insert')->with(
    38                 'id' => [
'integer', 141],
    39                 'pattern_certificate_id' => [
'integer', 1],
    40                 'obj_id' => [
'integer', 20],
    41                 'obj_type' => [
'text',  
'crs'],
    42                 'usr_id' => [
'integer', 400],
    43                 'user_name' => [
'text', 
'Niels Theen'],
    44                 'acquired_timestamp' => [
'integer', 123_456_789],
    45                 'certificate_content' => [
'clob', 
'<xml>Some Content</xml>'],
    46                 'template_values' => [
'clob', 
'[]'],
    47                 'valid_until' => [
'integer', null],
    48                 'version' => [
'integer', 1],
    49                 'ilias_version' => [
'text', 
'v5.4.0'],
    50                 'currently_active' => [
'integer', 
true],
    51                 'background_image_path' => [
'text', 
'/some/where/background.jpg'],
    52                 'thumbnail_image_path' => [
'text', 
'/some/where/thumbnail.svg'],
    53                 'background_image_ident' => [
'text', 
'-'],
    54                 'thumbnail_image_ident' => [
'text', 
'-'],
    55                 'certificate_id' => [
'text', 
'11111111-2222-3333-4444-555555555555'],
    59         $database->method(
'tableColumnExists')->willReturnMap(
    61                 [
'il_cert_user_cert', 
'background_image_path', 
true],
    62                 [
'il_cert_user_cert', 
'thumbnail_image_path', 
true],
    66         $logger = $this->getMockBuilder(ilLogger::class)
    67             ->disableOriginalConstructor()
    70         $logger->expects($this->atLeastOnce())
    86             '<xml>Some Content</xml>',
    93             '/some/where/background.jpg',
    94             '/some/where/thumbnail.svg',
   100         $repository->save($userCertificate);
   105         $database = $this->createMock(ilDBInterface::class);
   107         $database->method(
'nextId')
   110         $database->method(
'fetchAssoc')->willReturnOnConsecutiveCalls(
   113                 'pattern_certificate_id' => 1,
   117                 'user_name' => 
'Niels Theen',
   118                 'acquired_timestamp' => 123_456_789,
   119                 'certificate_content' => 
'<xml>Some Content</xml>',
   120                 'template_values' => 
'[]',
   121                 'valid_until' => null,
   123                 'ilias_version' => 
'v5.4.0',
   124                 'currently_active' => 
true,
   125                 'background_image_path' => 
'/some/where/background.jpg',
   126                 'thumbnail_image_path' => 
'/some/where/thumbnail.svg',
   127                 'background_image_ident' => 
'-',
   128                 'thumbnail_image_ident' => 
'-',
   129                 'title' => 
'Some Title',
   130                 'certificate_id' => 
'11111111-2222-3333-4444-555555555555'   134                 'pattern_certificate_id' => 5,
   138                 'user_name' => 
'Niels Theen',
   139                 'acquired_timestamp' => 987_654_321,
   140                 'certificate_content' => 
'<xml>Some Other Content</xml>',
   141                 'template_values' => 
'[]',
   142                 'valid_until' => null,
   144                 'ilias_version' => 
'v5.3.0',
   145                 'currently_active' => 
true,
   146                 'background_image_path' => 
'/some/where/else/background.jpg',
   147                 'thumbnail_image_path' => 
'/some/where/thumbnail.svg',
   148                 'background_image_ident' => 
'-',
   149                 'thumbnail_image_ident' => 
'-',
   150                 'title' => 
'Someother Title',
   151                 'certificate_id' => 
'11111111-2222-3333-4444-555555555555'   156         $logger = $this->getMockBuilder(ilLogger::class)
   157             ->disableOriginalConstructor()
   160         $logger->expects($this->atLeastOnce())
   169         $results = $repository->fetchActiveCertificates(400);
   171         $this->assertSame(141, 
$results[0]->getUserCertificate()->
getId());
   172         $this->assertSame(142, 
$results[1]->getUserCertificate()->
getId());
   177         $database = $this->createMock(ilDBInterface::class);
   179         $database->method(
'nextId')
   182         $database->method(
'fetchAssoc')->willReturnOnConsecutiveCalls(
   185                 'pattern_certificate_id' => 1,
   189                 'user_name' => 
'Niels Theen',
   190                 'acquired_timestamp' => 123_456_789,
   191                 'certificate_content' => 
'<xml>Some Content</xml>',
   192                 'template_values' => 
'[]',
   193                 'valid_until' => null,
   195                 'ilias_version' => 
'v5.4.0',
   196                 'currently_active' => 
true,
   197                 'background_image_path' => 
'/some/where/background.jpg',
   198                 'thumbnail_image_path' => 
'/some/where/thumbnail.svg',
   199                 'background_image_ident' => 
'-',
   200                 'thumbnail_image_ident' => 
'-',
   201                 'certificate_id' => 
'11111111-2222-3333-4444-555555555555'   205                 'pattern_certificate_id' => 5,
   209                 'user_name' => 
'Niels Theen',
   210                 'acquired_timestamp' => 987_654_321,
   211                 'certificate_content' => 
'<xml>Some Other Content</xml>',
   212                 'template_values' => 
'[]',
   213                 'valid_until' => null,
   215                 'ilias_version' => 
'v5.3.0',
   216                 'currently_active' => 
true,
   217                 'background_image_path' => 
'/some/where/else/background.jpg',
   218                 'thumbnail_image_path' => 
'/some/where/thumbnail.svg',
   219                 'background_image_ident' => 
'-',
   220                 'thumbnail_image_ident' => 
'-',
   221                 'certificate_id' => 
'11111111-2222-3333-4444-555555555555'   225         $logger = $this->getMockBuilder(ilLogger::class)
   226             ->disableOriginalConstructor()
   229         $logger->expects($this->atLeastOnce())
   238         $result = $repository->fetchActiveCertificate(400, 20);
   240         $this->assertSame(141, $result->getId());
   248         $this->expectException(ilException::class);
   250         $database = $this->createMock(ilDBInterface::class);
   252         $database->method(
'nextId')
   255         $database->method(
'fetchAssoc')->willReturn([]);
   257         $logger = $this->getMockBuilder(ilLogger::class)
   258             ->disableOriginalConstructor()
   261         $logger->expects($this->atLeastOnce())
   266         $repository->fetchActiveCertificate(400, 20);
   268         $this->fail(
'Should never happen. Certificate Found?');
   273         $database = $this->createMock(ilDBInterface::class);
   275         $database->method(
'nextId')
   278         $database->method(
'fetchAssoc')->willReturnOnConsecutiveCalls(
   281                 'pattern_certificate_id' => 1,
   285                 'user_name' => 
'Niels Theen',
   286                 'acquired_timestamp' => 123_456_789,
   287                 'certificate_content' => 
'<xml>Some Content</xml>',
   288                 'template_values' => 
'[]',
   289                 'valid_until' => null,
   291                 'ilias_version' => 
'v5.4.0',
   292                 'currently_active' => 
true,
   293                 'background_image_path' => 
'/some/where/background.jpg',
   294                 'thumbnail_image_path' => 
'/some/where/else/thumbnail.svg',
   295                 'background_image_ident' => 
'-',
   296                 'thumbnail_image_ident' => 
'-',
   297                 'title' => 
'SomeTitle',
   298                 'someDescription' => 
'SomeDescription',
   299                 'certificate_id' => 
'11111111-2222-3333-4444-555555555555'   303                 'pattern_certificate_id' => 5,
   307                 'user_name' => 
'Niels Theen',
   308                 'acquired_timestamp' => 987_654_321,
   309                 'certificate_content' => 
'<xml>Some Other Content</xml>',
   310                 'template_values' => 
'[]',
   311                 'valid_until' => null,
   313                 'ilias_version' => 
'v5.3.0',
   314                 'currently_active' => 
true,
   315                 'background_image_path' => 
'/some/where/else/background.jpg',
   316                 'thumbnail_image_path' => 
'/some/where/else/thumbnail.svg',
   317                 'background_image_ident' => 
'-',
   318                 'thumbnail_image_ident' => 
'-',
   319                 'title' => 
'SomeTitle',
   320                 'someDescription' => 
'SomeDescription',
   321                 'certificate_id' => 
'11111111-2222-3333-4444-555555555555'   326         $logger = $this->getMockBuilder(ilLogger::class)
   327             ->disableOriginalConstructor()
   330         $logger->expects($this->atLeastOnce())
   335         $results = $repository->fetchActiveCertificatesByTypeForPresentation(400, 
'crs');
   337         $this->assertSame(141, 
$results[0]->getUserCertificate()->
getId());
   338         $this->assertSame(142, 
$results[1]->getUserCertificate()->
getId());
   343         $database = $this->createMock(ilDBInterface::class);
   345         $database->method(
'nextId')
   348         $database->method(
'fetchAssoc')->willReturn(
   351                 'pattern_certificate_id' => 1,
   355                 'user_name' => 
'Niels Theen',
   356                 'acquired_timestamp' => 123_456_789,
   357                 'certificate_content' => 
'<xml>Some Content</xml>',
   358                 'template_values' => 
'[]',
   359                 'valid_until' => null,
   361                 'ilias_version' => 
'v5.4.0',
   362                 'currently_active' => 
true,
   363                 'background_image_path' => 
'/some/where/background.jpg',
   364                 'thumbnail_image_path' => 
'/some/where/else/thumbnail.svg',
   365                 'background_image_ident' => 
'-',
   366                 'thumbnail_image_ident' => 
'-',
   367                 'title' => 
'SomeTitle',
   368                 'someDescription' => 
'SomeDescription',
   369                 'certificate_id' => 
'11111111-2222-3333-4444-555555555555'   373         $logger = $this->getMockBuilder(ilLogger::class)
   374             ->disableOriginalConstructor()
   377         $logger->expects($this->atLeastOnce())
   382         $result = $repository->fetchCertificate(141);
   384         $this->assertSame(141, $result->getId());
   389         $this->expectException(ilException::class);
   391         $database = $this->createMock(ilDBInterface::class);
   393         $database->method(
'nextId')
   396         $database->method(
'fetchAssoc')
   399         $logger = $this->getMockBuilder(ilLogger::class)
   400             ->disableOriginalConstructor()
   403         $logger->expects($this->atLeastOnce())
   408         $repository->fetchCertificate(141);
   410         $this->fail(
'Should never happen. Certificate Found?');
   415         $database = $this->createMock(ilDBInterface::class);
   418             ->expects($this->once())
   422             ->expects($this->once())
   426             ->expects($this->exactly(3))
   427             ->method(
'fetchAssoc')
   428             ->willReturnOnConsecutiveCalls(
   434         $database->method(
'fetchAssoc')
   437         $logger = $this->getMockBuilder(ilLogger::class)
   438             ->disableOriginalConstructor()
   441         $logger->expects($this->atLeastOnce())
   447         $objectIds = [200, 300, 400];
   449         $results = $repository->fetchObjectIdsWithCertificateForUser($userId, $objectIds);
   451         $this->assertSame([100, 300], 
$results);
   456         $database = $this->createMock(ilDBInterface::class);
   459             ->expects($this->once())
   463             ->expects($this->exactly(3))
   464             ->method(
'fetchAssoc')
   465             ->willReturnOnConsecutiveCalls(
   471         $database->method(
'fetchAssoc')
   474         $logger = $this->getMockBuilder(ilLogger::class)
   475             ->disableOriginalConstructor()
   478         $logger->expects($this->atLeastOnce())
   485         $results = $repository->fetchUserIdsWithCertificateForObject($objectId);
   487         $this->assertSame([100, 300], 
$results);
 
testNoCertificateInFetchtCertificateLeadsToException()
 
testFetchUserIdsWithCertificateForObject()
 
testFetchActiveCertificatesByType()
 
Class ilCertificateBaseTestCase. 
 
testFetchObjectWithCertificateForUser()
 
testFetchActiveCertificateForUserObjectCombination()
 
testSaveOfUserCertificateToDatabase()
 
testFetchAllActiveCertificateForUser()
 
testFetchNoActiveCertificateLeadsToException()