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