[TASK] Add functional tests for QueryGeneratorTest
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / Database / QueryGeneratorTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Core\Tests\Functional\Database;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use TYPO3\CMS\Core\Database\QueryGenerator;
20 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
21
22 /**
23 * Test case
24 */
25 class QueryGeneratorTest extends FunctionalTestCase
26 {
27 /**
28 * @test
29 */
30 public function getTreeListReturnsIngoingIdIfDepthIsZero(): void
31 {
32 $id = 1;
33 $depth = 0;
34
35 $queryGenerator = new QueryGenerator();
36 $treeList = $queryGenerator->getTreeList($id, $depth);
37
38 static::assertSame($id, $treeList);
39 }
40
41 /**
42 * @test
43 */
44 public function getTreeListReturnsIngoingIdIfIdIsZero(): void
45 {
46 $id = 0;
47 $depth = 1;
48
49 $queryGenerator = new QueryGenerator();
50 $treeList = $queryGenerator->getTreeList($id, $depth);
51
52 static::assertSame($id, $treeList);
53 }
54
55 /**
56 * @test
57 */
58 public function getTreeListReturnsPositiveIngoingIdIfIdIsNegative(): void
59 {
60 $id = -1;
61 $depth = 0;
62
63 $queryGenerator = new QueryGenerator();
64 $treeList = $queryGenerator->getTreeList($id, $depth);
65
66 static::assertSame(1, $treeList);
67 }
68
69 /**
70 * @test
71 */
72 public function getTreeListReturnsEmptyStringIfIdAndDepthAreZeroAndBeginDoesNotEqualZero(): void
73 {
74 $id = 0;
75 $depth = 0;
76 $begin = 1;
77
78 $queryGenerator = new QueryGenerator();
79 $treeList = $queryGenerator->getTreeList($id, $depth, $begin);
80
81 static::assertSame('', $treeList);
82 }
83
84 /**
85 * @test
86 */
87 public function getTreeListReturnsIncomingIdIfNoSubPageRecordsOfThatIdExist(): void
88 {
89 $id = 1;
90 $depth = 1;
91
92 $queryGenerator = new QueryGenerator();
93 $treeList = $queryGenerator->getTreeList($id, $depth);
94
95 static::assertSame($id, $treeList);
96 }
97
98 /**
99 * @test
100 */
101 public function getTreeListRespectsPermClauses(): void
102 {
103 $this->importCSVDataSet(__DIR__ . '/Fixtures/DataSet/TestGetPageTreeStraightTreeSet.csv');
104
105 $id = 1;
106 $depth = 99;
107
108 $queryGenerator = new QueryGenerator();
109 $treeList = $queryGenerator->getTreeList($id, $depth, 0, 'hidden = 0');
110
111 static::assertSame('1,2,3,4,5', $treeList);
112 }
113
114 /**
115 * @test
116 * @dataProvider dataForGetTreeListReturnsListOfIdsWithBeginSetToZero
117 * @param int $id
118 * @param int $depth
119 * @param mixed $expectation
120 */
121 public function getTreeListReturnsListOfIdsWithBeginSetToZero(int $id, int $depth, $expectation): void
122 {
123 $this->importCSVDataSet(__DIR__ . '/Fixtures/DataSet/TestGetPageTreeStraightTreeSet.csv');
124
125 $queryGenerator = new QueryGenerator();
126 $treeList = $queryGenerator->getTreeList($id, $depth);
127
128 static::assertSame($expectation, $treeList);
129 }
130
131 /**
132 * @return array
133 */
134 public function dataForGetTreeListReturnsListOfIdsWithBeginSetToZero(): array
135 {
136 return [
137 // [$id, $depth, $expectation]
138 [
139 1,
140 1,
141 '1,2'
142 ],
143 [
144 1,
145 2,
146 '1,2,3'
147 ],
148 [
149 1,
150 99,
151 '1,2,3,4,5,6'
152 ],
153 [
154 2,
155 1,
156 '2,3'
157 ],
158 ];
159 }
160
161 /**
162 * @test
163 * @dataProvider dataForGetTreeListReturnsListOfIdsWithBeginSetToMinusOne
164 * @param int $id
165 * @param int $depth
166 * @param mixed $expectation
167 */
168 public function getTreeListReturnsListOfIdsWithBeginSetToMinusOne(int $id, int $depth, $expectation): void
169 {
170 $this->importCSVDataSet(__DIR__ . '/Fixtures/DataSet/TestGetPageTreeStraightTreeSet.csv');
171
172 $queryGenerator = new QueryGenerator();
173 $treeList = $queryGenerator->getTreeList($id, $depth, -1);
174
175 static::assertSame($expectation, $treeList);
176 }
177
178 /**
179 * @return array
180 */
181 public function dataForGetTreeListReturnsListOfIdsWithBeginSetToMinusOne(): array
182 {
183 return [
184 // [$id, $depth, $expectation]
185 [
186 1,
187 1,
188 ',2'
189 ],
190 [
191 1,
192 2,
193 ',2,3'
194 ],
195 [
196 1,
197 99,
198 ',2,3,4,5,6'
199 ],
200 [
201 2,
202 1,
203 ',3'
204 ],
205 ];
206 }
207
208 /**
209 * @test
210 */
211 public function getTreeListReturnsListOfPageIdsOfABranchedTreeWithBeginSetToZero(): void
212 {
213 $id = 1;
214 $depth = 3;
215
216 $this->importCSVDataSet(__DIR__ . '/Fixtures/DataSet/TestGetPageTreeBranchedTreeSet.csv');
217
218 $queryGenerator = new QueryGenerator();
219 $treeList = $queryGenerator->getTreeList($id, $depth);
220
221 static::assertSame('1,2,3,4,5', $treeList);
222 }
223
224 /**
225 * @test
226 */
227 public function getTreeListReturnsListOfPageIdsOfABranchedTreeWithBeginSetToOne(): void
228 {
229 $this->markTestSkipped('Test describes a bug in QueryGenerator::getTreeList, thus this test would fail.');
230
231 $id = 1;
232 $depth = 3;
233 $begin = 1;
234
235 $this->importCSVDataSet(__DIR__ . '/Fixtures/DataSet/TestGetPageTreeBranchedTreeSet.csv');
236
237 $queryGenerator = new QueryGenerator();
238 $treeList = $queryGenerator->getTreeList($id, $depth, $begin);
239
240 static::assertSame('2,3,4,5', $treeList);
241 // --- Expected
242 // +++ Actual
243 // @@ @@
244 // -'2,3,4,5'
245 // +'2,34,5'
246 }
247
248 /**
249 * @test
250 */
251 public function getTreeListReturnsListOfPageIdsOfABranchedTreeWithBeginSetToTwo(): void
252 {
253 $this->markTestSkipped('Test describes a bug in QueryGenerator::getTreeList, thus this test would fail.');
254
255 $id = 1;
256 $depth = 3;
257 $begin = 2;
258
259 $this->importCSVDataSet(__DIR__ . '/Fixtures/DataSet/TestGetPageTreeBranchedTreeSet.csv');
260
261 $queryGenerator = new QueryGenerator();
262 $treeList = $queryGenerator->getTreeList($id, $depth, $begin);
263
264 static::assertSame('3,5', $treeList);
265 // --- Expected
266 // +++ Actual
267 // @@ @@
268 // -'3,5'
269 // +'35'
270 }
271 }