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