362245b83c13202873306c475859c18d06b335e2
[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 * 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\Utility\RootlineUtility;
18
19 /**
20 * Testcase for class \TYPO3\CMS\Core\Utility\RootlineUtility
21 */
22 class RootlineUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
23 {
24 /**
25 * Subject is not notice free, disable E_NOTICES
26 */
27 protected static $suppressNotices = true;
28
29 /**
30 * @var RootlineUtility|\TYPO3\TestingFramework\Core\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject
31 */
32 protected $subject;
33
34 /**
35 * @var \TYPO3\CMS\Frontend\Page\PageRepository|\PHPUnit_Framework_MockObject_MockObject
36 */
37 protected $pageContextMock;
38
39 protected function setUp()
40 {
41 $this->pageContextMock = $this->createMock(\TYPO3\CMS\Frontend\Page\PageRepository::class);
42 $this->subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Utility\RootlineUtility::class, ['enrichWithRelationFields'], [1, '', $this->pageContextMock]);
43 }
44
45 protected function tearDown()
46 {
47 parent::tearDown();
48 RootlineUtility::purgeCaches();
49 }
50
51 /***
52 *
53 * UTILITY FUNCTIONS
54 *
55 */
56 /**
57 * Tests that $subsetCandidate is completely part of $superset
58 * and keys match.
59 *
60 * @see (A ^ B) = A <=> A c B
61 * @param array $subsetCandidate
62 * @param array $superset
63 */
64 protected function assertIsSubset(array $subsetCandidate, array $superset)
65 {
66 $this->assertSame($subsetCandidate, array_intersect_assoc($subsetCandidate, $superset));
67 }
68
69 /***
70 *
71 * >TEST CASES
72 *
73 */
74 /**
75 * @test
76 */
77 public function isMountedPageWithoutMountPointsReturnsFalse()
78 {
79 $this->subject->__construct(1);
80 $this->assertFalse($this->subject->isMountedPage());
81 }
82
83 /**
84 * @test
85 */
86 public function isMountedPageWithMatchingMountPointParameterReturnsTrue()
87 {
88 $this->subject->__construct(1, '1-99');
89 $this->assertTrue($this->subject->isMountedPage());
90 }
91
92 /**
93 * @test
94 */
95 public function isMountedPageWithNonMatchingMountPointParameterReturnsFalse()
96 {
97 $this->subject->__construct(1, '99-99');
98 $this->assertFalse($this->subject->isMountedPage());
99 }
100
101 /**
102 * @test
103 */
104 public function processMountedPageWithNonMountedPageThrowsException()
105 {
106 $this->expectException(\RuntimeException::class);
107 $this->expectExceptionCode(1343464100);
108
109 $this->subject->__construct(1, '1-99');
110 $this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT]);
111 }
112
113 /**
114 * @test
115 */
116 public function processMountedPageWithMountedPageNotThrowsException()
117 {
118 $this->subject->__construct(1, '1-99');
119 $this->assertNotEmpty($this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]));
120 }
121
122 /**
123 * @test
124 */
125 public function processMountedPageWithMountedPageAddsMountedFromParameter()
126 {
127 $this->subject->__construct(1, '1-99');
128 $result = $this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]);
129 $this->assertTrue(isset($result['_MOUNTED_FROM']));
130 $this->assertSame(1, $result['_MOUNTED_FROM']);
131 }
132
133 /**
134 * @test
135 */
136 public function processMountedPageWithMountedPageAddsMountPointParameterToReturnValue()
137 {
138 $this->subject->__construct(1, '1-99');
139 $result = $this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]);
140 $this->assertTrue(isset($result['_MP_PARAM']));
141 $this->assertSame('1-99', $result['_MP_PARAM']);
142 }
143
144 /**
145 * @test
146 */
147 public function processMountedPageForMountPageIsOverlayAddsMountOLParameter()
148 {
149 $this->subject->__construct(1, '1-99');
150 $result = $this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1]);
151 $this->assertTrue(isset($result['_MOUNT_OL']));
152 $this->assertSame(true, $result['_MOUNT_OL']);
153 }
154
155 /**
156 * @test
157 */
158 public function processMountedPageForMountPageIsOverlayAddsDataInformationAboutMountPage()
159 {
160 $this->subject->__construct(1, '1-99');
161 $result = $this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1, 'pid' => 5, 'title' => 'TestCase']);
162 $this->assertTrue(isset($result['_MOUNT_PAGE']));
163 $this->assertSame(['uid' => 99, 'pid' => 5, 'title' => 'TestCase'], $result['_MOUNT_PAGE']);
164 }
165
166 /**
167 * @test
168 */
169 public function processMountedPageForMountPageWithoutOverlayReplacesMountedPageWithMountPage()
170 {
171 $mountPointPageData = ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 0];
172 $this->subject->__construct(1, '1-99');
173 $result = $this->subject->_call('processMountedPage', ['uid' => 1], $mountPointPageData);
174 $this->assertIsSubset($mountPointPageData, $result);
175 }
176
177 /**
178 * @test
179 */
180 public function columnHasRelationToResolveDetectsGroupFieldAsLocal()
181 {
182 $this->assertFalse($this->subject->_call('columnHasRelationToResolve', [
183 'type' => 'group'
184 ]));
185 }
186
187 /**
188 * @test
189 */
190 public function columnHasRelationToResolveDetectsGroupFieldWithMMAsRemote2()
191 {
192 $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
193 'config' => [
194 'type' => 'group',
195 'MM' => 'tx_xyz'
196 ]
197 ]));
198 }
199
200 /**
201 * @test
202 */
203 public function columnHasRelationToResolveDetectsInlineFieldAsLocal()
204 {
205 $this->assertFalse($this->subject->_call('columnHasRelationToResolve', [
206 'config' => [
207 'type' => 'inline'
208 ]
209 ]));
210 }
211
212 /**
213 * @test
214 */
215 public function columnHasRelationToResolveDetectsInlineFieldWithForeignKeyAsRemote()
216 {
217 $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
218 'config' => [
219 'type' => 'inline',
220 'foreign_field' => 'xyz'
221 ]
222 ]));
223 }
224
225 /**
226 * @test
227 */
228 public function columnHasRelationToResolveDetectsInlineFieldWithFMMAsRemote()
229 {
230 $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
231 'config' => [
232 'type' => 'inline',
233 'MM' => 'xyz'
234 ]
235 ]));
236 }
237
238 /**
239 * @test
240 */
241 public function columnHasRelationToResolveDetectsSelectFieldAsLocal()
242 {
243 $this->assertFalse($this->subject->_call('columnHasRelationToResolve', [
244 'config' => [
245 'type' => 'select'
246 ]
247 ]));
248 }
249
250 /**
251 * @test
252 */
253 public function columnHasRelationToResolveDetectsSelectFieldWithMMAsRemote()
254 {
255 $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
256 'config' => [
257 'type' => 'select',
258 'MM' => 'xyz'
259 ]
260 ]));
261 }
262
263 /**
264 * @test
265 */
266 public function getCacheIdentifierContainsAllContextParameters()
267 {
268 $this->pageContextMock->sys_language_uid = 8;
269 $this->pageContextMock->versioningWorkspaceId = 15;
270 $this->pageContextMock->versioningPreview = true;
271 $this->subject->__construct(42, '47-11', $this->pageContextMock);
272 $this->assertSame('42_47-11_8_15_1', $this->subject->getCacheIdentifier());
273 $this->pageContextMock->versioningPreview = false;
274 $this->subject->__construct(42, '47-11', $this->pageContextMock);
275 $this->assertSame('42_47-11_8_15_0', $this->subject->getCacheIdentifier());
276 $this->pageContextMock->versioningWorkspaceId = 0;
277 $this->subject->__construct(42, '47-11', $this->pageContextMock);
278 $this->assertSame('42_47-11_8_0_0', $this->subject->getCacheIdentifier());
279 }
280
281 /**
282 * @test
283 */
284 public function getCacheIdentifierReturnsValidIdentifierWithCommasInMountPointParameter()
285 {
286 /** @var \TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend $cacheFrontendMock */
287 $cacheFrontendMock = $this->getMockForAbstractClass(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], '', false);
288 $this->pageContextMock->sys_language_uid = 8;
289 $this->pageContextMock->versioningWorkspaceId = 15;
290 $this->pageContextMock->versioningPreview = true;
291 $this->subject->__construct(42, '47-11,48-12', $this->pageContextMock);
292 $this->assertTrue($cacheFrontendMock->isValidEntryIdentifier($this->subject->getCacheIdentifier()));
293 }
294 }