[TASK] Cleanup and deprecate TYPO3_DB occurrences
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Database / Query / Restriction / FrontendRestrictionContainerTest.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\FrontendRestrictionContainer;
19 use TYPO3\CMS\Frontend\Page\PageRepository;
20
21 class FrontendRestrictionContainerTest extends AbstractRestrictionTestCase
22 {
23 /**
24 * @return void
25 */
26 protected function setUp()
27 {
28 parent::setUp();
29 }
30
31 public function frontendStatesDataProvider()
32 {
33 return [
34 'Live, no preview' => [
35 'tableName' => 'aTable',
36 'workspaceId' => 0,
37 'workspacePreview' => false,
38 'hiddenPagePreview' => false,
39 'hiddenRecordPreview' => false,
40 'feGroupList' => '0,-1',
41 '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")))'
42 ],
43 'Live, with hidden record preview' => [
44 'tableName' => 'aTable',
45 'workspaceId' => 0,
46 'workspacePreview' => false,
47 'hiddenPagePreview' => true,
48 'hiddenRecordPreview' => true,
49 'feGroupList' => '0,-1',
50 '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")))'
51 ],
52 'Workspace, with WS preview' => [
53 'tableName' => 'aTable',
54 'workspaceId' => 1,
55 'workspacePreview' => true,
56 'hiddenPagePreview' => false,
57 'hiddenRecordPreview' => false,
58 'feGroupList' => '0,-1',
59 '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")))'
60 ],
61 'Workspace, with WS preview and hidden record preview' => [
62 'tableName' => 'aTable',
63 'workspaceId' => 1,
64 'workspacePreview' => true,
65 'hiddenPagePreview' => true,
66 'hiddenRecordPreview' => true,
67 'feGroupList' => '0,-1',
68 '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")))'
69 ],
70 'Live page, no preview' => [
71 'tableName' => 'pages',
72 'workspaceId' => 0,
73 'workspacePreview' => false,
74 'hiddenPagePreview' => false,
75 'hiddenRecordPreview' => false,
76 'feGroupList' => '0,-1',
77 '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")))'
78 ],
79 'Live page, with hidden page preview' => [
80 'tableName' => 'pages',
81 'workspaceId' => 0,
82 'workspacePreview' => false,
83 'hiddenPagePreview' => true,
84 'hiddenRecordPreview' => true,
85 'feGroupList' => '0,-1',
86 '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")))'
87 ],
88 'Workspace page, with WS preview' => [
89 'tableName' => 'pages',
90 'workspaceId' => 1,
91 'workspacePreview' => true,
92 'hiddenPagePreview' => false,
93 'hiddenRecordPreview' => false,
94 'feGroupList' => '0,-1',
95 '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")))'
96 ],
97 'Workspace page, with WS preview and hidden pages preview' => [
98 'tableName' => '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 ];
107 }
108
109 /**
110 * @param string $tableName
111 * @param int $workspaceId
112 * @param bool $workspacePreview
113 * @param bool $hiddenPagePreview
114 * @param bool $hiddenRecordPreview
115 * @param string $feGroupList
116 * @param string $expectedSQL
117 *
118 * @test
119 * @dataProvider frontendStatesDataProvider
120 */
121 public function buildExpressionAddsCorrectClause(
122 string $tableName,
123 int $workspaceId,
124 bool $workspacePreview,
125 bool $hiddenPagePreview,
126 bool $hiddenRecordPreview,
127 string $feGroupList,
128 string $expectedSQL
129 ) {
130 $GLOBALS['TCA'] = [
131 'aTable' => [
132 'ctrl' => [
133 'versioningWS' => 2,
134 'delete' => 'deleted',
135 'enablecolumns' => [
136 'disabled' => 'myHiddenField',
137 'starttime' => 'myStartTimeField',
138 'endtime' => 'myEndTimeField',
139 'fe_group' => 'myGroupField',
140 ],
141 ],
142 ],
143 'pages' => [
144 'ctrl' => [
145 'label' => 'title',
146 'tstamp' => 'tstamp',
147 'sortby' => 'sorting',
148 'type' => 'doktype',
149 'versioningWS' => true,
150 'origUid' => 't3_origuid',
151 'delete' => 'deleted',
152 'enablecolumns' => [
153 'disabled' => 'hidden',
154 'starttime' => 'starttime',
155 'endtime' => 'endtime',
156 'fe_group' => 'fe_group'
157 ],
158 ],
159 'columns' => []
160 ]
161 ];
162
163 $pageRepository = $this->createMock(PageRepository::class);
164 $pageRepository->versioningWorkspaceId = $workspaceId;
165 $pageRepository->versioningPreview = $workspacePreview;
166
167 $typoScriptFrontendController = new \stdClass();
168 $typoScriptFrontendController->showHiddenPage = $hiddenPagePreview;
169 $typoScriptFrontendController->showHiddenRecords = $hiddenRecordPreview;
170 $typoScriptFrontendController->gr_list = $feGroupList;
171 $typoScriptFrontendController->sys_page = $pageRepository;
172
173 $GLOBALS['TSFE'] = $typoScriptFrontendController;
174 $GLOBALS['SIM_ACCESS_TIME'] = 42;
175
176 $subject = new FrontendRestrictionContainer();
177 $expression = $subject->buildExpression([$tableName => ''], $this->expressionBuilder);
178 $this->assertSame($expectedSQL, (string)$expression);
179 }
180 }