82d8842e07acca88030ce716d02782a79184ebe9
[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 */
25 protected function setUp()
26 {
27 parent::setUp();
28 }
29
30 public function frontendStatesDataProvider()
31 {
32 return [
33 'Live, no preview' => [
34 'tableName' => 'aTable',
35 'workspaceId' => 0,
36 'workspacePreview' => false,
37 'hiddenPagePreview' => false,
38 'hiddenRecordPreview' => false,
39 'feGroupList' => '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 'workspaceId' => 0,
45 'workspacePreview' => false,
46 'hiddenPagePreview' => true,
47 'hiddenRecordPreview' => true,
48 'feGroupList' => '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 'workspaceId' => 1,
54 'workspacePreview' => true,
55 'hiddenPagePreview' => false,
56 'hiddenRecordPreview' => false,
57 'feGroupList' => '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 'workspaceId' => 1,
63 'workspacePreview' => true,
64 'hiddenPagePreview' => true,
65 'hiddenRecordPreview' => true,
66 'feGroupList' => '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 'workspaceId' => 0,
72 'workspacePreview' => false,
73 'hiddenPagePreview' => false,
74 'hiddenRecordPreview' => false,
75 'feGroupList' => '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 'workspaceId' => 0,
81 'workspacePreview' => false,
82 'hiddenPagePreview' => true,
83 'hiddenRecordPreview' => true,
84 'feGroupList' => '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 '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 'workspaceId' => 1,
99 'workspacePreview' => true,
100 'hiddenPagePreview' => true,
101 'hiddenRecordPreview' => true,
102 'feGroupList' => '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 ];
106 }
107
108 /**
109 * @param string $tableName
110 * @param int $workspaceId
111 * @param bool $workspacePreview
112 * @param bool $hiddenPagePreview
113 * @param bool $hiddenRecordPreview
114 * @param string $feGroupList
115 * @param string $expectedSQL
116 *
117 * @test
118 * @dataProvider frontendStatesDataProvider
119 */
120 public function buildExpressionAddsCorrectClause(
121 string $tableName,
122 int $workspaceId,
123 bool $workspacePreview,
124 bool $hiddenPagePreview,
125 bool $hiddenRecordPreview,
126 string $feGroupList,
127 string $expectedSQL
128 ) {
129 $GLOBALS['TCA'] = [
130 'aTable' => [
131 'ctrl' => [
132 'versioningWS' => 2,
133 'delete' => 'deleted',
134 'enablecolumns' => [
135 'disabled' => 'myHiddenField',
136 'starttime' => 'myStartTimeField',
137 'endtime' => 'myEndTimeField',
138 'fe_group' => 'myGroupField',
139 ],
140 ],
141 ],
142 'pages' => [
143 'ctrl' => [
144 'label' => 'title',
145 'tstamp' => 'tstamp',
146 'sortby' => 'sorting',
147 'type' => 'doktype',
148 'versioningWS' => true,
149 'origUid' => 't3_origuid',
150 'delete' => 'deleted',
151 'enablecolumns' => [
152 'disabled' => 'hidden',
153 'starttime' => 'starttime',
154 'endtime' => 'endtime',
155 'fe_group' => 'fe_group'
156 ],
157 ],
158 'columns' => []
159 ]
160 ];
161
162 $pageRepository = $this->createMock(PageRepository::class);
163 $pageRepository->versioningWorkspaceId = $workspaceId;
164 $pageRepository->versioningPreview = $workspacePreview;
165
166 $typoScriptFrontendController = new \stdClass();
167 $typoScriptFrontendController->showHiddenPage = $hiddenPagePreview;
168 $typoScriptFrontendController->showHiddenRecords = $hiddenRecordPreview;
169 $typoScriptFrontendController->gr_list = $feGroupList;
170 $typoScriptFrontendController->sys_page = $pageRepository;
171
172 $GLOBALS['TSFE'] = $typoScriptFrontendController;
173 $GLOBALS['SIM_ACCESS_TIME'] = 42;
174
175 $subject = new FrontendRestrictionContainer();
176 $expression = $subject->buildExpression([$tableName => $tableName], $this->expressionBuilder);
177 $this->assertSame($expectedSQL, (string)$expression);
178 }
179 }