TYPO3 CMS  TYPO3_8-7
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 
20 
22 {
23  public function frontendStatesDataProvider()
24  {
25  return [
26  'Live, no preview' => [
27  'tableName' => 'aTable',
28  'tableAlias' => 'aTable',
29  'workspaceId' => 0,
30  'workspacePreview' => false,
31  'hiddenPagePreview' => false,
32  'hiddenRecordPreview' => false,
33  'feGroupList' => '0,-1',
34  '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")))'
35  ],
36  'Live, with hidden record preview' => [
37  'tableName' => 'aTable',
38  'tableAlias' => 'aTable',
39  'workspaceId' => 0,
40  'workspacePreview' => false,
41  'hiddenPagePreview' => true,
42  'hiddenRecordPreview' => true,
43  'feGroupList' => '0,-1',
44  '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")))'
45  ],
46  'Workspace, with WS preview' => [
47  'tableName' => 'aTable',
48  'tableAlias' => 'aTable',
49  'workspaceId' => 1,
50  'workspacePreview' => true,
51  'hiddenPagePreview' => false,
52  'hiddenRecordPreview' => false,
53  'feGroupList' => '0,-1',
54  '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")))'
55  ],
56  'Workspace, with WS preview and hidden record preview' => [
57  'tableName' => 'aTable',
58  'tableAlias' => 'aTable',
59  'workspaceId' => 1,
60  'workspacePreview' => true,
61  'hiddenPagePreview' => true,
62  'hiddenRecordPreview' => true,
63  'feGroupList' => '0,-1',
64  '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")))'
65  ],
66  'Live page, no preview' => [
67  'tableName' => 'pages',
68  'tableAlias' => 'pages',
69  'workspaceId' => 0,
70  'workspacePreview' => false,
71  'hiddenPagePreview' => false,
72  'hiddenRecordPreview' => false,
73  'feGroupList' => '0,-1',
74  '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")))'
75  ],
76  'Live page, with hidden page preview' => [
77  'tableName' => 'pages',
78  'tableAlias' => 'pages',
79  'workspaceId' => 0,
80  'workspacePreview' => false,
81  'hiddenPagePreview' => true,
82  'hiddenRecordPreview' => true,
83  'feGroupList' => '0,-1',
84  '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")))'
85  ],
86  'Workspace page, with WS preview' => [
87  'tableName' => 'pages',
88  'tableAlias' => 'pages',
89  'workspaceId' => 1,
90  'workspacePreview' => true,
91  'hiddenPagePreview' => false,
92  'hiddenRecordPreview' => false,
93  'feGroupList' => '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  'workspacePreview' => true,
101  'hiddenPagePreview' => true,
102  'hiddenRecordPreview' => true,
103  'feGroupList' => '0,-1',
104  '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")))'
105  ],
106  'Live, no preview with alias' => [
107  'tableName' => 'aTable',
108  'tableAlias' => 'a',
109  'workspaceId' => 0,
110  'workspacePreview' => false,
111  'hiddenPagePreview' => false,
112  'hiddenRecordPreview' => false,
113  'feGroupList' => '0,-1',
114  '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")))'
115  ],
116  ];
117  }
118 
133  string $tableName,
134  string $tableAlias,
135  int $workspaceId,
136  bool $workspacePreview,
137  bool $hiddenPagePreview,
138  bool $hiddenRecordPreview,
139  string $feGroupList,
140  string $expectedSQL
141  ) {
142  $GLOBALS['TCA'] = [
143  'aTable' => [
144  'ctrl' => [
145  'versioningWS' => 2,
146  'delete' => 'deleted',
147  'enablecolumns' => [
148  'disabled' => 'myHiddenField',
149  'starttime' => 'myStartTimeField',
150  'endtime' => 'myEndTimeField',
151  'fe_group' => 'myGroupField',
152  ],
153  ],
154  ],
155  'pages' => [
156  'ctrl' => [
157  'label' => 'title',
158  'tstamp' => 'tstamp',
159  'sortby' => 'sorting',
160  'type' => 'doktype',
161  'versioningWS' => true,
162  'origUid' => 't3_origuid',
163  'delete' => 'deleted',
164  'enablecolumns' => [
165  'disabled' => 'hidden',
166  'starttime' => 'starttime',
167  'endtime' => 'endtime',
168  'fe_group' => 'fe_group'
169  ],
170  ],
171  'columns' => []
172  ]
173  ];
174 
175  $pageRepository = $this->createMock(PageRepository::class);
176  $pageRepository->versioningWorkspaceId = $workspaceId;
177  $pageRepository->versioningPreview = $workspacePreview;
178 
179  $typoScriptFrontendController = new \stdClass();
180  $typoScriptFrontendController->showHiddenPage = $hiddenPagePreview;
181  $typoScriptFrontendController->showHiddenRecords = $hiddenRecordPreview;
182  $typoScriptFrontendController->gr_list = $feGroupList;
183  $typoScriptFrontendController->sys_page = $pageRepository;
184 
185  $GLOBALS['TSFE'] = $typoScriptFrontendController;
186  $GLOBALS['SIM_ACCESS_TIME'] = 42;
187 
188  $subject = new FrontendRestrictionContainer();
189  $expression = $subject->buildExpression([$tableAlias => $tableName], $this->expressionBuilder);
190  $this->assertSame($expectedSQL, (string)$expression);
191  }
192 }
buildExpressionAddsCorrectClause(string $tableName, string $tableAlias, int $workspaceId, bool $workspacePreview, bool $hiddenPagePreview, bool $hiddenRecordPreview, string $feGroupList, string $expectedSQL)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']