[CLEANUP] Make use of possible imports and remove unused ones
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Functional / Page / PageRepositoryTest.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Functional\Page;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Frontend\Page\PageRepository;
18
19 /**
20 * Test case
21 */
22 class PageRepositoryTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
23
24 protected $coreExtensionsToLoad = array('frontend');
25
26 protected function setUp() {
27 parent::setUp();
28 $this->importDataSet(__DIR__ . '/../Fixtures/pages.xml');
29 $this->pagerepo = new PageRepository();
30 $this->pagerepo->init(false);
31 }
32
33 /**
34 * @test
35 */
36 public function getMenuSingleUidRoot() {
37 $rows = $this->pagerepo->getMenu(1, 'uid, title');
38 $this->assertArrayHasKey(2, $rows);
39 $this->assertArrayHasKey(3, $rows);
40 $this->assertArrayHasKey(4, $rows);
41 $this->assertCount(3, $rows);
42 }
43
44 /**
45 * @test
46 */
47 public function getMenuSingleUidSubpage() {
48 $rows = $this->pagerepo->getMenu(2, 'uid, title');
49 $this->assertArrayHasKey(5, $rows);
50 $this->assertArrayHasKey(6, $rows);
51 $this->assertArrayHasKey(7, $rows);
52 $this->assertCount(3, $rows);
53 }
54
55 /**
56 * @test
57 */
58 public function getMenuMulipleUid() {
59 $rows = $this->pagerepo->getMenu(array(2, 3), 'uid, title');
60 $this->assertArrayHasKey(5, $rows);
61 $this->assertArrayHasKey(6, $rows);
62 $this->assertArrayHasKey(7, $rows);
63 $this->assertArrayHasKey(8, $rows);
64 $this->assertArrayHasKey(9, $rows);
65 $this->assertCount(5, $rows);
66 }
67
68 /**
69 * @test
70 */
71 public function getMenuPageOverlay() {
72 $this->pagerepo->sys_language_uid = 1;
73
74 $rows = $this->pagerepo->getMenu(array(2, 3), 'uid, title');
75 $this->assertEquals('Attrappe 1-2-5', $rows[5]['title']);
76 $this->assertEquals('Attrappe 1-2-6', $rows[6]['title']);
77 $this->assertEquals('Dummy 1-2-7', $rows[7]['title']);
78 $this->assertEquals('Dummy 1-3-8', $rows[8]['title']);
79 $this->assertEquals('Attrappe 1-3-9', $rows[9]['title']);
80 $this->assertCount(5, $rows);
81 }
82
83 /**
84 * @test
85 */
86 public function getPageOverlayById() {
87 $row = $this->pagerepo->getPageOverlay(1, 1);
88 $this->assertOverlayRow($row);
89 $this->assertEquals('Wurzel 1', $row['title']);
90 $this->assertEquals('901', $row['_PAGES_OVERLAY_UID']);
91 $this->assertEquals(1, $row['_PAGES_OVERLAY_LANGUAGE']);
92 }
93
94 /**
95 * @test
96 */
97 public function getPageOverlayByIdWithoutTranslation() {
98 $row = $this->pagerepo->getPageOverlay(4, 1);
99 $this->assertInternalType('array', $row);
100 $this->assertCount(0, $row);
101 }
102
103 /**
104 * @test
105 */
106 public function getPageOverlayByRow() {
107 $orig = $this->pagerepo->getPage(1);
108 $row = $this->pagerepo->getPageOverlay($orig, 1);
109 $this->assertOverlayRow($row);
110 $this->assertEquals(1, $row['uid']);
111 $this->assertEquals('Wurzel 1', $row['title']);
112 $this->assertEquals('901', $row['_PAGES_OVERLAY_UID']);
113 $this->assertEquals(1, $row['_PAGES_OVERLAY_LANGUAGE']);
114 }
115
116 /**
117 * @test
118 */
119 public function getPageOverlayByRowWithoutTranslation() {
120 $orig = $this->pagerepo->getPage(4);
121 $row = $this->pagerepo->getPageOverlay($orig, 1);
122 $this->assertInternalType('array', $row);
123 $this->assertEquals(4, $row['uid']);
124 $this->assertEquals('Dummy 1-4', $row['title']);//original title
125 }
126
127 /**
128 * @test
129 */
130 public function getPagesOverlayByIdSingle() {
131 $this->pagerepo->sys_language_uid = 1;
132 $rows = $this->pagerepo->getPagesOverlay(array(1));
133 $this->assertInternalType('array', $rows);
134 $this->assertCount(1, $rows);
135 $this->assertArrayHasKey(0, $rows);
136
137 $row = $rows[0];
138 $this->assertOverlayRow($row);
139 $this->assertEquals('Wurzel 1', $row['title']);
140 $this->assertEquals('901', $row['_PAGES_OVERLAY_UID']);
141 $this->assertEquals(1, $row['_PAGES_OVERLAY_LANGUAGE']);
142 }
143
144 /**
145 * @test
146 */
147 public function getPagesOverlayByIdMultiple() {
148 $this->pagerepo->sys_language_uid = 1;
149 $rows = $this->pagerepo->getPagesOverlay(array(1, 5));
150 $this->assertInternalType('array', $rows);
151 $this->assertCount(2, $rows);
152 $this->assertArrayHasKey(0, $rows);
153 $this->assertArrayHasKey(1, $rows);
154
155 $row = $rows[0];
156 $this->assertOverlayRow($row);
157 $this->assertEquals('Wurzel 1', $row['title']);
158 $this->assertEquals('901', $row['_PAGES_OVERLAY_UID']);
159 $this->assertEquals(1, $row['_PAGES_OVERLAY_LANGUAGE']);
160
161 $row = $rows[1];
162 $this->assertOverlayRow($row);
163 $this->assertEquals('Attrappe 1-2-5', $row['title']);
164 $this->assertEquals('904', $row['_PAGES_OVERLAY_UID']);
165 $this->assertEquals(1, $row['_PAGES_OVERLAY_LANGUAGE']);
166 }
167
168 /**
169 * @test
170 */
171 public function getPagesOverlayByIdMultipleSomeNotOverlaid() {
172 $this->pagerepo->sys_language_uid = 1;
173 $rows = $this->pagerepo->getPagesOverlay(array(1, 4, 5, 8));
174 $this->assertInternalType('array', $rows);
175 $this->assertCount(2, $rows);
176 $this->assertArrayHasKey(0, $rows);
177 $this->assertArrayHasKey(2, $rows);
178
179 $row = $rows[0];
180 $this->assertOverlayRow($row);
181 $this->assertEquals('Wurzel 1', $row['title']);
182
183 $row = $rows[2];
184 $this->assertOverlayRow($row);
185 $this->assertEquals('Attrappe 1-2-5', $row['title']);
186 }
187
188 /**
189 * @test
190 */
191 public function getPagesOverlayByRowSingle() {
192 $origRow = $this->pagerepo->getPage(1);
193
194 $this->pagerepo->sys_language_uid = 1;
195 $rows = $this->pagerepo->getPagesOverlay(array($origRow));
196 $this->assertInternalType('array', $rows);
197 $this->assertCount(1, $rows);
198 $this->assertArrayHasKey(0, $rows);
199
200 $row = $rows[0];
201 $this->assertOverlayRow($row);
202 $this->assertEquals('Wurzel 1', $row['title']);
203 $this->assertEquals('901', $row['_PAGES_OVERLAY_UID']);
204 $this->assertEquals(1, $row['_PAGES_OVERLAY_LANGUAGE']);
205 }
206
207 /**
208 * @test
209 */
210 public function getPagesOverlayByRowMultiple() {
211 $orig1 = $this->pagerepo->getPage(1);
212 $orig2 = $this->pagerepo->getPage(5);
213
214 $this->pagerepo->sys_language_uid = 1;
215 $rows = $this->pagerepo->getPagesOverlay(array(1 => $orig1, 5 => $orig2));
216 $this->assertInternalType('array', $rows);
217 $this->assertCount(2, $rows);
218 $this->assertArrayHasKey(1, $rows);
219 $this->assertArrayHasKey(5, $rows);
220
221 $row = $rows[1];
222 $this->assertOverlayRow($row);
223 $this->assertEquals('Wurzel 1', $row['title']);
224 $this->assertEquals('901', $row['_PAGES_OVERLAY_UID']);
225 $this->assertEquals(1, $row['_PAGES_OVERLAY_LANGUAGE']);
226
227 $row = $rows[5];
228 $this->assertOverlayRow($row);
229 $this->assertEquals('Attrappe 1-2-5', $row['title']);
230 $this->assertEquals('904', $row['_PAGES_OVERLAY_UID']);
231 $this->assertEquals(1, $row['_PAGES_OVERLAY_LANGUAGE']);
232 }
233
234 /**
235 * @test
236 */
237 public function getPagesOverlayByRowMultipleSomeNotOverlaid() {
238 $orig1 = $this->pagerepo->getPage(1);
239 $orig2 = $this->pagerepo->getPage(7);
240 $orig3 = $this->pagerepo->getPage(9);
241
242 $this->pagerepo->sys_language_uid = 1;
243 $rows = $this->pagerepo->getPagesOverlay(array($orig1, $orig2, $orig3));
244 $this->assertInternalType('array', $rows);
245 $this->assertCount(3, $rows);
246 $this->assertArrayHasKey(0, $rows);
247 $this->assertArrayHasKey(1, $rows);
248 $this->assertArrayHasKey(2, $rows);
249
250 $row = $rows[0];
251 $this->assertOverlayRow($row);
252 $this->assertEquals('Wurzel 1', $row['title']);
253
254 $row = $rows[1];
255 $this->assertNotOverlayRow($row);
256 $this->assertEquals('Dummy 1-2-7', $row['title']);
257
258 $row = $rows[2];
259 $this->assertOverlayRow($row);
260 $this->assertEquals('Attrappe 1-3-9', $row['title']);
261 }
262
263 protected function assertOverlayRow($row) {
264 $this->assertInternalType('array', $row);
265
266 $this->assertArrayHasKey('_PAGES_OVERLAY', $row);
267 $this->assertArrayHasKey('_PAGES_OVERLAY_UID', $row);
268 $this->assertArrayHasKey('_PAGES_OVERLAY_LANGUAGE', $row);
269
270 $this->assertTrue($row['_PAGES_OVERLAY']);
271 }
272
273 protected function assertNotOverlayRow($row) {
274 $this->assertInternalType('array', $row);
275
276 $this->assertFalse(isset($row['_PAGES_OVERLAY']));
277 $this->assertFalse(isset($row['_PAGES_OVERLAY_UID']));
278 $this->assertFalse(isset($row['_PAGES_OVERLAY_LANGUAGE']));
279 }
280 }