[TASK] Doctrine: Migrate BackendUserAuthentication::getPagePermsClause
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Authentication / BackendUserAuthenticationTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Authentication;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Prophecy\Argument;
18 use Prophecy\Prophecy\ObjectProphecy;
19 use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
20 use TYPO3\CMS\Core\Database\Connection;
21 use TYPO3\CMS\Core\Database\ConnectionPool;
22 use TYPO3\CMS\Core\Database\DatabaseConnection;
23 use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
24 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
25 use TYPO3\CMS\Core\Tests\Unit\Database\Mocks\MockPlatform;
26 use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation;
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28
29 /**
30 * Testcase for BackendUserAuthentication
31 */
32 class BackendUserAuthenticationTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
33 {
34 /**
35 * @var array
36 */
37 protected $defaultFilePermissions = array(
38 // File permissions
39 'addFile' => false,
40 'readFile' => false,
41 'writeFile' => false,
42 'copyFile' => false,
43 'moveFile' => false,
44 'renameFile' => false,
45 'deleteFile' => false,
46 // Folder permissions
47 'addFolder' => false,
48 'readFolder' => false,
49 'writeFolder' => false,
50 'copyFolder' => false,
51 'moveFolder' => false,
52 'renameFolder' => false,
53 'deleteFolder' => false,
54 'recursivedeleteFolder' => false
55 );
56
57 protected function setUp()
58 {
59 // reset hooks
60 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'] = array();
61 }
62
63 protected function tearDown()
64 {
65 \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::purgeInstances();
66 parent::tearDown();
67 }
68
69 /////////////////////////////////////////
70 // Tests concerning the form protection
71 /////////////////////////////////////////
72 /**
73 * @test
74 */
75 public function logoffCleansFormProtectionIfBackendUserIsLoggedIn()
76 {
77 /** @var ObjectProphecy|Connection $connection */
78 $connection = $this->prophesize(Connection::class);
79 $connection->delete('be_sessions', Argument::cetera())->willReturn(1);
80
81 /** @var ObjectProphecy|ConnectionPool $connectionPool */
82 $connectionPool = $this->prophesize(ConnectionPool::class);
83 $connectionPool->getConnectionForTable(Argument::cetera())->willReturn($connection->reveal());
84
85 GeneralUtility::addInstance(ConnectionPool::class, $connectionPool->reveal());
86
87 /** @var ObjectProphecy|\TYPO3\CMS\Core\FormProtection\AbstractFormProtection $formProtection */
88 $formProtection = $this->prophesize(\TYPO3\CMS\Core\FormProtection\BackendFormProtection::class);
89 $formProtection->clean()->shouldBeCalled();
90
91 \TYPO3\CMS\Core\FormProtection\FormProtectionFactory::set(
92 'default',
93 $formProtection->reveal()
94 );
95
96 // logoff() call the static factory that has a dependency to a valid BE_USER object. Mock this away
97 $GLOBALS['BE_USER'] = $this->getMock(BackendUserAuthentication::class, array(), array(), '', false);
98 $GLOBALS['BE_USER']->user = array('uid' => $this->getUniqueId());
99 $GLOBALS['TYPO3_DB'] = $this->getMock(DatabaseConnection::class, array(), array(), '', false);
100
101 /** @var BackendUserAuthentication|\PHPUnit_Framework_MockObject_MockObject $subject */
102 $subject = $this->getMock(BackendUserAuthentication::class, array('dummy'), array(), '', false);
103 $subject->logoff();
104 }
105
106 /**
107 * @return array
108 */
109 public function getTSConfigDataProvider()
110 {
111 $completeConfiguration = array(
112 'value' => 'oneValue',
113 'value.' => array('oneProperty' => 'oneValue'),
114 'permissions.' => array(
115 'file.' => array(
116 'default.' => array('readAction' => '1'),
117 '1.' => array('writeAction' => '1'),
118 '0.' => array('readAction' => '0'),
119 ),
120 )
121 );
122
123 return array(
124 'single level string' => array(
125 $completeConfiguration,
126 'permissions',
127 array(
128 'value' => null,
129 'properties' =>
130 array(
131 'file.' => array(
132 'default.' => array('readAction' => '1'),
133 '1.' => array('writeAction' => '1'),
134 '0.' => array('readAction' => '0'),
135 ),
136 ),
137 ),
138 ),
139 'two levels string' => array(
140 $completeConfiguration,
141 'permissions.file',
142 array(
143 'value' => null,
144 'properties' =>
145 array(
146 'default.' => array('readAction' => '1'),
147 '1.' => array('writeAction' => '1'),
148 '0.' => array('readAction' => '0'),
149 ),
150 ),
151 ),
152 'three levels string' => array(
153 $completeConfiguration,
154 'permissions.file.default',
155 array(
156 'value' => null,
157 'properties' =>
158 array('readAction' => '1'),
159 ),
160 ),
161 'three levels string with integer property' => array(
162 $completeConfiguration,
163 'permissions.file.1',
164 array(
165 'value' => null,
166 'properties' => array('writeAction' => '1'),
167 ),
168 ),
169 'three levels string with integer zero property' => array(
170 $completeConfiguration,
171 'permissions.file.0',
172 array(
173 'value' => null,
174 'properties' => array('readAction' => '0'),
175 ),
176 ),
177 'four levels string with integer zero property, value, no properties' => array(
178 $completeConfiguration,
179 'permissions.file.0.readAction',
180 array(
181 'value' => '0',
182 'properties' => null,
183 ),
184 ),
185 'four levels string with integer property, value, no properties' => array(
186 $completeConfiguration,
187 'permissions.file.1.writeAction',
188 array(
189 'value' => '1',
190 'properties' => null,
191 ),
192 ),
193 'one level, not existent string' => array(
194 $completeConfiguration,
195 'foo',
196 array(
197 'value' => null,
198 'properties' => null,
199 ),
200 ),
201 'two level, not existent string' => array(
202 $completeConfiguration,
203 'foo.bar',
204 array(
205 'value' => null,
206 'properties' => null,
207 ),
208 ),
209 'two level, where second level does not exist' => array(
210 $completeConfiguration,
211 'permissions.bar',
212 array(
213 'value' => null,
214 'properties' => null,
215 ),
216 ),
217 'three level, where third level does not exist' => array(
218 $completeConfiguration,
219 'permissions.file.foo',
220 array(
221 'value' => null,
222 'properties' => null,
223 ),
224 ),
225 'three level, where second and third level does not exist' => array(
226 $completeConfiguration,
227 'permissions.foo.bar',
228 array(
229 'value' => null,
230 'properties' => null,
231 ),
232 ),
233 'value and properties' => array(
234 $completeConfiguration,
235 'value',
236 array(
237 'value' => 'oneValue',
238 'properties' => array('oneProperty' => 'oneValue'),
239 ),
240 ),
241 );
242 }
243
244 /**
245 * @param array $completeConfiguration
246 * @param string $objectString
247 * @param array $expectedConfiguration
248 * @dataProvider getTSConfigDataProvider
249 * @test
250 */
251 public function getTSConfigReturnsCorrectArrayForGivenObjectString(array $completeConfiguration, $objectString, array $expectedConfiguration)
252 {
253 $subject = $this->getMock(BackendUserAuthentication::class, array('dummy'), array(), '', false);
254 $subject->userTS = $completeConfiguration;
255
256 $actualConfiguration = $subject->getTSConfig($objectString);
257 $this->assertSame($expectedConfiguration, $actualConfiguration);
258 }
259
260 /**
261 * @return array
262 */
263 public function getFilePermissionsTakesUserDefaultAndStoragePermissionsIntoAccountIfUserIsNotAdminDataProvider()
264 {
265 return array(
266 'Only read permissions' => array(
267 array(
268 'addFile' => 0,
269 'readFile' => 1,
270 'writeFile' => 0,
271 'copyFile' => 0,
272 'moveFile' => 0,
273 'renameFile' => 0,
274 'deleteFile' => 0,
275 'addFolder' => 0,
276 'readFolder' => 1,
277 'copyFolder' => 0,
278 'moveFolder' => 0,
279 'renameFolder' => 0,
280 'writeFolder' => 0,
281 'deleteFolder' => 0,
282 'recursivedeleteFolder' => 0,
283 )
284 ),
285 'Uploading allowed' => array(
286 array(
287 'addFile' => 1,
288 'readFile' => 1,
289 'writeFile' => 1,
290 'copyFile' => 1,
291 'moveFile' => 1,
292 'renameFile' => 1,
293 'deleteFile' => 1,
294 'addFolder' => 0,
295 'readFolder' => 1,
296 'copyFolder' => 0,
297 'moveFolder' => 0,
298 'renameFolder' => 0,
299 'writeFolder' => 0,
300 'deleteFolder' => 0,
301 'recursivedeleteFolder' => 0
302 )
303 ),
304 'One value is enough' => array(
305 array(
306 'addFile' => 1,
307 )
308 ),
309 );
310 }
311
312 /**
313 * @param array $userTsConfiguration
314 * @test
315 * @dataProvider getFilePermissionsTakesUserDefaultAndStoragePermissionsIntoAccountIfUserIsNotAdminDataProvider
316 */
317 public function getFilePermissionsTakesUserDefaultPermissionsFromTsConfigIntoAccountIfUserIsNotAdmin(array $userTsConfiguration)
318 {
319 $subject = $this->getMock(BackendUserAuthentication::class, array('isAdmin'));
320
321 $subject
322 ->expects($this->any())
323 ->method('isAdmin')
324 ->will($this->returnValue(false));
325
326 $subject->userTS = array(
327 'permissions.' => array(
328 'file.' => array(
329 'default.' => $userTsConfiguration
330 ),
331 )
332 );
333
334 $expectedPermissions = array_merge($this->defaultFilePermissions, $userTsConfiguration);
335 array_walk(
336 $expectedPermissions,
337 function (&$value) {
338 $value = (bool)$value;
339 }
340 );
341
342 $this->assertEquals($expectedPermissions, $subject->getFilePermissions());
343 }
344
345 /**
346 * @return array
347 */
348 public function getFilePermissionsFromStorageDataProvider()
349 {
350 $defaultPermissions = array(
351 'addFile' => true,
352 'readFile' => true,
353 'writeFile' => true,
354 'copyFile' => true,
355 'moveFile' => true,
356 'renameFile' => true,
357 'deleteFile' => true,
358 'addFolder' => true,
359 'readFolder' => true,
360 'copyFolder' => true,
361 'moveFolder' => true,
362 'renameFolder' => true,
363 'writeFolder' => true,
364 'deleteFolder' => true,
365 'recursivedeleteFolder' => true
366 );
367
368 return array(
369 'Overwrites given storage permissions with default permissions' => array(
370 $defaultPermissions,
371 1,
372 array(
373 'addFile' => 0,
374 'recursivedeleteFolder' =>0
375 ),
376 array(
377 'addFile' => 0,
378 'readFile' => 1,
379 'writeFile' => 1,
380 'copyFile' => 1,
381 'moveFile' => 1,
382 'renameFile' => 1,
383 'deleteFile' => 1,
384 'addFolder' => 1,
385 'readFolder' => 1,
386 'copyFolder' => 1,
387 'moveFolder' => 1,
388 'renameFolder' => 1,
389 'writeFolder' => 1,
390 'deleteFolder' => 1,
391 'recursivedeleteFolder' => 0
392 )
393 ),
394 'Overwrites given storage 0 permissions with default permissions' => array(
395 $defaultPermissions,
396 0,
397 array(
398 'addFile' => 0,
399 'recursivedeleteFolder' =>0
400 ),
401 array(
402 'addFile' => false,
403 'readFile' => true,
404 'writeFile' => true,
405 'copyFile' => true,
406 'moveFile' => true,
407 'renameFile' => true,
408 'deleteFile' => true,
409 'addFolder' => true,
410 'readFolder' => true,
411 'copyFolder' => true,
412 'moveFolder' => true,
413 'renameFolder' => true,
414 'writeFolder' => true,
415 'deleteFolder' => true,
416 'recursivedeleteFolder' => false
417 )
418 ),
419 'Returns default permissions if no storage permissions are found' => array(
420 $defaultPermissions,
421 1,
422 array(),
423 array(
424 'addFile' => true,
425 'readFile' => true,
426 'writeFile' => true,
427 'copyFile' => true,
428 'moveFile' => true,
429 'renameFile' => true,
430 'deleteFile' => true,
431 'addFolder' => true,
432 'readFolder' => true,
433 'copyFolder' => true,
434 'moveFolder' => true,
435 'renameFolder' => true,
436 'writeFolder' => true,
437 'deleteFolder' => true,
438 'recursivedeleteFolder' => true
439 )
440 ),
441 );
442 }
443
444 /**
445 * @param array $defaultPermissions
446 * @param int $storageUid
447 * @param array $storagePermissions
448 * @param array $expectedPermissions
449 * @test
450 * @dataProvider getFilePermissionsFromStorageDataProvider
451 */
452 public function getFilePermissionsFromStorageOverwritesDefaultPermissions(array $defaultPermissions, $storageUid, array $storagePermissions, array $expectedPermissions)
453 {
454 $subject = $this->getMock(BackendUserAuthentication::class, array('isAdmin', 'getFilePermissions'));
455 $storageMock = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceStorage::class, array(), array(), '', false);
456 $storageMock->expects($this->any())->method('getUid')->will($this->returnValue($storageUid));
457
458 $subject
459 ->expects($this->any())
460 ->method('isAdmin')
461 ->will($this->returnValue(false));
462
463 $subject
464 ->expects($this->any())
465 ->method('getFilePermissions')
466 ->will($this->returnValue($defaultPermissions));
467
468 $subject->userTS = array(
469 'permissions.' => array(
470 'file.' => array(
471 'storage.' => array(
472 $storageUid . '.' => $storagePermissions
473 ),
474 ),
475 )
476 );
477
478 $this->assertEquals($expectedPermissions, $subject->getFilePermissionsForStorage($storageMock));
479 }
480
481 /**
482 * @param array $defaultPermissions
483 * @param $storageUid
484 * @param array $storagePermissions
485 * @test
486 * @dataProvider getFilePermissionsFromStorageDataProvider
487 */
488 public function getFilePermissionsFromStorageAlwaysReturnsDefaultPermissionsForAdmins(array $defaultPermissions, $storageUid, array $storagePermissions)
489 {
490 $subject = $this->getMock(BackendUserAuthentication::class, array('isAdmin', 'getFilePermissions'));
491 $storageMock = $this->getMock(\TYPO3\CMS\Core\Resource\ResourceStorage::class, array(), array(), '', false);
492 $storageMock->expects($this->any())->method('getUid')->will($this->returnValue($storageUid));
493
494 $subject
495 ->expects($this->any())
496 ->method('isAdmin')
497 ->will($this->returnValue(true));
498
499 $subject
500 ->expects($this->any())
501 ->method('getFilePermissions')
502 ->will($this->returnValue($defaultPermissions));
503
504 $subject->userTS = array(
505 'permissions.' => array(
506 'file.' => array(
507 'storage.' => array(
508 $storageUid . '.' => $storagePermissions
509 ),
510 ),
511 )
512 );
513
514 $this->assertEquals($defaultPermissions, $subject->getFilePermissionsForStorage($storageMock));
515 }
516
517 /**
518 * @return array
519 */
520 public function getFilePermissionsTakesUserDefaultPermissionsFromRecordIntoAccountIfUserIsNotAdminDataProvider()
521 {
522 return array(
523 'No permission' => array(
524 '',
525 array(
526 'addFile' => false,
527 'readFile' => false,
528 'writeFile' => false,
529 'copyFile' => false,
530 'moveFile' => false,
531 'renameFile' => false,
532 'deleteFile' => false,
533 'addFolder' => false,
534 'readFolder' => false,
535 'copyFolder' => false,
536 'moveFolder' => false,
537 'renameFolder' => false,
538 'writeFolder' => false,
539 'deleteFolder' => false,
540 'recursivedeleteFolder' => false
541 )
542 ),
543 'Standard file permissions' => array(
544 'addFile,readFile,writeFile,copyFile,moveFile,renameFile,deleteFile',
545 array(
546 'addFile' => true,
547 'readFile' => true,
548 'writeFile' => true,
549 'copyFile' => true,
550 'moveFile' => true,
551 'renameFile' => true,
552 'deleteFile' => true,
553 'addFolder' => false,
554 'readFolder' => false,
555 'copyFolder' => false,
556 'moveFolder' => false,
557 'renameFolder' => false,
558 'writeFolder' => false,
559 'deleteFolder' => false,
560 'recursivedeleteFolder' => false
561 )
562 ),
563 'Standard folder permissions' => array(
564 'addFolder,readFolder,moveFolder,renameFolder,writeFolder,deleteFolder',
565 array(
566 'addFile' => false,
567 'readFile' => false,
568 'writeFile' => false,
569 'copyFile' => false,
570 'moveFile' => false,
571 'renameFile' => false,
572 'deleteFile' => false,
573 'addFolder' => true,
574 'readFolder' => true,
575 'writeFolder' => true,
576 'copyFolder' => false,
577 'moveFolder' => true,
578 'renameFolder' => true,
579 'deleteFolder' => true,
580 'recursivedeleteFolder' => false
581 )
582 ),
583 'Copy folder allowed' => array(
584 'readFolder,copyFolder',
585 array(
586 'addFile' => false,
587 'readFile' => false,
588 'writeFile' => false,
589 'copyFile' => false,
590 'moveFile' => false,
591 'renameFile' => false,
592 'deleteFile' => false,
593 'addFolder' => false,
594 'readFolder' => true,
595 'writeFolder' => false,
596 'copyFolder' => true,
597 'moveFolder' => false,
598 'renameFolder' => false,
599 'deleteFolder' => false,
600 'recursivedeleteFolder' => false
601 )
602 ),
603 'Copy folder and remove subfolders allowed' => array(
604 'readFolder,copyFolder,recursivedeleteFolder',
605 array(
606 'addFile' => false,
607 'readFile' => false,
608 'writeFile' => false,
609 'copyFile' => false,
610 'moveFile' => false,
611 'renameFile' => false,
612 'deleteFile' => false,
613 'addFolder' => false,
614 'readFolder' => true,
615 'writeFolder' => false,
616 'copyFolder' => true,
617 'moveFolder' => false,
618 'renameFolder' => false,
619 'deleteFolder' => false,
620 'recursivedeleteFolder' => true
621 )
622 ),
623 );
624 }
625
626 /**
627 * @test
628 * @dataProvider getFilePermissionsTakesUserDefaultPermissionsFromRecordIntoAccountIfUserIsNotAdminDataProvider
629 */
630 public function getFilePermissionsTakesUserDefaultPermissionsFromRecordIntoAccountIfUserIsNotAdmin($permissionValue, $expectedPermissions)
631 {
632 $subject = $this->getMock(BackendUserAuthentication::class, array('isAdmin'));
633
634 $subject
635 ->expects($this->any())
636 ->method('isAdmin')
637 ->will($this->returnValue(false));
638
639 $subject->userTS = array();
640 $subject->groupData['file_permissions'] = $permissionValue;
641 $this->assertEquals($expectedPermissions, $subject->getFilePermissions());
642 }
643
644 /**
645 * @test
646 */
647 public function getFilePermissionsGrantsAllPermissionsToAdminUsers()
648 {
649 $subject = $this->getMock(BackendUserAuthentication::class, array('isAdmin'));
650
651 $subject
652 ->expects($this->any())
653 ->method('isAdmin')
654 ->will($this->returnValue(true));
655
656 $expectedPermissions = array(
657 'addFile' => true,
658 'readFile' => true,
659 'writeFile' => true,
660 'copyFile' => true,
661 'moveFile' => true,
662 'renameFile' => true,
663 'deleteFile' => true,
664 'addFolder' => true,
665 'readFolder' => true,
666 'writeFolder' => true,
667 'copyFolder' => true,
668 'moveFolder' => true,
669 'renameFolder' => true,
670 'deleteFolder' => true,
671 'recursivedeleteFolder' => true
672 );
673
674 $this->assertEquals($expectedPermissions, $subject->getFilePermissions());
675 }
676
677 /**
678 * @test
679 */
680 public function jsConfirmationReturnsTrueIfPassedValueEqualsConfiguration()
681 {
682 $subject = $this->getMock(BackendUserAuthentication::class, ['getTSConfig']);
683 $subject->method('getTSConfig')->with('options.alertPopups')->willReturn(['value' => 1]);
684
685 $this->assertTrue($subject->jsConfirmation(JsConfirmation::TYPE_CHANGE));
686 $this->assertFalse($subject->jsConfirmation(JsConfirmation::COPY_MOVE_PASTE));
687 }
688
689 /**
690 * @test
691 */
692 public function jsConfirmationAllowsSettingMultipleBitsInValue()
693 {
694 $subject = $this->getMock(BackendUserAuthentication::class, ['getTSConfig']);
695 $subject->method('getTSConfig')->with('options.alertPopups')->willReturn(['value' => 3]);
696
697 $this->assertTrue($subject->jsConfirmation(JsConfirmation::TYPE_CHANGE));
698 $this->assertTrue($subject->jsConfirmation(JsConfirmation::COPY_MOVE_PASTE));
699 }
700
701 /**
702 * @test
703 */
704 public function jsConfirmationAlwaysReturnsFalseIfNoConfirmationIsSet()
705 {
706 $subject = $this->getMock(BackendUserAuthentication::class, ['getTSConfig']);
707 $subject->method('getTSConfig')->with('options.alertPopups')->willReturn(['value' => 0]);
708
709 $this->assertFalse($subject->jsConfirmation(JsConfirmation::TYPE_CHANGE));
710 $this->assertFalse($subject->jsConfirmation(JsConfirmation::COPY_MOVE_PASTE));
711 }
712
713 /**
714 * @test
715 */
716 public function jsConfirmationReturnsTrueIfConfigurationIsMissing()
717 {
718 $subject = $this->getMock(BackendUserAuthentication::class, ['getTSConfig']);
719
720 $this->assertTrue($subject->jsConfirmation(JsConfirmation::TYPE_CHANGE));
721 }
722
723 /**
724 * Data provider to test page permissions constraints
725 * returns an array of test conditions:
726 * - permission bit(s) as integer
727 * - admin flag
728 * - groups for user
729 * - expected SQL fragment
730 *
731 * @return array
732 */
733 public function getPagePermissionsClauseWithValidUserDataProvider(): array
734 {
735 return [
736 'for admin' => [
737 1,
738 true,
739 '',
740 ' 1=1'
741 ],
742 'for admin with groups' => [
743 11,
744 true,
745 '1,2',
746 ' 1=1'
747 ],
748 'for user' => [
749 2,
750 false,
751 '',
752 ' ((`pages`.`perms_everybody` & 2 = 2) OR' .
753 ' ((`pages`.`perms_userid` = 123) AND (`pages`.`perms_user` & 2 = 2)))'
754 ],
755 'for user with groups' => [
756 8,
757 false,
758 '1,2',
759 ' ((`pages`.`perms_everybody` & 8 = 8) OR' .
760 ' ((`pages`.`perms_userid` = 123) AND (`pages`.`perms_user` & 8 = 8))' .
761 ' OR ((`pages`.`perms_groupid` IN (1, 2)) AND (`pages`.`perms_group` & 8 = 8)))'
762 ],
763 ];
764 }
765
766 /**
767 * @test
768 * @dataProvider getPagePermissionsClauseWithValidUserDataProvider
769 * @param int $perms
770 * @param bool $admin
771 * @param string $groups
772 * @param string $expected
773 */
774 public function getPagePermissionsClauseWithValidUser(int $perms, bool $admin, string $groups, string $expected)
775 {
776 // We only need to setup the mocking for the non-admin cases
777 // If this setup is done for admin cases the FIFO behavior
778 // of GeneralUtility::addInstance will influence other tests
779 // as the ConnectionPool is never used!
780 if (!$admin) {
781 /** @var Connection|ObjectProphecy $connectionProphet */
782 $connectionProphet = $this->prophesize(Connection::class);
783 $connectionProphet->getDatabasePlatform()->willReturn(new MockPlatform());
784 $connectionProphet->quoteIdentifier(Argument::cetera())->will(function ($args) {
785 return '`' . str_replace('.', '`.`', $args[0]) . '`';
786 });
787
788 /** @var QueryBuilder|ObjectProphecy $queryBuilderProphet */
789 $queryBuilderProphet = $this->prophesize(QueryBuilder::class);
790 $queryBuilderProphet->expr()->willReturn(
791 GeneralUtility::makeInstance(ExpressionBuilder::class, $connectionProphet->reveal())
792 );
793
794 /** @var ConnectionPool|ObjectProphecy $databaseProphet */
795 $databaseProphet = $this->prophesize(ConnectionPool::class);
796 $databaseProphet->getQueryBuilderForTable('pages')->willReturn($queryBuilderProphet->reveal());
797 GeneralUtility::addInstance(ConnectionPool::class, $databaseProphet->reveal());
798 }
799
800 /** @var BackendUserAuthentication|\PHPUnit_Framework_MockObject_MockObject $subject */
801 $subject = $this->getMock(BackendUserAuthentication::class, ['isAdmin']);
802 $subject->expects($this->any())
803 ->method('isAdmin')
804 ->will($this->returnValue($admin));
805
806 $subject->user = ['uid' => 123];
807 $subject->groupList = $groups;
808
809 $this->assertEquals($expected, $subject->getPagePermsClause($perms));
810 }
811 }