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