2 namespace TYPO3\CMS\Frontend\Tests\Functional\Page
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Frontend\Page\PageRepository
;
18 use TYPO3\CMS\Core\Tests\FunctionalTestCase
;
23 class PageRepositoryTest
extends FunctionalTestCase
{
25 protected $coreExtensionsToLoad = array('frontend');
28 * @var \TYPO3\CMS\Frontend\Page\PageRepository
32 protected function setUp() {
34 $this->importDataSet(__DIR__
. '/../Fixtures/pages.xml');
35 $this->pageRepo
= new PageRepository();
36 $this->pageRepo
->init(FALSE);
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);
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);
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);
77 public function getMenuPageOverlay() {
78 $this->pageRepo
->sys_language_uid
= 1;
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);
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']);
103 public function getPageOverlayByIdWithoutTranslation() {
104 $row = $this->pageRepo
->getPageOverlay(4, 1);
105 $this->assertInternalType('array', $row);
106 $this->assertCount(0, $row);
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']);
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
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);
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']);
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);
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']);
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']);
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);
186 $this->assertOverlayRow($row);
187 $this->assertEquals('Wurzel 1', $row['title']);
190 $this->assertOverlayRow($row);
191 $this->assertEquals('Attrappe 1-2-5', $row['title']);
197 public function getPagesOverlayByRowSingle() {
198 $origRow = $this->pageRepo
->getPage(1);
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);
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']);
216 public function getPagesOverlayByRowMultiple() {
217 $orig1 = $this->pageRepo
->getPage(1);
218 $orig2 = $this->pageRepo
->getPage(5);
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);
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']);
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']);
243 public function getPagesOverlayByRowMultipleSomeNotOverlaid() {
244 $orig1 = $this->pageRepo
->getPage(1);
245 $orig2 = $this->pageRepo
->getPage(7);
246 $orig3 = $this->pageRepo
->getPage(9);
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);
257 $this->assertOverlayRow($row);
258 $this->assertEquals('Wurzel 1', $row['title']);
261 $this->assertNotOverlayRow($row);
262 $this->assertEquals('Dummy 1-2-7', $row['title']);
265 $this->assertOverlayRow($row);
266 $this->assertEquals('Attrappe 1-3-9', $row['title']);
269 protected function assertOverlayRow($row) {
270 $this->assertInternalType('array', $row);
272 $this->assertArrayHasKey('_PAGES_OVERLAY', $row);
273 $this->assertArrayHasKey('_PAGES_OVERLAY_UID', $row);
274 $this->assertArrayHasKey('_PAGES_OVERLAY_LANGUAGE', $row);
276 $this->assertTrue($row['_PAGES_OVERLAY']);
279 protected function assertNotOverlayRow($row) {
280 $this->assertInternalType('array', $row);
282 $this->assertFalse(isset($row['_PAGES_OVERLAY']));
283 $this->assertFalse(isset($row['_PAGES_OVERLAY_UID']));
284 $this->assertFalse(isset($row['_PAGES_OVERLAY_LANGUAGE']));