[BUGFIX] Apc Cache backend has side effects
[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 require_once __DIR__ . '/Fixtures/RootlineUtilityTestAccessibleFixture.php';
28
29 /**
30 * Testcase for class \TYPO3\CMS\Core\Utility\RootlineUtility
31 *
32 * @author Steffen Ritter <steffen.ritter@typo3.org>
33 */
34 class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
35
36 /***
37 *
38 * UTILITY FUNCTIONS
39 *
40 */
41 /**
42 * Tests that $subsetCandidate is completely part of $superset
43 * and keys match.
44 *
45 * @see (A ^ B) = A <=> A c B
46 * @param array $subsetCandidate
47 * @param array $superset
48 */
49 protected function assertIsSubset(array $subsetCandidate, array $superset) {
50 $this->assertSame($subsetCandidate, array_intersect_assoc($subsetCandidate, $superset));
51 }
52
53 /***
54 *
55 * >TEST CASES
56 *
57 */
58 /**
59 * @test
60 */
61 public function isMountedPageWithoutMountPointsReturnsFalse() {
62 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
63 $this->assertFalse($fixture->isMountedPage());
64 }
65
66 /**
67 * @test
68 */
69 public function isMountedPageWithMatchingMountPointParameterReturnsTrue() {
70 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
71 $this->assertTrue($fixture->isMountedPage());
72 }
73
74 /**
75 * @test
76 */
77 public function isMountedPageWithNonMatchingMountPointParameterReturnsFalse() {
78 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '99-99');
79 $this->assertFalse($fixture->isMountedPage());
80 }
81
82 /**
83 * @test
84 * @expectedException \RuntimeException
85 */
86 public function processMountedPageWithNonMountedPageThrowsException() {
87 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
88 $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT));
89 }
90
91 /**
92 * @test
93 */
94 public function processMountedPageWithMountedPageNotThrowsException() {
95 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
96 $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
97 }
98
99 /**
100 * @test
101 */
102 public function processMountedPageWithMountedPageAddsMountedFromParameter() {
103 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
104 $result = $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
105 $this->assertTrue(isset($result['_MOUNTED_FROM']));
106 $this->assertSame(1, $result['_MOUNTED_FROM']);
107 }
108
109 /**
110 * @test
111 */
112 public function processMountedPageWithMountedPageAddsMountPointParameterToReturnValue() {
113 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
114 $result = $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
115 $this->assertTrue(isset($result['_MP_PARAM']));
116 $this->assertSame('1-99', $result['_MP_PARAM']);
117 }
118
119 /**
120 * @test
121 */
122 public function processMountedPageForMountPageIsOverlayAddsMountOLParameter() {
123 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
124 $result = $fixture->processMountedPage(array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1));
125 $this->assertTrue(isset($result['_MOUNT_OL']));
126 $this->assertSame(TRUE, $result['_MOUNT_OL']);
127 }
128
129 /**
130 * @test
131 */
132 public function processMountedPageForMountPageIsOverlayAddsDataInformationAboutMountPage() {
133 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
134 $result = $fixture->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'));
135 $this->assertTrue(isset($result['_MOUNT_PAGE']));
136 $this->assertSame(array('uid' => 99, 'pid' => 5, 'title' => 'TestCase'), $result['_MOUNT_PAGE']);
137 }
138
139 /**
140 * @test
141 */
142 public function processMountedPageForMountPageWithoutOverlayReplacesMountedPageWithMountPage() {
143 $a = array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 0);
144 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1, '1-99');
145 $result = $fixture->processMountedPage(array('uid' => 1), $a);
146 $this->assertIsSubset($a, $result);
147 }
148
149 /**
150 * @test
151 */
152 public function columnHasRelationToResolveDetectsGroupFieldAsLocal() {
153 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
154 $this->assertFalse($fixture->columnHasRelationToResolve(array(
155 'type' => 'group'
156 )));
157 }
158
159 /**
160 * @test
161 */
162 public function columnHasRelationToResolveDetectsGroupFieldWithMMAsRemote() {
163 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
164 $this->assertTrue($fixture->columnHasRelationToResolve(array(
165 'config' => array(
166 'type' => 'group',
167 'MM' => 'tx_xyz'
168 )
169 )));
170 }
171
172 /**
173 * @test
174 */
175 public function columnHasRelationToResolveDetectsInlineFieldAsLocal() {
176 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
177 $this->assertFalse($fixture->columnHasRelationToResolve(array(
178 'config' => array(
179 'type' => 'inline'
180 )
181 )));
182 }
183
184 /**
185 * @test
186 */
187 public function columnHasRelationToResolveDetectsInlineFieldWithForeignKeyAsRemote() {
188 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
189 $this->assertTrue($fixture->columnHasRelationToResolve(array(
190 'config' => array(
191 'type' => 'inline',
192 'foreign_field' => 'xyz'
193 )
194 )));
195 }
196
197 /**
198 * @test
199 */
200 public function columnHasRelationToResolveDetectsInlineFieldWithFMMAsRemote() {
201 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
202 $this->assertTrue($fixture->columnHasRelationToResolve(array(
203 'config' => array(
204 'type' => 'inline',
205 'MM' => 'xyz'
206 )
207 )));
208 }
209
210 /**
211 * @test
212 */
213 public function columnHasRelationToResolveDetectsSelectFieldAsLocal() {
214 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
215 $this->assertFalse($fixture->columnHasRelationToResolve(array(
216 'config' => array(
217 'type' => 'select'
218 )
219 )));
220 }
221
222 /**
223 * @test
224 */
225 public function columnHasRelationToResolveDetectsSelectFieldWithMMAsRemote() {
226 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(1);
227 $this->assertTrue($fixture->columnHasRelationToResolve(array(
228 'config' => array(
229 'type' => 'select',
230 'MM' => 'xyz'
231 )
232 )));
233 }
234
235 /**
236 * @test
237 */
238 public function getCacheIdentifierContainsAllContextParameters() {
239 $pageContext = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
240 $pageContext->sys_language_uid = 8;
241 $pageContext->versioningWorkspaceId = 15;
242 $pageContext->versioningPreview = TRUE;
243 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(42, '47-11', $pageContext);
244 $this->assertSame('42_47-11_8_15_1', $fixture->getCacheIdentifier());
245 $pageContext->versioningPreview = FALSE;
246 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(42, '47-11', $pageContext);
247 $this->assertSame('42_47-11_8_15_0', $fixture->getCacheIdentifier());
248 $pageContext->versioningWorkspaceId = 0;
249 $fixture = new Fixtures\RootlineUtilityTestAccessibleFixture(42, '47-11', $pageContext);
250 $this->assertSame('42_47-11_8_0_0', $fixture->getCacheIdentifier());
251 }
252
253 }
254
255 ?>