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