‪TYPO3CMS  10.4
FrontendRestrictionContainerTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 
19 
27 
29 {
30  protected ‪$resetSingletonInstances = true;
31 
33  {
34  return [
35  'Live, no preview' => [
36  'tableName' => 'aTable',
37  'tableAlias' => 'aTable',
38  'workspaceId' => 0,
39  'hiddenPagePreview' => false,
40  'hiddenRecordPreview' => false,
41  'frontendUserGroups' => [0, -1],
42  'expectedSQL' => '("aTable"."deleted" = 0) AND (("aTable"."t3ver_state" <= 0) AND ("aTable"."t3ver_oid" = 0)) AND ("aTable"."myHiddenField" = 0) AND ("aTable"."myStartTimeField" <= 42) AND (("aTable"."myEndTimeField" = 0) OR ("aTable"."myEndTimeField" > 42)) AND (("aTable"."myGroupField" IS NULL) OR ("aTable"."myGroupField" = \'\') OR ("aTable"."myGroupField" = \'0\') OR (FIND_IN_SET(\'0\', "aTable"."myGroupField")) OR (FIND_IN_SET(\'-1\', "aTable"."myGroupField")))'
43  ],
44  'Live, with hidden record preview' => [
45  'tableName' => 'aTable',
46  'tableAlias' => 'aTable',
47  'workspaceId' => 0,
48  'hiddenPagePreview' => true,
49  'hiddenRecordPreview' => true,
50  'frontendUserGroups' => [0, -1],
51  'expectedSQL' => '("aTable"."deleted" = 0) AND (("aTable"."t3ver_state" <= 0) AND ("aTable"."t3ver_oid" = 0)) AND ("aTable"."myStartTimeField" <= 42) AND (("aTable"."myEndTimeField" = 0) OR ("aTable"."myEndTimeField" > 42)) AND (("aTable"."myGroupField" IS NULL) OR ("aTable"."myGroupField" = \'\') OR ("aTable"."myGroupField" = \'0\') OR (FIND_IN_SET(\'0\', "aTable"."myGroupField")) OR (FIND_IN_SET(\'-1\', "aTable"."myGroupField")))'
52  ],
53  'Workspace, with WS preview' => [
54  'tableName' => 'aTable',
55  'tableAlias' => 'aTable',
56  'workspaceId' => 1,
57  'hiddenPagePreview' => false,
58  'hiddenRecordPreview' => false,
59  'frontendUserGroups' => [0, -1],
60  'expectedSQL' => '("aTable"."deleted" = 0) AND ((("aTable"."t3ver_wsid" = 0) OR ("aTable"."t3ver_wsid" = 1)) AND ("aTable"."t3ver_oid" = 0)) AND ("aTable"."myHiddenField" = 0) AND ("aTable"."myStartTimeField" <= 42) AND (("aTable"."myEndTimeField" = 0) OR ("aTable"."myEndTimeField" > 42)) AND (("aTable"."myGroupField" IS NULL) OR ("aTable"."myGroupField" = \'\') OR ("aTable"."myGroupField" = \'0\') OR (FIND_IN_SET(\'0\', "aTable"."myGroupField")) OR (FIND_IN_SET(\'-1\', "aTable"."myGroupField")))'
61  ],
62  'Workspace, with WS preview and hidden record preview' => [
63  'tableName' => 'aTable',
64  'tableAlias' => 'aTable',
65  'workspaceId' => 1,
66  'hiddenPagePreview' => true,
67  'hiddenRecordPreview' => true,
68  'frontendUserGroups' => [0, -1],
69  'expectedSQL' => '("aTable"."deleted" = 0) AND ((("aTable"."t3ver_wsid" = 0) OR ("aTable"."t3ver_wsid" = 1)) AND ("aTable"."t3ver_oid" = 0)) AND ("aTable"."myStartTimeField" <= 42) AND (("aTable"."myEndTimeField" = 0) OR ("aTable"."myEndTimeField" > 42)) AND (("aTable"."myGroupField" IS NULL) OR ("aTable"."myGroupField" = \'\') OR ("aTable"."myGroupField" = \'0\') OR (FIND_IN_SET(\'0\', "aTable"."myGroupField")) OR (FIND_IN_SET(\'-1\', "aTable"."myGroupField")))'
70  ],
71  'Live page, no preview' => [
72  'tableName' => 'pages',
73  'tableAlias' => 'pages',
74  'workspaceId' => 0,
75  'hiddenPagePreview' => false,
76  'hiddenRecordPreview' => false,
77  'frontendUserGroups' => [0, -1],
78  'expectedSQL' => '("pages"."deleted" = 0) AND (("pages"."t3ver_state" <= 0) AND ("pages"."t3ver_oid" = 0)) AND ("pages"."hidden" = 0) AND ("pages"."starttime" <= 42) AND (("pages"."endtime" = 0) OR ("pages"."endtime" > 42)) AND (("pages"."fe_group" IS NULL) OR ("pages"."fe_group" = \'\') OR ("pages"."fe_group" = \'0\') OR (FIND_IN_SET(\'0\', "pages"."fe_group")) OR (FIND_IN_SET(\'-1\', "pages"."fe_group")))'
79  ],
80  'Live page, with hidden page preview' => [
81  'tableName' => 'pages',
82  'tableAlias' => 'pages',
83  'workspaceId' => 0,
84  'hiddenPagePreview' => true,
85  'hiddenRecordPreview' => true,
86  'frontendUserGroups' => [0, -1],
87  'expectedSQL' => '("pages"."deleted" = 0) AND (("pages"."t3ver_state" <= 0) AND ("pages"."t3ver_oid" = 0)) AND ("pages"."starttime" <= 42) AND (("pages"."endtime" = 0) OR ("pages"."endtime" > 42)) AND (("pages"."fe_group" IS NULL) OR ("pages"."fe_group" = \'\') OR ("pages"."fe_group" = \'0\') OR (FIND_IN_SET(\'0\', "pages"."fe_group")) OR (FIND_IN_SET(\'-1\', "pages"."fe_group")))'
88  ],
89  'Workspace page, with WS preview' => [
90  'tableName' => 'pages',
91  'tableAlias' => 'pages',
92  'workspaceId' => 1,
93  'hiddenPagePreview' => false,
94  'hiddenRecordPreview' => false,
95  'frontendUserGroups' => [0, -1],
96  'expectedSQL' => '("pages"."deleted" = 0) AND ("pages"."t3ver_oid" = 0) AND ("pages"."hidden" = 0) AND ("pages"."starttime" <= 42) AND (("pages"."endtime" = 0) OR ("pages"."endtime" > 42)) AND (("pages"."fe_group" IS NULL) OR ("pages"."fe_group" = \'\') OR ("pages"."fe_group" = \'0\') OR (FIND_IN_SET(\'0\', "pages"."fe_group")) OR (FIND_IN_SET(\'-1\', "pages"."fe_group")))'
97  ],
98  'Workspace page, with WS preview and hidden pages preview' => [
99  'tableName' => 'pages',
100  'tableAlias' => 'pages',
101  'workspaceId' => 1,
102  'hiddenPagePreview' => true,
103  'hiddenRecordPreview' => true,
104  'frontendUserGroups' => [0, -1],
105  'expectedSQL' => '("pages"."deleted" = 0) AND ("pages"."t3ver_oid" = 0) AND ("pages"."starttime" <= 42) AND (("pages"."endtime" = 0) OR ("pages"."endtime" > 42)) AND (("pages"."fe_group" IS NULL) OR ("pages"."fe_group" = \'\') OR ("pages"."fe_group" = \'0\') OR (FIND_IN_SET(\'0\', "pages"."fe_group")) OR (FIND_IN_SET(\'-1\', "pages"."fe_group")))'
106  ],
107  'Live, no preview with alias' => [
108  'tableName' => 'aTable',
109  'tableAlias' => 'a',
110  'workspaceId' => 0,
111  'hiddenPagePreview' => false,
112  'hiddenRecordPreview' => false,
113  'frontendUserGroups' => [0, -1],
114  'expectedSQL' => '("a"."deleted" = 0) AND (("a"."t3ver_state" <= 0) AND ("a"."t3ver_oid" = 0)) AND ("a"."myHiddenField" = 0) AND ("a"."myStartTimeField" <= 42) AND (("a"."myEndTimeField" = 0) OR ("a"."myEndTimeField" > 42)) AND (("a"."myGroupField" IS NULL) OR ("a"."myGroupField" = \'\') OR ("a"."myGroupField" = \'0\') OR (FIND_IN_SET(\'0\', "a"."myGroupField")) OR (FIND_IN_SET(\'-1\', "a"."myGroupField")))'
115  ],
116  ];
117  }
118 
132  string $tableName,
133  string $tableAlias,
134  int $workspaceId,
135  bool $hiddenPagePreview,
136  bool $hiddenRecordPreview,
137  array $frontendUserGroups,
138  string $expectedSQL
139  ) {
140  ‪$GLOBALS['TCA'] = [
141  'aTable' => [
142  'ctrl' => [
143  'versioningWS' => 2,
144  'delete' => 'deleted',
145  'enablecolumns' => [
146  'disabled' => 'myHiddenField',
147  'starttime' => 'myStartTimeField',
148  'endtime' => 'myEndTimeField',
149  'fe_group' => 'myGroupField',
150  ],
151  ],
152  ],
153  'pages' => [
154  'ctrl' => [
155  'label' => 'title',
156  'tstamp' => 'tstamp',
157  'sortby' => 'sorting',
158  'type' => 'doktype',
159  'versioningWS' => true,
160  'origUid' => 't3_origuid',
161  'delete' => 'deleted',
162  'enablecolumns' => [
163  'disabled' => 'hidden',
164  'starttime' => 'starttime',
165  'endtime' => 'endtime',
166  'fe_group' => 'fe_group'
167  ],
168  ],
169  'columns' => []
170  ]
171  ];
172  $context = new ‪Context([
173  'visibility' => new ‪VisibilityAspect($hiddenPagePreview, $hiddenRecordPreview),
174  'frontend.user' => new ‪UserAspect(new ‪FrontendUserAuthentication(), $frontendUserGroups),
175  'workspace' => new ‪WorkspaceAspect($workspaceId)
176  ]);
177  GeneralUtility::setSingletonInstance(Context::class, $context);
178 
179  ‪$GLOBALS['SIM_ACCESS_TIME'] = 42;
180 
181  $subject = new ‪FrontendRestrictionContainer($context);
182  $expression = $subject->buildExpression([$tableAlias => $tableName], $this->expressionBuilder);
183  self::assertSame($expectedSQL, (string)$expression);
184  }
185 }
‪TYPO3\CMS\Core\Context\VisibilityAspect
Definition: VisibilityAspect.php:31
‪TYPO3\CMS\Core\Context\WorkspaceAspect
Definition: WorkspaceAspect.php:31
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\FrontendRestrictionContainerTest
Definition: FrontendRestrictionContainerTest.php:29
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction
Definition: AbstractRestrictionContainerTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\FrontendRestrictionContainerTest\$resetSingletonInstances
‪$resetSingletonInstances
Definition: FrontendRestrictionContainerTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\AbstractRestrictionTestCase
Definition: AbstractRestrictionTestCase.php:28
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\FrontendRestrictionContainerTest\frontendStatesDataProvider
‪frontendStatesDataProvider()
Definition: FrontendRestrictionContainerTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\FrontendRestrictionContainerTest\buildExpressionAddsCorrectClause
‪buildExpressionAddsCorrectClause(string $tableName, string $tableAlias, int $workspaceId, bool $hiddenPagePreview, bool $hiddenRecordPreview, array $frontendUserGroups, string $expectedSQL)
Definition: FrontendRestrictionContainerTest.php:131
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
Definition: FrontendUserAuthentication.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer
Definition: FrontendRestrictionContainer.php:31
‪TYPO3\CMS\Core\Context\UserAspect
Definition: UserAspect.php:38