‪TYPO3CMS  11.5
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 
32  public function ‪frontendStatesDataProvider(): array
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  'localContextFrontendUserGroups' => null,
43  '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")))',
44  ],
45  'Live, local context with differing user groups' => [
46  'tableName' => 'aTable',
47  'tableAlias' => 'aTable',
48  'workspaceId' => 0,
49  'hiddenPagePreview' => false,
50  'hiddenRecordPreview' => false,
51  'frontendUserGroups' => [0, -1],
52  'localContextFrontendUserGroups' => [3],
53  '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(\'3\', "aTable"."myGroupField")))',
54  ],
55  'Live, with hidden record preview' => [
56  'tableName' => 'aTable',
57  'tableAlias' => 'aTable',
58  'workspaceId' => 0,
59  'hiddenPagePreview' => true,
60  'hiddenRecordPreview' => true,
61  'frontendUserGroups' => [0, -1],
62  'localContextFrontendUserGroups' => null,
63  '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")))',
64  ],
65  'Workspace, with WS preview' => [
66  'tableName' => 'aTable',
67  'tableAlias' => 'aTable',
68  'workspaceId' => 1,
69  'hiddenPagePreview' => false,
70  'hiddenRecordPreview' => false,
71  'frontendUserGroups' => [0, -1],
72  'localContextFrontendUserGroups' => null,
73  '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")))',
74  ],
75  'Workspace, with WS preview and hidden record preview' => [
76  'tableName' => 'aTable',
77  'tableAlias' => 'aTable',
78  'workspaceId' => 1,
79  'hiddenPagePreview' => true,
80  'hiddenRecordPreview' => true,
81  'frontendUserGroups' => [0, -1],
82  'localContextFrontendUserGroups' => null,
83  '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")))',
84  ],
85  'Live page, no preview' => [
86  'tableName' => 'pages',
87  'tableAlias' => 'pages',
88  'workspaceId' => 0,
89  'hiddenPagePreview' => false,
90  'hiddenRecordPreview' => false,
91  'frontendUserGroups' => [0, -1],
92  'localContextFrontendUserGroups' => null,
93  '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")))',
94  ],
95  'Live page, with hidden page preview' => [
96  'tableName' => 'pages',
97  'tableAlias' => 'pages',
98  'workspaceId' => 0,
99  'hiddenPagePreview' => true,
100  'hiddenRecordPreview' => true,
101  'frontendUserGroups' => [0, -1],
102  'localContextFrontendUserGroups' => null,
103  '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")))',
104  ],
105  'Workspace page, with WS preview' => [
106  'tableName' => 'pages',
107  'tableAlias' => 'pages',
108  'workspaceId' => 1,
109  'hiddenPagePreview' => false,
110  'hiddenRecordPreview' => false,
111  'frontendUserGroups' => [0, -1],
112  'localContextFrontendUserGroups' => null,
113  '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")))',
114  ],
115  'Workspace page, with WS preview and hidden pages preview' => [
116  'tableName' => 'pages',
117  'tableAlias' => 'pages',
118  'workspaceId' => 1,
119  'hiddenPagePreview' => true,
120  'hiddenRecordPreview' => true,
121  'frontendUserGroups' => [0, -1],
122  'localContextFrontendUserGroups' => null,
123  '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")))',
124  ],
125  'Live, no preview with alias' => [
126  'tableName' => 'aTable',
127  'tableAlias' => 'a',
128  'workspaceId' => 0,
129  'hiddenPagePreview' => false,
130  'hiddenRecordPreview' => false,
131  'frontendUserGroups' => [0, -1],
132  'localContextFrontendUserGroups' => null,
133  '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")))',
134  ],
135  ];
136  }
137 
151  string $tableName,
152  string $tableAlias,
153  int $workspaceId,
154  bool $hiddenPagePreview,
155  bool $hiddenRecordPreview,
156  array $frontendUserGroups,
157  ?array $localContextFrontendUserGroups,
158  string $expectedSQL
159  ): void {
160  ‪$GLOBALS['TCA'] = [
161  'aTable' => [
162  'ctrl' => [
163  'versioningWS' => 2,
164  'delete' => 'deleted',
165  'enablecolumns' => [
166  'disabled' => 'myHiddenField',
167  'starttime' => 'myStartTimeField',
168  'endtime' => 'myEndTimeField',
169  'fe_group' => 'myGroupField',
170  ],
171  ],
172  ],
173  'pages' => [
174  'ctrl' => [
175  'label' => 'title',
176  'tstamp' => 'tstamp',
177  'sortby' => 'sorting',
178  'type' => 'doktype',
179  'versioningWS' => true,
180  'origUid' => 't3_origuid',
181  'delete' => 'deleted',
182  'enablecolumns' => [
183  'disabled' => 'hidden',
184  'starttime' => 'starttime',
185  'endtime' => 'endtime',
186  'fe_group' => 'fe_group',
187  ],
188  ],
189  'columns' => [],
190  ],
191  ];
192  $context = new ‪Context([
193  'visibility' => new ‪VisibilityAspect($hiddenPagePreview, $hiddenRecordPreview),
194  'frontend.user' => new ‪UserAspect(new ‪FrontendUserAuthentication(), $frontendUserGroups),
195  'workspace' => new ‪WorkspaceAspect($workspaceId),
196  ]);
197  GeneralUtility::setSingletonInstance(Context::class, $context);
198 
199  ‪$GLOBALS['SIM_ACCESS_TIME'] = 42;
200 
201  $localContext = clone $context;
202  if ($localContextFrontendUserGroups !== null) {
203  $localContext->setAspect(
204  'frontend.user',
205  new ‪UserAspect(new ‪FrontendUserAuthentication(), $localContextFrontendUserGroups)
206  );
207  }
208 
209  $subject = new ‪FrontendRestrictionContainer($localContext);
210  $expression = $subject->buildExpression([$tableAlias => $tableName], $this->expressionBuilder);
211  self::assertSame($expectedSQL, (string)$expression);
212  }
213 }
‪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\buildExpressionAddsCorrectClause
‪buildExpressionAddsCorrectClause(string $tableName, string $tableAlias, int $workspaceId, bool $hiddenPagePreview, bool $hiddenRecordPreview, array $frontendUserGroups, ?array $localContextFrontendUserGroups, string $expectedSQL)
Definition: FrontendRestrictionContainerTest.php:150
‪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:29
‪TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction\FrontendRestrictionContainerTest\frontendStatesDataProvider
‪frontendStatesDataProvider()
Definition: FrontendRestrictionContainerTest.php:32
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
Definition: FrontendUserAuthentication.php:32
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer
Definition: FrontendRestrictionContainer.php:31
‪TYPO3\CMS\Core\Context\UserAspect
Definition: UserAspect.php:37