ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ilTermsOfServiceDocumentGUITest.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11use PHPUnit\Framework\MockObject\MockObject;
12
18{
21
23 protected $tos;
24
26 protected $tpl;
27
29 protected $ctrl;
30
32 protected $lng;
33
35 protected $rbacsystem;
36
38 protected $error;
39
41 protected $user;
42
44 protected $log;
45
47 protected $uiFactory;
48
50 protected $uiRenderer;
51
53 protected $httpState;
54
56 protected $toolbar;
57
59 protected $fileUpload;
60
62 protected $fileSystems;
63
66
69
73 public function setUp() : void
74 {
75 parent::setUp();
76
77 $this->tos = $this->getMockBuilder(ilObjTermsOfService::class)->disableOriginalConstructor()->getMock();
78 $this->criterionTypeFactory = $this->getMockBuilder(ilTermsOfServiceCriterionTypeFactoryInterface::class)->disableOriginalConstructor()->getMock();
79 $this->tpl = $this->getMockBuilder(ilGlobalPageTemplate::class)->disableOriginalConstructor()->getMock();
80 $this->ctrl = $this->getMockBuilder(ilCtrl::class)->disableOriginalConstructor()->getMock();
81 $this->lng = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock();
82 $this->rbacsystem = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->getMock();
83 $this->error = $this->getMockBuilder(ilErrorHandling::class)->disableOriginalConstructor()->getMock();
84 $this->user = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
85 $this->log = $this->getMockBuilder(ilLogger::class)->disableOriginalConstructor()->getMock();
86 $this->toolbar = $this->getMockBuilder(ilToolbarGUI::class)->disableOriginalConstructor()->getMock();
87 $this->httpState = $this->getMockBuilder(GlobalHttpState::class)->getMock();
88 $this->uiFactory = $this->getMockBuilder(Factory::class)->disableOriginalConstructor()->getMock();
89 $this->uiRenderer = $this->getMockBuilder(Renderer::class)->disableOriginalConstructor()->getMock();
90 $this->fileSystems = $this->getMockBuilder(Filesystems::class)->getMock();
91 $this->fileUpload = $this->getMockBuilder(FileUpload::class)->getMock();
92 $this->tableDataProviderFactory = $this->getMockBuilder(ilTermsOfServiceTableDataProviderFactory::class)->disableOriginalConstructor()->getMock();
93 $this->documentPurifier = $this->getMockBuilder(ilHtmlPurifierInterface::class)->getMock();
94 }
95
99 public function commandProvider() : array
100 {
101 return [
102 ['default_____read', [false]],
103 ['confirmReset', [true, false]],
104 ['reset', [true, false]],
105 ['saveAddDocumentForm', [true, false]],
106 ['showAddDocumentForm', [true, false]],
107 ['saveEditDocumentForm', [true, false]],
108 ['showEditDocumentForm', [true, false]],
109 ['deleteDocuments', [true, false]],
110 ['saveDocumentSorting', [true, false]],
111 ['showAttachCriterionForm', [true, false]],
112 ['saveAttachCriterionForm', [true, false]],
113 ['showChangeCriterionForm', [true, false]],
114 ['saveChangeCriterionForm', [true, false]],
115 ['detachCriterionAssignment', [true, false]]
116 ];
117 }
118
124 public function testAccessDeniedErrorIsRaisedWhenPermissionsAreMissing(string $command, array $accessResults) : void
125 {
126 $this->ctrl
127 ->expects($this->once())
128 ->method('getCmd')
129 ->willReturn($command);
130
131 $accessResultCounter = 0;
132 $this->rbacsystem
133 ->expects($this->exactly(count($accessResults)))
134 ->method('checkAccess')
135 ->willReturnCallback(function () use ($accessResults, &$accessResultCounter) {
136 $result = $accessResults[$accessResultCounter];
137
138 $accessResultCounter++;
139
140 return $result;
141 });
142
143 $this->error
144 ->expects($this->any())
145 ->method('raiseError')
146 ->willThrowException(new ilException('no_permission'));
147
149 $this->tos,
150 $this->criterionTypeFactory,
151 $this->tpl,
152 $this->user,
153 $this->ctrl,
154 $this->lng,
155 $this->rbacsystem,
156 $this->error,
157 $this->log,
158 $this->toolbar,
159 $this->httpState,
160 $this->uiFactory,
161 $this->uiRenderer,
162 $this->fileSystems,
163 $this->fileUpload,
164 $this->tableDataProviderFactory,
165 $this->documentPurifier
166 );
167
168 $this->expectException(ilException::class);
169
170 $gui->executeCommand();
171 }
172
177 {
178 $this->setGlobalVariable('lng', clone $this->lng);
179 $this->setGlobalVariable('ilUser', clone $this->user);
180
181 $lastResetDate = $this->getMockBuilder(ilDate::class)
182 ->disableOriginalConstructor()
183 ->getMock();
184
185 $date = new DateTime();
186
187 $lastResetDate->setDate($date->getTimestamp(), IL_CAL_UNIX);
188
189 $lastResetDate
190 ->expects($this->any())
191 ->method('get')
192 ->willReturn([
193 'seconds' => (int) $date->format('s'),
194 'minutes' => (int) $date->format('i'),
195 'hours' => (int) $date->format('G'),
196 'mday' => (int) $date->format('j'),
197 'wday' => (int) $date->format('w'),
198 'mon' => (int) $date->format('n'),
199 'year' => (int) $date->format('Y'),
200 'yday' => (int) $date->format('z'),
201 'weekday' => $date->format('l'),
202 'month' => $date->format('F'),
203 'isoday' => (int) $date->format('N')
204 ]);
205
206 $lastResetDate
207 ->expects($this->any())
208 ->method('isNull')
209 ->willReturn(true); // Required because of \ilDatePresentation static calls
210
211 $this->tos
212 ->expects($this->any())
213 ->method('getLastResetDate')
214 ->willReturn($lastResetDate);
215
216 $this->ctrl
217 ->expects($this->once())
218 ->method('getCmd')
219 ->willReturn('getResetMessageBoxHtml');
220
221 $this->ctrl
222 ->expects($this->once())
223 ->method('getLinkTarget')
224 ->with($this->isInstanceOf(ilTermsOfServiceDocumentGUI::class), 'confirmReset')
225 ->willReturn('confirmReset');
226
227 $this->rbacsystem
228 ->expects($this->any())
229 ->method('checkAccess')
230 ->willReturn(true);
231
232 $buttonFactory = $this->getMockBuilder(\ILIAS\UI\Component\Button\Factory::class)->getMock();
233 $button = $this->getMockBuilder(Standard::class)->getMock();
234
235 $buttonFactory
236 ->expects($this->once())
237 ->method('standard')
238 ->with($this->isType('string'), $this->equalTo('confirmReset'))
239 ->willReturn($button);
240
241 $this->uiFactory
242 ->expects($this->once())
243 ->method('button')
244 ->willReturn($buttonFactory);
245
246 $messageBoxFactory = $this->getMockBuilder(\ILIAS\UI\Component\MessageBox\Factory::class)->getMock();
247 $info = $this->getMockBuilder(MessageBox::class)->getMock();
248
249 $messageBoxFactory
250 ->expects($this->once())
251 ->method('info')
252 ->with($this->stringContains('Some date:'))
253 ->willReturn($info);
254
255 $info
256 ->expects($this->once())
257 ->method('withButtons')
258 ->with($this->countOf(1));
259
260 $this->uiFactory
261 ->expects($this->once())
262 ->method('messageBox')
263 ->willReturn($messageBoxFactory);
264
265 $this->error
266 ->expects($this->never())
267 ->method('raiseError');
268
269 $this->uiRenderer
270 ->expects($this->atLeast(1))
271 ->method('render')
272 ->willReturn('');
273
274 $this->lng
275 ->expects($this->exactly(2))
276 ->method('txt')
277 ->willReturnOnConsecutiveCalls(
278 'Some date: %s',
279 'Some button text'
280 );
281
283 $this->tos,
284 $this->criterionTypeFactory,
285 $this->tpl,
286 $this->user,
287 $this->ctrl,
288 $this->lng,
289 $this->rbacsystem,
290 $this->error,
291 $this->log,
292 $this->toolbar,
293 $this->httpState,
294 $this->uiFactory,
295 $this->uiRenderer,
296 $this->fileSystems,
297 $this->fileUpload,
298 $this->tableDataProviderFactory,
299 $this->documentPurifier
300 );
301
302 $gui->executeCommand();
303 }
304
309 {
310 $this->setGlobalVariable('lng', clone $this->lng);
311 $this->setGlobalVariable('ilUser', clone $this->user);
312
313 $lastResetDate = $this->getMockBuilder(ilDate::class)
314 ->disableOriginalConstructor()
315 ->getMock();
316
317 $lastResetDate
318 ->expects($this->any())
319 ->method('get')
320 ->willReturn(0);
321 $lastResetDate
322 ->expects($this->any())
323 ->method('isNull')
324 ->willReturn(true);
325
326 $this->tos
327 ->expects($this->any())
328 ->method('getLastResetDate')
329 ->willReturn($lastResetDate);
330
331 $this->ctrl
332 ->expects($this->once())
333 ->method('getCmd')
334 ->willReturn('getResetMessageBoxHtml');
335
336 $this->ctrl
337 ->expects($this->once())
338 ->method('getLinkTarget')
339 ->with($this->isInstanceOf(ilTermsOfServiceDocumentGUI::class), 'confirmReset')
340 ->willReturn('confirmReset');
341
342 $this->rbacsystem
343 ->expects($this->any())
344 ->method('checkAccess')
345 ->willReturn(true);
346
347 $buttonFactory = $this->getMockBuilder(\ILIAS\UI\Component\Button\Factory::class)->getMock();
348 $button = $this->getMockBuilder(Standard::class)->getMock();
349
350 $buttonFactory
351 ->expects($this->once())
352 ->method('standard')
353 ->with($this->isType('string'), $this->equalTo('confirmReset'))
354 ->willReturn($button);
355
356 $this->uiFactory
357 ->expects($this->once())
358 ->method('button')
359 ->willReturn($buttonFactory);
360
361 $messageBoxFactory = $this->getMockBuilder(\ILIAS\UI\Component\MessageBox\Factory::class)->getMock();
362 $info = $this->getMockBuilder(MessageBox::class)->getMock();
363
364 $messageBoxFactory
365 ->expects($this->once())
366 ->method('info')
367 ->with($this->stringContains('Agreements never reset'))
368 ->willReturn($info);
369
370 $info
371 ->expects($this->once())
372 ->method('withButtons')
373 ->with($this->countOf(1));
374
375 $this->uiFactory
376 ->expects($this->once())
377 ->method('messageBox')
378 ->willReturn($messageBoxFactory);
379
380 $this->error
381 ->expects($this->never())
382 ->method('raiseError');
383
384 $this->uiRenderer
385 ->expects($this->atLeast(1))
386 ->method('render')
387 ->willReturn('');
388
389 $this->lng
390 ->expects($this->exactly(2))
391 ->method('txt')
392 ->willReturnOnConsecutiveCalls(
393 'Agreements never reset',
394 'Some button text'
395 );
396
398 $this->tos,
399 $this->criterionTypeFactory,
400 $this->tpl,
401 $this->user,
402 $this->ctrl,
403 $this->lng,
404 $this->rbacsystem,
405 $this->error,
406 $this->log,
407 $this->toolbar,
408 $this->httpState,
409 $this->uiFactory,
410 $this->uiRenderer,
411 $this->fileSystems,
412 $this->fileUpload,
413 $this->tableDataProviderFactory,
414 $this->documentPurifier
415 );
416
417 $gui->executeCommand();
418 }
419}
$result
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
error($a_errmsg)
set error message @access public
Base class for ILIAS Exception handling.
Class ilTermsOfServiceBaseTest.
setGlobalVariable(string $name, $value)
Class ilTermsOfServiceDocumentGUITest.
testAccessDeniedErrorIsRaisedWhenPermissionsAreMissing(string $command, array $accessResults)
@dataProvider commandProvider
Class ilTermsOfServiceDocumentGUI.
Interface GlobalHttpState.
This describes a standard button.
Definition: Standard.php:13
This is how the factory for UI elements looks.
Definition: Factory.php:18
An entity that renders components to a string output.
Definition: Renderer.php:15
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.