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