‪TYPO3CMS  10.4
RootlineUtilityTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
29 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
30 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
31 
35 class ‪RootlineUtilityTest extends UnitTestCase
36 {
40  protected ‪$subject;
41 
46  protected function ‪setUp(): void
47  {
48  parent::setUp();
49  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
50  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
51  $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
52  $cacheManagerProphecy->getCache('rootline')->willReturn($cacheFrontendProphecy->reveal());
53 
54  $this->subject = $this->getAccessibleMock(
55  RootlineUtility::class,
56  ['enrichWithRelationFields', 'resolvePageId'],
57  [1, '', new ‪Context()]
58  );
59 
60  $this->subject->expects(self::any())->method('resolvePageId')->willReturnArgument(0);
61  }
62 
63  protected function ‪tearDown(): void
64  {
66  GeneralUtility::purgeInstances();
67  parent::tearDown();
68  }
69 
78  protected function ‪assertIsSubset(array $subsetCandidate, array $superset): void
79  {
80  self::assertSame($subsetCandidate, array_intersect_assoc($subsetCandidate, $superset));
81  }
82 
87  {
88  $this->subject->__construct(1, '', new Context());
89  self::assertFalse($this->subject->isMountedPage());
90  }
91 
96  {
97  $this->subject->__construct(1, '1-99', new Context());
98  self::assertTrue($this->subject->isMountedPage());
99  }
100 
105  {
106  $this->subject->__construct(1, '99-99', new Context());
107  self::assertFalse($this->subject->isMountedPage());
108  }
109 
114  {
115  $this->expectException(\RuntimeException::class);
116  $this->expectExceptionCode(1343464100);
117 
118  $this->subject->__construct(1, '1-99', new Context());
119  $this->subject->_call(
120  'processMountedPage',
121  ['uid' => 1],
122  ['uid' => 99, 'doktype' => ‪PageRepository::DOKTYPE_DEFAULT]
123  );
124  }
125 
130  {
131  $this->subject->__construct(1, '1-99', new Context());
132  self::assertNotEmpty($this->subject->_call(
133  'processMountedPage',
134  ['uid' => 1],
135  ['uid' => 99, 'doktype' => ‪PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]
136  ));
137  }
138 
143  {
144  $this->subject->__construct(1, '1-99', new Context());
145  $result = $this->subject->_call(
146  'processMountedPage',
147  ['uid' => 1],
148  ['uid' => 99, 'doktype' => ‪PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]
149  );
150  self::assertTrue(isset($result['_MOUNTED_FROM']));
151  self::assertSame(1, $result['_MOUNTED_FROM']);
152  }
153 
158  {
159  $this->subject->__construct(1, '1-99', new Context());
160  $result = $this->subject->_call(
161  'processMountedPage',
162  ['uid' => 1],
163  ['uid' => 99, 'doktype' => ‪PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]
164  );
165  self::assertTrue(isset($result['_MP_PARAM']));
166  self::assertSame('1-99', $result['_MP_PARAM']);
167  }
168 
173  {
174  $this->subject->__construct(1, '1-99', new Context());
175  $result = $this->subject->_call(
176  'processMountedPage',
177  ['uid' => 1],
178  ['uid' => 99, 'doktype' => ‪PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1]
179  );
180  self::assertTrue(isset($result['_MOUNT_OL']));
181  self::assertTrue($result['_MOUNT_OL']);
182  }
183 
188  {
189  $this->subject->__construct(1, '1-99', new Context());
190  $result = $this->subject->_call('processMountedPage', ['uid' => 1], [
191  'uid' => 99,
193  'mount_pid' => 1,
194  'mount_pid_ol' => 1,
195  'pid' => 5,
196  'title' => 'TestCase'
197  ]);
198  self::assertTrue(isset($result['_MOUNT_PAGE']));
199  self::assertSame(['uid' => 99, 'pid' => 5, 'title' => 'TestCase'], $result['_MOUNT_PAGE']);
200  }
201 
206  {
207  $mountPointPageData = [
208  'uid' => 99,
210  'mount_pid' => 1,
211  'mount_pid_ol' => 0
212  ];
213  $this->subject->__construct(1, '1-99', new Context());
214  $result = $this->subject->_call('processMountedPage', ['uid' => 1], $mountPointPageData);
215  $this->‪assertIsSubset($mountPointPageData, $result);
216  }
217 
222  {
223  self::assertFalse($this->subject->_call('columnHasRelationToResolve', [
224  'type' => 'group'
225  ]));
226  }
227 
232  {
233  self::assertTrue($this->subject->_call('columnHasRelationToResolve', [
234  'config' => [
235  'type' => 'group',
236  'MM' => 'tx_xyz'
237  ]
238  ]));
239  }
240 
245  {
246  self::assertFalse($this->subject->_call('columnHasRelationToResolve', [
247  'config' => [
248  'type' => 'inline'
249  ]
250  ]));
251  }
252 
257  {
258  self::assertTrue($this->subject->_call('columnHasRelationToResolve', [
259  'config' => [
260  'type' => 'inline',
261  'foreign_field' => 'xyz'
262  ]
263  ]));
264  }
265 
270  {
271  self::assertTrue($this->subject->_call('columnHasRelationToResolve', [
272  'config' => [
273  'type' => 'inline',
274  'MM' => 'xyz'
275  ]
276  ]));
277  }
278 
283  {
284  self::assertFalse($this->subject->_call('columnHasRelationToResolve', [
285  'config' => [
286  'type' => 'select'
287  ]
288  ]));
289  }
290 
295  {
296  self::assertTrue($this->subject->_call('columnHasRelationToResolve', [
297  'config' => [
298  'type' => 'select',
299  'MM' => 'xyz'
300  ]
301  ]));
302  }
303 
308  {
309  $this->subject->expects(self::any())->method('resolvePageId')->willReturn(42);
310 
311  $context = new Context();
312  $context->setAspect('workspace', new WorkspaceAspect(15));
313  $context->setAspect('language', new LanguageAspect(8, 8, ‪LanguageAspect::OVERLAYS_OFF));
314  $this->subject->__construct(42, '47-11', $context);
315  self::assertSame('42_47-11_8_15', $this->subject->getCacheIdentifier());
316  $this->subject->__construct(42, '47-11', $context);
317  self::assertSame('42_47-11_8_15', $this->subject->getCacheIdentifier());
318 
319  $context->setAspect('workspace', new WorkspaceAspect(0));
320  $this->subject->__construct(42, '47-11', $context);
321  self::assertSame('42_47-11_8_0', $this->subject->getCacheIdentifier());
322  }
323 
329  {
330  $this->subject->expects(self::any())->method('resolvePageId')->willReturn(42);
331 
333  $cacheFrontendMock = $this->getMockForAbstractClass(
334  AbstractFrontend::class,
335  [],
336  '',
337  false
338  );
339  $context = new Context();
340  $context->setAspect('workspace', new WorkspaceAspect(15));
341  $context->setAspect('language', new LanguageAspect(8, 8, ‪LanguageAspect::OVERLAYS_OFF));
342 
343  $this->subject->__construct(42, '47-11,48-12', $context);
344  self::assertTrue($cacheFrontendMock->isValidEntryIdentifier($this->subject->getCacheIdentifier()));
345  }
346 }
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest
Definition: RootlineUtilityTest.php:36
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageWithMountedPageNotThrowsException
‪processMountedPageWithMountedPageNotThrowsException()
Definition: RootlineUtilityTest.php:128
‪TYPO3\CMS\Core\Context\WorkspaceAspect
Definition: WorkspaceAspect.php:31
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\tearDown
‪tearDown()
Definition: RootlineUtilityTest.php:62
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\setUp
‪setUp()
Definition: RootlineUtilityTest.php:45
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_DEFAULT
‪const DOKTYPE_DEFAULT
Definition: PageRepository.php:103
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsGroupFieldWithMMAsRemote2
‪columnHasRelationToResolveDetectsGroupFieldWithMMAsRemote2()
Definition: RootlineUtilityTest.php:230
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageWithMountedPageAddsMountedFromParameter
‪processMountedPageWithMountedPageAddsMountedFromParameter()
Definition: RootlineUtilityTest.php:141
‪TYPO3\CMS\Core\Utility\RootlineUtility
Definition: RootlineUtility.php:39
‪TYPO3\CMS\Core\Utility\RootlineUtility\purgeCaches
‪static purgeCaches()
Definition: RootlineUtility.php:160
‪TYPO3\CMS\Core\Tests\Unit\Utility
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\assertIsSubset
‪assertIsSubset(array $subsetCandidate, array $superset)
Definition: RootlineUtilityTest.php:77
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageForMountPageIsOverlayAddsMountOLParameter
‪processMountedPageForMountPageIsOverlayAddsMountOLParameter()
Definition: RootlineUtilityTest.php:171
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsGroupFieldAsLocal
‪columnHasRelationToResolveDetectsGroupFieldAsLocal()
Definition: RootlineUtilityTest.php:220
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageWithNonMountedPageThrowsException
‪processMountedPageWithNonMountedPageThrowsException()
Definition: RootlineUtilityTest.php:112
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_MOUNTPOINT
‪const DOKTYPE_MOUNTPOINT
Definition: PageRepository.php:107
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\$subject
‪RootlineUtility AccessibleObjectInterface PHPUnit Framework MockObject MockObject $subject
Definition: RootlineUtilityTest.php:39
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsInlineFieldAsLocal
‪columnHasRelationToResolveDetectsInlineFieldAsLocal()
Definition: RootlineUtilityTest.php:243
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\isMountedPageWithNonMatchingMountPointParameterReturnsFalse
‪isMountedPageWithNonMatchingMountPointParameterReturnsFalse()
Definition: RootlineUtilityTest.php:103
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageForMountPageIsOverlayAddsDataInformationAboutMountPage
‪processMountedPageForMountPageIsOverlayAddsDataInformationAboutMountPage()
Definition: RootlineUtilityTest.php:186
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\isMountedPageWithoutMountPointsReturnsFalse
‪isMountedPageWithoutMountPointsReturnsFalse()
Definition: RootlineUtilityTest.php:85
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:35
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageForMountPageWithoutOverlayReplacesMountedPageWithMountPage
‪processMountedPageForMountPageWithoutOverlayReplacesMountedPageWithMountPage()
Definition: RootlineUtilityTest.php:204
‪TYPO3\CMS\Core\Context\LanguageAspect
Definition: LanguageAspect.php:57
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsInlineFieldWithForeignKeyAsRemote
‪columnHasRelationToResolveDetectsInlineFieldWithForeignKeyAsRemote()
Definition: RootlineUtilityTest.php:255
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageWithMountedPageAddsMountPointParameterToReturnValue
‪processMountedPageWithMountedPageAddsMountPointParameterToReturnValue()
Definition: RootlineUtilityTest.php:156
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsInlineFieldWithFMMAsRemote
‪columnHasRelationToResolveDetectsInlineFieldWithFMMAsRemote()
Definition: RootlineUtilityTest.php:268
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\getCacheIdentifierReturnsValidIdentifierWithCommasInMountPointParameter
‪getCacheIdentifierReturnsValidIdentifierWithCommasInMountPointParameter()
Definition: RootlineUtilityTest.php:327
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsSelectFieldWithMMAsRemote
‪columnHasRelationToResolveDetectsSelectFieldWithMMAsRemote()
Definition: RootlineUtilityTest.php:293
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_OFF
‪const OVERLAYS_OFF
Definition: LanguageAspect.php:74
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\isMountedPageWithMatchingMountPointParameterReturnsTrue
‪isMountedPageWithMatchingMountPointParameterReturnsTrue()
Definition: RootlineUtilityTest.php:94
‪TYPO3\CMS\Core\Domain\Repository\PageRepository
Definition: PageRepository.php:52
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsSelectFieldAsLocal
‪columnHasRelationToResolveDetectsSelectFieldAsLocal()
Definition: RootlineUtilityTest.php:281
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\getCacheIdentifierContainsAllContextParameters
‪getCacheIdentifierContainsAllContextParameters()
Definition: RootlineUtilityTest.php:306
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
Definition: AbstractFrontend.php:27