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