[BUGFIX] Fix rootline translation
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Utility / RootlineUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Steffen Ritter <steffen.ritter@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Testcase for class \TYPO3\CMS\Core\Utility\RootlineUtility
29 *
30 * @author Steffen Ritter <steffen.ritter@typo3.org>
31 */
32 class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
33
34 /**
35 * @var \TYPO3\CMS\Core\Utility\RootlineUtility|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject
36 */
37 protected $fixture;
38
39 /**
40 * @var \TYPO3\CMS\Frontend\Page\PageRepository|\PHPUnit_Framework_MockObject_MockObject
41 */
42 protected $pageContextMock;
43
44 public function setUp() {
45 $this->pageContextMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
46 $this->fixture = $this->getAccessibleMock('\TYPO3\CMS\Core\Utility\RootlineUtility', array('enrichWithRelationFields'), array(1, '', $this->pageContextMock));
47 }
48
49
50 /***
51 *
52 * UTILITY FUNCTIONS
53 *
54 */
55 /**
56 * Tests that $subsetCandidate is completely part of $superset
57 * and keys match.
58 *
59 * @see (A ^ B) = A <=> A c B
60 * @param array $subsetCandidate
61 * @param array $superset
62 */
63 protected function assertIsSubset(array $subsetCandidate, array $superset) {
64 $this->assertSame($subsetCandidate, array_intersect_assoc($subsetCandidate, $superset));
65 }
66
67 /***
68 *
69 * >TEST CASES
70 *
71 */
72 /**
73 * @test
74 */
75 public function isMountedPageWithoutMountPointsReturnsFalse() {
76 $this->fixture->__construct(1);
77 $this->assertFalse($this->fixture->isMountedPage());
78 }
79
80 /**
81 * @test
82 */
83 public function isMountedPageWithMatchingMountPointParameterReturnsTrue() {
84 $this->fixture->__construct(1, '1-99');
85 $this->assertTrue($this->fixture->isMountedPage());
86 }
87
88 /**
89 * @test
90 */
91 public function isMountedPageWithNonMatchingMountPointParameterReturnsFalse() {
92 $this->fixture->__construct(1, '99-99');
93 $this->assertFalse($this->fixture->isMountedPage());
94 }
95
96 /**
97 * @test
98 * @expectedException \RuntimeException
99 */
100 public function processMountedPageWithNonMountedPageThrowsException() {
101 $this->fixture->__construct(1, '1-99');
102 $this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT));
103 }
104
105 /**
106 * @test
107 */
108 public function processMountedPageWithMountedPageNotThrowsException() {
109 $this->fixture->__construct(1, '1-99');
110 $this->assertNotEmpty($this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1)));
111 }
112
113 /**
114 * @test
115 */
116 public function processMountedPageWithMountedPageAddsMountedFromParameter() {
117 $this->fixture->__construct(1, '1-99');
118 $result = $this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
119 $this->assertTrue(isset($result['_MOUNTED_FROM']));
120 $this->assertSame(1, $result['_MOUNTED_FROM']);
121 }
122
123 /**
124 * @test
125 */
126 public function processMountedPageWithMountedPageAddsMountPointParameterToReturnValue() {
127 $this->fixture->__construct(1, '1-99');
128 $result = $this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
129 $this->assertTrue(isset($result['_MP_PARAM']));
130 $this->assertSame('1-99', $result['_MP_PARAM']);
131 }
132
133 /**
134 * @test
135 */
136 public function processMountedPageForMountPageIsOverlayAddsMountOLParameter() {
137 $this->fixture->__construct(1, '1-99');
138 $result = $this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1));
139 $this->assertTrue(isset($result['_MOUNT_OL']));
140 $this->assertSame(TRUE, $result['_MOUNT_OL']);
141 }
142
143 /**
144 * @test
145 */
146 public function processMountedPageForMountPageIsOverlayAddsDataInformationAboutMountPage() {
147 $this->fixture->__construct(1, '1-99');
148 $result = $this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1, 'pid' => 5, 'title' => 'TestCase'));
149 $this->assertTrue(isset($result['_MOUNT_PAGE']));
150 $this->assertSame(array('uid' => 99, 'pid' => 5, 'title' => 'TestCase'), $result['_MOUNT_PAGE']);
151 }
152
153 /**
154 * @test
155 */
156 public function processMountedPageForMountPageWithoutOverlayReplacesMountedPageWithMountPage() {
157 $mountPointPageData = array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 0);
158 $this->fixture->__construct(1, '1-99');
159 $result = $this->fixture->_call('processMountedPage', array('uid' => 1), $mountPointPageData);
160 $this->assertIsSubset($mountPointPageData, $result);
161 }
162
163 /**
164 * @test
165 */
166 public function columnHasRelationToResolveDetectsGroupFieldAsLocal() {
167 $this->assertFalse($this->fixture->_call('columnHasRelationToResolve', array(
168 'type' => 'group'
169 )));
170 }
171
172 /**
173 * @test
174 */
175 public function columnHasRelationToResolveDetectsGroupFieldWithMMAsRemote2() {
176 $this->assertTrue($this->fixture->_call('columnHasRelationToResolve', array(
177 'config' => array(
178 'type' => 'group',
179 'MM' => 'tx_xyz'
180 )
181 )));
182 }
183
184 /**
185 * @test
186 */
187 public function columnHasRelationToResolveDetectsInlineFieldAsLocal() {
188 $this->assertFalse($this->fixture->_call('columnHasRelationToResolve', array(
189 'config' => array(
190 'type' => 'inline'
191 )
192 )));
193 }
194
195 /**
196 * @test
197 */
198 public function columnHasRelationToResolveDetectsInlineFieldWithForeignKeyAsRemote() {
199 $this->assertTrue($this->fixture->_call('columnHasRelationToResolve', array(
200 'config' => array(
201 'type' => 'inline',
202 'foreign_field' => 'xyz'
203 )
204 )));
205 }
206
207 /**
208 * @test
209 */
210 public function columnHasRelationToResolveDetectsInlineFieldWithFMMAsRemote() {
211 $this->assertTrue($this->fixture->_call('columnHasRelationToResolve', array(
212 'config' => array(
213 'type' => 'inline',
214 'MM' => 'xyz'
215 )
216 )));
217 }
218
219 /**
220 * @test
221 */
222 public function columnHasRelationToResolveDetectsSelectFieldAsLocal() {
223 $this->assertFalse($this->fixture->_call('columnHasRelationToResolve', array(
224 'config' => array(
225 'type' => 'select'
226 )
227 )));
228 }
229
230 /**
231 * @test
232 */
233 public function columnHasRelationToResolveDetectsSelectFieldWithMMAsRemote() {
234 $this->assertTrue($this->fixture->_call('columnHasRelationToResolve', array(
235 'config' => array(
236 'type' => 'select',
237 'MM' => 'xyz'
238 )
239 )));
240 }
241
242 /**
243 * @test
244 */
245 public function getCacheIdentifierContainsAllContextParameters() {
246 $this->pageContextMock->sys_language_uid = 8;
247 $this->pageContextMock->versioningWorkspaceId = 15;
248 $this->pageContextMock->versioningPreview = TRUE;
249 $this->fixture->__construct(42, '47-11', $this->pageContextMock);
250 $this->assertSame('42_47-11_8_15_1', $this->fixture->getCacheIdentifier());
251 $this->pageContextMock->versioningPreview = FALSE;
252 $this->fixture->__construct(42, '47-11', $this->pageContextMock);
253 $this->assertSame('42_47-11_8_15_0', $this->fixture->getCacheIdentifier());
254 $this->pageContextMock->versioningWorkspaceId = 0;
255 $this->fixture->__construct(42, '47-11', $this->pageContextMock);
256 $this->assertSame('42_47-11_8_0_0', $this->fixture->getCacheIdentifier());
257 }
258
259 /**
260 * @test
261 */
262 public function getRecordArrayFetchesTranslationWhenLanguageIdIsSet() {
263 $pageData = array(
264 'uid' => 1,
265 'title' => 'Original',
266 );
267 $pageDataTranslated = array(
268 'uid' => 1,
269 'title' => 'Translated',
270 '_PAGES_OVERLAY_UID' => '2',
271 );
272
273 $this->fixture
274 ->expects($this->any())
275 ->method('enrichWithRelationFields')
276 ->with(2, $pageDataTranslated)
277 ->will($this->returnArgument(1));
278
279 $databaseConnectionMock = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
280 $databaseConnectionMock
281 ->expects($this->once())
282 ->method('exec_SELECTgetSingleRow')
283 ->will(
284 $this->returnValue($pageData)
285 );
286 $this->fixture->_set('databaseConnection',
287 $databaseConnectionMock
288 );
289
290 $this->pageContextMock
291 ->expects($this->any())
292 ->method('getPageOverlay')
293 ->will($this->returnValue($pageDataTranslated));
294
295 $this->fixture->_set('languageUid', 1);
296 $this->assertSame($pageDataTranslated, $this->fixture->_call('getRecordArray', 1));
297 }
298 }
299
300 ?>