2 namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
17 use Prophecy\Argument;
18 use Prophecy\Prophecy\ObjectProphecy;
19 use TYPO3\CMS\Backend\Form\Exception\AccessDeniedContentEditException;
20 use TYPO3\CMS\Backend\Form\Exception\AccessDeniedEditInternalsException;
21 use TYPO3\CMS\Backend\Form\Exception\AccessDeniedPageEditException;
22 use TYPO3\CMS\Backend\Form\Exception\AccessDeniedPageNewException;
23 use TYPO3\CMS\Backend\Form\Exception\AccessDeniedRootNodeException;
24 use TYPO3\CMS\Backend\Form\Exception\AccessDeniedTableModifyException;
25 use TYPO3\CMS\Backend\Form\Exception\AccessDeniedHookException;
27 use TYPO3\CMS\Core\Tests\UnitTestCase;
50 $this->beUserProphecy = $this->prophesize(BackendUserAuthentication::class);
51 $GLOBALS[
'BE_USER'] = $this->beUserProphecy->reveal();
52 $GLOBALS[
'BE_USER']->user[
'uid'] = 42;
60 $this->beUserProphecy->isAdmin()->willReturn(
true);
62 $result = $this->subject->addData(array());
73 'tableName' =>
'tt_content',
75 $this->beUserProphecy->isAdmin()->willReturn(
false);
76 $this->beUserProphecy->check(
'tables_modify', $input[
'tableName'])->willReturn(
false);
78 $this->setExpectedException(AccessDeniedTableModifyException::class, $this->anything(), 1437683248);
80 $this->subject->addData($input);
89 'tableName' =>
'tt_content',
96 $this->beUserProphecy->isAdmin()->willReturn(
false);
97 $this->beUserProphecy->check(
'tables_modify', $input[
'tableName'])->willReturn(
true);
100 $this->setExpectedException(AccessDeniedContentEditException::class, 1437679657);
102 $this->subject->addData($input);
111 'tableName' =>
'tt_content',
118 $this->beUserProphecy->isAdmin()->willReturn(
false);
119 $this->beUserProphecy->check(
'tables_modify', $input[
'tableName'])->willReturn(
true);
121 $this->beUserProphecy->recordEditAccessInternals($input[
'tableName'], Argument::any())->willReturn(
true);
123 $result = $this->subject->addData($input);
134 'tableName' =>
'pages',
142 $this->beUserProphecy->isAdmin()->willReturn(
false);
143 $this->beUserProphecy->check(
'tables_modify', $input[
'tableName'])->willReturn(
true);
146 $this->setExpectedException(AccessDeniedPageEditException::class, 1437679336);
148 $this->subject->addData($input);
157 'tableName' =>
'pages',
165 $this->beUserProphecy->isAdmin()->willReturn(
false);
166 $this->beUserProphecy->check(
'tables_modify', $input[
'tableName'])->willReturn(
true);
168 $this->beUserProphecy->recordEditAccessInternals($input[
'tableName'], Argument::cetera())->willReturn(
true);
170 $result = $this->subject->addData($input);
181 'tableName' =>
'tt_content',
189 $this->beUserProphecy->isAdmin()->willReturn(
false);
190 $this->beUserProphecy->check(
'tables_modify', $input[
'tableName'])->willReturn(
true);
191 $this->beUserProphecy->recordEditAccessInternals($input[
'tableName'], Argument::cetera())->willReturn(
true);
192 $GLOBALS[
'TCA'][$input[
'tableName']][
'ctrl'][
'security'][
'ignoreRootLevelRestriction'] =
true;
194 $result = $this->subject->addData($input);
205 'tableName' =>
'tt_content',
213 $this->beUserProphecy->isAdmin()->willReturn(
false);
214 $this->beUserProphecy->check(
'tables_modify', $input[
'tableName'])->willReturn(
true);
215 $this->beUserProphecy->recordEditAccessInternals($input[
'tableName'], Argument::cetera())->willReturn(
true);
217 $this->setExpectedException(AccessDeniedRootNodeException::class, $this->anything(), 1437679856);
219 $this->subject->addData($input);
228 'tableName' =>
'tt_content',
236 $this->beUserProphecy->isAdmin()->willReturn(
false);
237 $this->beUserProphecy->check(
'tables_modify', $input[
'tableName'])->willReturn(
true);
238 $this->beUserProphecy->calcPerms($input[
'parentPageRow'])->willReturn(
Permission::ALL);
239 $this->beUserProphecy->recordEditAccessInternals($input[
'tableName'], Argument::cetera())->willReturn(
false);
241 $this->setExpectedException(AccessDeniedEditInternalsException::class, $this->anything(), 1437687404);
243 $this->subject->addData($input);
252 'tableName' =>
'tt_content',
260 $this->beUserProphecy->isAdmin()->willReturn(
false);
261 $this->beUserProphecy->check(
'tables_modify', $input[
'tableName'])->willReturn(
true);
262 $this->beUserProphecy->calcPerms($input[
'parentPageRow'])->willReturn(
Permission::NOTHING);
264 $this->setExpectedException(AccessDeniedContentEditException::class, $this->anything(), 1437745759);
266 $this->subject->addData($input);
275 'tableName' =>
'pages',
283 $this->beUserProphecy->isAdmin()->willReturn(
false);
284 $this->beUserProphecy->check(
'tables_modify', $input[
'tableName'])->willReturn(
true);
285 $this->beUserProphecy->calcPerms($input[
'parentPageRow'])->willReturn(
Permission::NOTHING);
287 $this->setExpectedException(AccessDeniedPageNewException::class, $this->anything(), 1437745640);
289 $this->subject->addData($input);
298 'tableName' =>
'tt_content',
306 $this->beUserProphecy->isAdmin()->willReturn(
false);
307 $this->beUserProphecy->check(
'tables_modify', $input[
'tableName'])->willReturn(
true);
308 $this->beUserProphecy->calcPerms($input[
'parentPageRow'])->willReturn(
Permission::ALL);
309 $this->beUserProphecy->recordEditAccessInternals($input[
'tableName'], Argument::cetera())->willReturn(
true);
311 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'typo3/alt_doc.php'][
'makeEditForm_accessCheck'] = array(
312 'unitTest' =>
function () {
317 $this->setExpectedException(AccessDeniedHookException::class, $this->anything(), 1437689705);
319 $this->subject->addData($input);
328 'tableName' =>
'pages',
336 $this->beUserProphecy->isAdmin()->willReturn(
false);
337 $this->beUserProphecy->check(
'tables_modify', $input[
'tableName'])->willReturn(
true);
339 $this->beUserProphecy->recordEditAccessInternals($input[
'tableName'], Argument::cetera())->willReturn(
true);
341 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'typo3/alt_doc.php'][
'makeEditForm_accessCheck'] = array(
342 'unitTest' =>
function () {
347 $result = $this->subject->addData($input);
358 'tableName' =>
'pages',
366 $this->beUserProphecy->isAdmin()->willReturn(
false);
367 $this->beUserProphecy->check(
'tables_modify', $input[
'tableName'])->willReturn(
true);
369 $this->beUserProphecy->recordEditAccessInternals($input[
'tableName'], Argument::cetera())->willReturn(
true);
371 $result = $this->subject->addData($input);
382 'tableName' =>
'tt_content',
390 $this->beUserProphecy->isAdmin()->willReturn(
false);
391 $this->beUserProphecy->check(
'tables_modify', $input[
'tableName'])->willReturn(
true);
393 $this->beUserProphecy->recordEditAccessInternals($input[
'tableName'], Argument::cetera())->willReturn(
true);
395 $result = $this->subject->addData($input);
406 'tableName' =>
'pages',
409 'parentPageRow' => null,
412 $this->beUserProphecy->isAdmin()->willReturn(
false);
413 $this->beUserProphecy->check(
'tables_modify', $input[
'tableName'])->willReturn(
true);
415 $this->setExpectedException(\RuntimeException::class, $this->anything(), 1437745221);
417 $this->subject->addData($input);