ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilDefaultPlaceholderValuesTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  public function testGetPlaceholderValues(): void
24  {
25  $objectMock = $this->getMockBuilder(ilObjUser::class)
26  ->disableOriginalConstructor()
27  ->onlyMethods(
28  [
29  'getLogin',
30  'getFullname',
31  'getFirstname',
32  'getLastname',
33  'getUTitle',
34  'getGender',
35  'getBirthday',
36  'getInstitution',
37  'getDepartment',
38  'getStreet',
39  'getCity',
40  'getZipcode',
41  'getCountry',
42  'getMatriculation'
43  ]
44  )
45  ->getMock();
46 
47  $objectMock->expects($this->once())
48  ->method('getLogin')
49  ->willReturn('a_login');
50 
51  $objectMock->expects($this->once())
52  ->method('getFullname')
53  ->willReturn('Niels Theen');
54 
55  $objectMock->expects($this->once())
56  ->method('getFirstname')
57  ->willReturn('Niels');
58 
59  $objectMock->expects($this->once())
60  ->method('getLastname')
61  ->willReturn('Theen');
62 
63  $objectMock->expects($this->once())
64  ->method('getUTitle')
65  ->willReturn('');
66 
67  $objectMock->expects($this->once())
68  ->method('getGender')
69  ->willReturn('m');
70 
71  $objectMock->expects($this->once())
72  ->method('getBirthday')
73  ->willReturn('2018-10-10');
74 
75  $objectMock->expects($this->once())
76  ->method('getInstitution')
77  ->willReturn('');
78 
79  $objectMock->expects($this->once())
80  ->method('getDepartment')
81  ->willReturn('');
82 
83  $objectMock->expects($this->once())
84  ->method('getStreet')
85  ->willReturn('');
86 
87  $objectMock->expects($this->once())
88  ->method('getCity')
89  ->willReturn('');
90 
91  $objectMock->expects($this->once())
92  ->method('getZipcode')
93  ->willReturn('');
94 
95  $objectMock->expects($this->once())
96  ->method('getCountry')
97  ->willReturn('');
98 
99  $objectMock->expects($this->once())
100  ->method('getMatriculation')
101  ->willReturn('');
102 
103  $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
104  ->getMock();
105 
106  $objectHelper->expects($this->once())
107  ->method('getInstanceByObjId')
108  ->with(100)
109  ->willReturn($objectMock);
110 
111  $dateHelper = $this->getMockBuilder(ilCertificateDateHelper::class)
112  ->getMock();
113 
114  $dateHelper->expects($this->exactly(2))
115  ->method('formatDate')
116  ->willReturn('2018-09-10');
117 
118  $dateHelper->expects($this->once())
119  ->method('formatDateTime')
120  ->willReturn('2018-09-10 12:01:33');
121 
122  $language = $this->getMockBuilder(ilLanguage::class)
123  ->disableOriginalConstructor()
124  ->getMock();
125 
126  $language->method('txt')
127  ->willReturn('Something');
128 
129  $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
130  ->disableOriginalConstructor()
131  ->getMock();
132 
133  $utilHelper->method('prepareFormOutput')
134  ->willReturnCallback(function ($input) {
135  return $input;
136  });
137 
138  $userDefinePlaceholderMock = $this->getMockBuilder(ilUserDefinedFieldsPlaceholderValues::class)
139  ->disableOriginalConstructor()
140  ->getMock();
141 
142  $userDefinePlaceholderMock->method('getPlaceholderValues')
143  ->willReturn([]);
144 
145  $userDefinePlaceholderMock->method('getPlaceholderValuesForPreview')
146  ->willReturn([]);
147 
148  $uuid_factory_mock = $this->getMockBuilder(ILIAS\Data\UUID\Factory::class)
149  ->getMock();
150  $uuid_factory_mock->method('uuid4AsString')->willReturn('randomUniqueString');
151 
152  $placeHolderObject = new ilDefaultPlaceholderValues(
153  $objectHelper,
154  $dateHelper,
155  3,
156  $language,
157  $utilHelper,
158  $userDefinePlaceholderMock,
159  $uuid_factory_mock,
160  2
161  );
162  $placeHolderObject->setUserLanguage($language);
163 
164  $result = $placeHolderObject->getPlaceholderValues(100, 200);
165 
166  $this->assertEquals(
167  [
168  'CERTIFICATE_ID' => '',
169  'USER_LOGIN' => 'a_login',
170  'USER_FULLNAME' => 'Niels Theen',
171  'USER_FIRSTNAME' => 'Niels',
172  'USER_LASTNAME' => 'Theen',
173  'USER_TITLE' => '',
174  'USER_SALUTATION' => 'Something',
175  'USER_BIRTHDAY' => '2018-09-10',
176  'USER_INSTITUTION' => '',
177  'USER_DEPARTMENT' => '',
178  'USER_STREET' => '',
179  'USER_CITY' => '',
180  'USER_ZIPCODE' => '',
181  'USER_COUNTRY' => '',
182  'USER_MATRICULATION' => '',
183  'DATE_COMPLETED' => '',
184  'DATETIME_COMPLETED' => '',
185  'DATE' => '2018-09-10',
186  'DATETIME' => '2018-09-10 12:01:33'
187  ],
188  $result
189  );
190  }
191 
192  public function testGetPlaceholderValuesForPreview(): void
193  {
194  $objectHelper = $this->getMockBuilder(ilCertificateObjectHelper::class)
195  ->getMock();
196 
197  $dateHelper = $this->getMockBuilder(ilCertificateDateHelper::class)
198  ->getMock();
199 
200  $dateHelper->method('formatDate')
201  ->willReturn('2018-09-09');
202 
203  $dateHelper->method('formatDateTime')
204  ->willReturn('2018-09-09 14:00:30');
205 
206  $language = $this->getMockBuilder(ilLanguage::class)
207  ->disableOriginalConstructor()
208  ->getMock();
209 
210  $language->method('txt')
211  ->willReturn('Something');
212 
213  $utilHelper = $this->getMockBuilder(ilCertificateUtilHelper::class)
214  ->disableOriginalConstructor()
215  ->getMock();
216 
217  $utilHelper->method('prepareFormOutput')
218  ->willReturnCallback(function ($input) {
219  return $input;
220  });
221 
222  $userDefinePlaceholderMock = $this->getMockBuilder(ilUserDefinedFieldsPlaceholderValues::class)
223  ->disableOriginalConstructor()
224  ->getMock();
225 
226  $userDefinePlaceholderMock->method('getPlaceholderValues')
227  ->willReturn([]);
228 
229  $userDefinePlaceholderMock->method('getPlaceholderValuesForPreview')
230  ->willReturn([]);
231 
232  $uuid_factory_mock = $this->getMockBuilder(ILIAS\Data\UUID\Factory::class)
233  ->getMock();
234  $uuid_factory_mock->method('uuid4AsString')->willReturn('randomUniqueString');
235 
236  $placeHolderObject = new ilDefaultPlaceholderValues(
237  $objectHelper,
238  $dateHelper,
239  3,
240  $language,
241  $utilHelper,
242  $userDefinePlaceholderMock,
243  $uuid_factory_mock,
244  2
245  );
246 
247  $result = $placeHolderObject->getPlaceholderValuesForPreview(
248  100,
249  10
250  );
251 
252  $this->assertSame(
253  [
254  'CERTIFICATE_ID' => 'randomUniqueString',
255  'USER_LOGIN' => 'Something',
256  'USER_FULLNAME' => 'Something',
257  'USER_FIRSTNAME' => 'Something',
258  'USER_LASTNAME' => 'Something',
259  'USER_TITLE' => 'Something',
260  'USER_SALUTATION' => 'Something',
261  'USER_BIRTHDAY' => '2018-09-09',
262  'USER_INSTITUTION' => 'Something',
263  'USER_DEPARTMENT' => 'Something',
264  'USER_STREET' => 'Something',
265  'USER_CITY' => 'Something',
266  'USER_ZIPCODE' => 'Something',
267  'USER_COUNTRY' => 'Something',
268  'USER_MATRICULATION' => 'Something',
269  'DATE' => '2018-09-09',
270  'DATETIME' => '2018-09-09 14:00:30',
271  'DATE_COMPLETED' => '2018-09-09',
272  'DATETIME_COMPLETED' => '2018-09-09 14:00:30'
273  ],
274  $result
275  );
276  }
277 }
Interface Observer Contains several chained tasks and infos about them.