‪TYPO3CMS  9.5
RootlineUtilityTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
28 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
34 class ‪RootlineUtilityTest extends UnitTestCase
35 {
39  protected ‪$subject;
40 
45  protected function ‪setUp(): void
46  {
47  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
48  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
49  $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
50  $cacheManagerProphecy->getCache('cache_rootline')->willReturn($cacheFrontendProphecy->reveal());
51 
52  $this->subject = $this->getAccessibleMock(
53  RootlineUtility::class,
54  ['enrichWithRelationFields', 'resolvePageId'],
55  [1, '', new ‪Context()]
56  );
57 
58  $this->subject->expects(static::any())->method('resolvePageId')->willReturnArgument(0);
59  }
60 
64  protected function ‪tearDown(): void
65  {
67  GeneralUtility::purgeInstances();
68  parent::tearDown();
69  }
70 
79  protected function ‪assertIsSubset(array $subsetCandidate, array $superset): void
80  {
81  $this->assertSame($subsetCandidate, array_intersect_assoc($subsetCandidate, $superset));
82  }
83 
88  {
89  $this->subject->__construct(1, '', new ‪Context());
90  $this->assertFalse($this->subject->isMountedPage());
91  }
92 
97  {
98  $this->subject->__construct(1, '1-99', new ‪Context());
99  $this->assertTrue($this->subject->isMountedPage());
100  }
101 
106  {
107  $this->subject->__construct(1, '99-99', new ‪Context());
108  $this->assertFalse($this->subject->isMountedPage());
109  }
110 
115  {
116  $this->expectException(\RuntimeException::class);
117  $this->expectExceptionCode(1343464100);
118 
119  $this->subject->__construct(1, '1-99', new ‪Context());
120  $this->subject->_call(
121  'processMountedPage',
122  ['uid' => 1],
123  ['uid' => 99, 'doktype' => ‪PageRepository::DOKTYPE_DEFAULT]
124  );
125  }
126 
131  {
132  $this->subject->__construct(1, '1-99', new ‪Context());
133  $this->assertNotEmpty($this->subject->_call(
134  'processMountedPage',
135  ['uid' => 1],
136  ['uid' => 99, 'doktype' => ‪PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]
137  ));
138  }
139 
144  {
145  $this->subject->__construct(1, '1-99', new ‪Context());
146  $result = $this->subject->_call(
147  'processMountedPage',
148  ['uid' => 1],
149  ['uid' => 99, 'doktype' => ‪PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]
150  );
151  $this->assertTrue(isset($result['_MOUNTED_FROM']));
152  $this->assertSame(1, $result['_MOUNTED_FROM']);
153  }
154 
159  {
160  $this->subject->__construct(1, '1-99', new ‪Context());
161  $result = $this->subject->_call(
162  'processMountedPage',
163  ['uid' => 1],
164  ['uid' => 99, 'doktype' => ‪PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]
165  );
166  $this->assertTrue(isset($result['_MP_PARAM']));
167  $this->assertSame('1-99', $result['_MP_PARAM']);
168  }
169 
174  {
175  $this->subject->__construct(1, '1-99', new ‪Context());
176  $result = $this->subject->_call(
177  'processMountedPage',
178  ['uid' => 1],
179  ['uid' => 99, 'doktype' => ‪PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1]
180  );
181  $this->assertTrue(isset($result['_MOUNT_OL']));
182  $this->assertSame(true, $result['_MOUNT_OL']);
183  }
184 
189  {
190  $this->subject->__construct(1, '1-99', new ‪Context());
191  $result = $this->subject->_call('processMountedPage', ['uid' => 1], [
192  'uid' => 99,
194  'mount_pid' => 1,
195  'mount_pid_ol' => 1,
196  'pid' => 5,
197  'title' => 'TestCase'
198  ]);
199  $this->assertTrue(isset($result['_MOUNT_PAGE']));
200  $this->assertSame(['uid' => 99, 'pid' => 5, 'title' => 'TestCase'], $result['_MOUNT_PAGE']);
201  }
202 
207  {
208  $mountPointPageData = [
209  'uid' => 99,
211  'mount_pid' => 1,
212  'mount_pid_ol' => 0
213  ];
214  $this->subject->__construct(1, '1-99', new ‪Context());
215  $result = $this->subject->_call('processMountedPage', ['uid' => 1], $mountPointPageData);
216  $this->‪assertIsSubset($mountPointPageData, $result);
217  }
218 
223  {
224  $this->assertFalse($this->subject->_call('columnHasRelationToResolve', [
225  'type' => 'group'
226  ]));
227  }
228 
233  {
234  $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
235  'config' => [
236  'type' => 'group',
237  'MM' => 'tx_xyz'
238  ]
239  ]));
240  }
241 
246  {
247  $this->assertFalse($this->subject->_call('columnHasRelationToResolve', [
248  'config' => [
249  'type' => 'inline'
250  ]
251  ]));
252  }
253 
258  {
259  $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
260  'config' => [
261  'type' => 'inline',
262  'foreign_field' => 'xyz'
263  ]
264  ]));
265  }
266 
271  {
272  $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
273  'config' => [
274  'type' => 'inline',
275  'MM' => 'xyz'
276  ]
277  ]));
278  }
279 
284  {
285  $this->assertFalse($this->subject->_call('columnHasRelationToResolve', [
286  'config' => [
287  'type' => 'select'
288  ]
289  ]));
290  }
291 
296  {
297  $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
298  'config' => [
299  'type' => 'select',
300  'MM' => 'xyz'
301  ]
302  ]));
303  }
304 
309  {
310  $this->subject->expects(static::any())->method('resolvePageId')->willReturn(42);
311 
312  $context = new ‪Context();
313  $context->setAspect('workspace', new ‪WorkspaceAspect(15));
314  $context->setAspect('language', new ‪LanguageAspect(8, 8, ‪LanguageAspect::OVERLAYS_OFF));
315  $this->subject->__construct(42, '47-11', $context);
316  $this->assertSame('42_47-11_8_15', $this->subject->getCacheIdentifier());
317  $this->subject->__construct(42, '47-11', $context);
318  $this->assertSame('42_47-11_8_15', $this->subject->getCacheIdentifier());
319 
320  $context->setAspect('workspace', new ‪WorkspaceAspect(0));
321  $this->subject->__construct(42, '47-11', $context);
322  $this->assertSame('42_47-11_8_0', $this->subject->getCacheIdentifier());
323  }
324 
330  {
331  $this->subject->expects(static::any())->method('resolvePageId')->willReturn(42);
332 
334  $cacheFrontendMock = $this->getMockForAbstractClass(
335  AbstractFrontend::class,
336  [],
337  '',
338  false
339  );
340  $context = new ‪Context();
341  $context->setAspect('workspace', new ‪WorkspaceAspect(15));
342  $context->setAspect('language', new ‪LanguageAspect(8, 8, ‪LanguageAspect::OVERLAYS_OFF));
343 
344  $this->subject->__construct(42, '47-11,48-12', $context);
345  $this->assertTrue($cacheFrontendMock->isValidEntryIdentifier($this->subject->getCacheIdentifier()));
346  }
347 }
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest
Definition: RootlineUtilityTest.php:35
‪TYPO3\CMS\Frontend\Page\PageRepository\DOKTYPE_MOUNTPOINT
‪const DOKTYPE_MOUNTPOINT
Definition: PageRepository.php:172
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageWithMountedPageNotThrowsException
‪processMountedPageWithMountedPageNotThrowsException()
Definition: RootlineUtilityTest.php:129
‪TYPO3\CMS\Core\Context\WorkspaceAspect
Definition: WorkspaceAspect.php:29
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\tearDown
‪tearDown()
Definition: RootlineUtilityTest.php:63
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\setUp
‪setUp()
Definition: RootlineUtilityTest.php:44
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsGroupFieldWithMMAsRemote2
‪columnHasRelationToResolveDetectsGroupFieldWithMMAsRemote2()
Definition: RootlineUtilityTest.php:231
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageWithMountedPageAddsMountedFromParameter
‪processMountedPageWithMountedPageAddsMountedFromParameter()
Definition: RootlineUtilityTest.php:142
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\$subject
‪RootlineUtility AccessibleObjectInterface PHPUnit_Framework_MockObject_MockObject $subject
Definition: RootlineUtilityTest.php:38
‪TYPO3\CMS\Core\Utility\RootlineUtility
Definition: RootlineUtility.php:36
‪TYPO3\CMS\Core\Utility\RootlineUtility\purgeCaches
‪static purgeCaches()
Definition: RootlineUtility.php:164
‪TYPO3\CMS\Core\Tests\Unit\Utility
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\assertIsSubset
‪assertIsSubset(array $subsetCandidate, array $superset)
Definition: RootlineUtilityTest.php:78
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:49
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageForMountPageIsOverlayAddsMountOLParameter
‪processMountedPageForMountPageIsOverlayAddsMountOLParameter()
Definition: RootlineUtilityTest.php:172
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsGroupFieldAsLocal
‪columnHasRelationToResolveDetectsGroupFieldAsLocal()
Definition: RootlineUtilityTest.php:221
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageWithNonMountedPageThrowsException
‪processMountedPageWithNonMountedPageThrowsException()
Definition: RootlineUtilityTest.php:113
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsInlineFieldAsLocal
‪columnHasRelationToResolveDetectsInlineFieldAsLocal()
Definition: RootlineUtilityTest.php:244
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\isMountedPageWithNonMatchingMountPointParameterReturnsFalse
‪isMountedPageWithNonMatchingMountPointParameterReturnsFalse()
Definition: RootlineUtilityTest.php:104
‪TYPO3\CMS\Frontend\Page\PageRepository
Definition: PageRepository.php:53
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageForMountPageIsOverlayAddsDataInformationAboutMountPage
‪processMountedPageForMountPageIsOverlayAddsDataInformationAboutMountPage()
Definition: RootlineUtilityTest.php:187
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\isMountedPageWithoutMountPointsReturnsFalse
‪isMountedPageWithoutMountPointsReturnsFalse()
Definition: RootlineUtilityTest.php:86
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Frontend\Page\PageRepository\DOKTYPE_DEFAULT
‪const DOKTYPE_DEFAULT
Definition: PageRepository.php:168
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageForMountPageWithoutOverlayReplacesMountedPageWithMountPage
‪processMountedPageForMountPageWithoutOverlayReplacesMountedPageWithMountPage()
Definition: RootlineUtilityTest.php:205
‪TYPO3\CMS\Core\Context\LanguageAspect
Definition: LanguageAspect.php:55
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsInlineFieldWithForeignKeyAsRemote
‪columnHasRelationToResolveDetectsInlineFieldWithForeignKeyAsRemote()
Definition: RootlineUtilityTest.php:256
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:21
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageWithMountedPageAddsMountPointParameterToReturnValue
‪processMountedPageWithMountedPageAddsMountPointParameterToReturnValue()
Definition: RootlineUtilityTest.php:157
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsInlineFieldWithFMMAsRemote
‪columnHasRelationToResolveDetectsInlineFieldWithFMMAsRemote()
Definition: RootlineUtilityTest.php:269
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\getCacheIdentifierReturnsValidIdentifierWithCommasInMountPointParameter
‪getCacheIdentifierReturnsValidIdentifierWithCommasInMountPointParameter()
Definition: RootlineUtilityTest.php:328
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsSelectFieldWithMMAsRemote
‪columnHasRelationToResolveDetectsSelectFieldWithMMAsRemote()
Definition: RootlineUtilityTest.php:294
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_OFF
‪const OVERLAYS_OFF
Definition: LanguageAspect.php:72
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\isMountedPageWithMatchingMountPointParameterReturnsTrue
‪isMountedPageWithMatchingMountPointParameterReturnsTrue()
Definition: RootlineUtilityTest.php:95
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsSelectFieldAsLocal
‪columnHasRelationToResolveDetectsSelectFieldAsLocal()
Definition: RootlineUtilityTest.php:282
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\getCacheIdentifierContainsAllContextParameters
‪getCacheIdentifierContainsAllContextParameters()
Definition: RootlineUtilityTest.php:307
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
Definition: AbstractFrontend.php:26