ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilApiUserCertificateRepositoryTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 {
29  private $database;
31  private $logger;
33  private $controller;
34 
35  protected function setUp(): void
36  {
37  $this->database = $this->createMock(ilDBInterface::class);
38  $this->controller = $this->createMock(ilCtrlInterface::class);
39  $this->logger = $this->getMockBuilder(ilLogger::class)
40  ->disableOriginalConstructor()
41  ->getMock();
42  }
43 
44  public function testGetUserData(): void
45  {
46  $filter = new \ILIAS\Certificate\API\Filter\UserDataFilter();
47 
48  $this->database
49  ->method('fetchAssoc')
50  ->willReturnOnConsecutiveCalls(
51  [
52  'id' => 5,
53  'title' => 'test',
54  'obj_id' => 100,
55  'ref_id' => 5000,
56  'acquired_timestamp' => 1234567890,
57  'usr_id' => 2000,
58  'firstname' => 'ilyas',
59  'lastname' => 'homer',
60  'login' => 'breakdanceMcFunkyPants',
61  'email' => 'ilyas@ilias.de',
62  'second_email' => 'breakdance@funky.de'
63  ],
64  [
65  'id' => 5,
66  'title' => 'test',
67  'obj_id' => 100,
68  'ref_id' => 6000,
69  'acquired_timestamp' => 1234567890,
70  'usr_id' => 2000,
71  'firstname' => 'ilyas',
72  'lastname' => 'homer',
73  'login' => 'breakdanceMcFunkyPants',
74  'email' => 'ilyas@ilias.de',
75  'second_email' => 'breakdance@funky.de'
76  ]
77  );
78 
79  $this->controller->method('getLinkTargetByClass')->willReturn('somewhere.php?goto=4');
80 
81  $repository = new \ILIAS\Certificate\API\Repository\UserDataRepository(
82  $this->database,
83  $this->logger,
84  $this->controller,
85  'no title given'
86  );
87 
89  $userData = $repository->getUserData($filter, ['something']);
90 
92  $object = $userData[5];
93  $this->assertSame('test', $object->getObjectTitle());
94  $this->assertSame(5, $object->getCertificateId());
95  $this->assertSame(100, $object->getObjectId());
96  $this->assertSame([5000, 6000], $object->getObjectRefIds());
97  $this->assertSame(1234567890, $object->getIssuedOnTimestamp());
98  $this->assertSame(2000, $object->getUserId());
99  $this->assertSame('ilyas', $object->getUserFirstName());
100  $this->assertSame('homer', $object->getUserLastName());
101  $this->assertSame('breakdanceMcFunkyPants', $object->getUserLogin());
102  $this->assertSame('ilyas@ilias.de', $object->getUserEmail());
103  $this->assertSame('breakdance@funky.de', $object->getUserSecondEmail());
104  $this->assertSame('somewhere.php?goto=4', $object->getDownloadLink());
105  }
106 }
Class ilCertificateBaseTestCase.