66d4572cb2356a65a10b4b0531075988688428c2
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Database / Query / Restriction / FrontendGroupRestrictionTest.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction;
19 use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
20
21 class FrontendGroupRestrictionTest extends AbstractRestrictionTestCase
22 {
23 /**
24 * @return void
25 */
26 protected function setUp()
27 {
28 parent::setUp();
29 }
30
31 /**
32 * @test
33 */
34 public function buildExpressionAddsNoAccessGroupWhereClause()
35 {
36 $GLOBALS['TCA']['aTable']['ctrl'] = [
37 'enablecolumns' => [
38 'fe_group' => 'myGroupField',
39 ],
40 ];
41 $subject = new FrontendGroupRestriction([]);
42 $expression = $subject->buildExpression(['aTable' => ''], $this->expressionBuilder);
43 $this->assertSame('("aTable"."myGroupField" IS NULL) OR ("aTable"."myGroupField" = \'\') OR ("aTable"."myGroupField" = \'0\')', (string)$expression);
44 }
45
46 /**
47 * @test
48 */
49 public function buildExpressionAddsGroupWhereClause()
50 {
51 $GLOBALS['TCA']['aTable']['ctrl'] = [
52 'enablecolumns' => [
53 'fe_group' => 'myGroupField',
54 ],
55 ];
56 $subject = new FrontendGroupRestriction([2, 3]);
57 $expression = $subject->buildExpression(['aTable' => ''], $this->expressionBuilder);
58 $this->assertSame('("aTable"."myGroupField" IS NULL) OR ("aTable"."myGroupField" = \'\') OR ("aTable"."myGroupField" = \'0\') OR (FIND_IN_SET(\'2\', "aTable"."myGroupField")) OR (FIND_IN_SET(\'3\', "aTable"."myGroupField"))', (string)$expression);
59 }
60
61 /**
62 * @test
63 */
64 public function handlesNullTypoScriptFrontendControllerGroupList()
65 {
66 $GLOBALS['TSFE'] = $this->prophesize(TypoScriptFrontendController::class);
67 $GLOBALS['TSFE']->gr_list = null;
68
69 $GLOBALS['TCA']['aTable']['ctrl'] = [
70 'enablecolumns' => [
71 'fe_group' => 'myGroupField',
72 ],
73 ];
74 $subject = new FrontendGroupRestriction();
75 $expression = $subject->buildExpression(['aTable' => ''], $this->expressionBuilder);
76 $this->assertSame('("aTable"."myGroupField" IS NULL) OR ("aTable"."myGroupField" = \'\') OR ("aTable"."myGroupField" = \'0\') OR (FIND_IN_SET(\'\', "aTable"."myGroupField"))', (string)$expression);
77 }
78 }