‪TYPO3CMS  11.5
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 
20 use PHPUnit\Framework\MockObject\MockObject;
21 use Prophecy\PhpUnit\ProphecyTrait;
32 use TYPO3\TestingFramework\Core\AccessibleObjectInterface;
33 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
34 
38 class ‪RootlineUtilityTest extends UnitTestCase
39 {
40  use ProphecyTrait;
41 
45  protected ‪$subject;
46 
51  protected function ‪setUp(): void
52  {
53  parent::setUp();
54  $cacheManagerProphecy = $this->prophesize(CacheManager::class);
55  GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManagerProphecy->reveal());
56  $cacheFrontendProphecy = $this->prophesize(FrontendInterface::class);
57  $cacheManagerProphecy->getCache('rootline')->willReturn($cacheFrontendProphecy->reveal());
58 
59  $this->subject = $this->getAccessibleMock(
60  RootlineUtility::class,
61  ['enrichWithRelationFields', 'resolvePageId'],
62  [1, '', new ‪Context()]
63  );
64 
65  $this->subject->method('resolvePageId')->willReturnArgument(0);
66  }
67 
68  protected function ‪tearDown(): void
69  {
71  GeneralUtility::purgeInstances();
72  parent::tearDown();
73  }
74 
83  protected function ‪assertIsSubset(array $subsetCandidate, array $superset): void
84  {
85  self::assertSame($subsetCandidate, array_intersect_assoc($subsetCandidate, $superset));
86  }
87 
92  {
93  $this->subject->__construct(1, '', new Context());
94  self::assertFalse($this->subject->isMountedPage());
95  }
96 
101  {
102  $this->subject->__construct(1, '1-99', new Context());
103  self::assertTrue($this->subject->isMountedPage());
104  }
105 
110  {
111  $this->subject->__construct(1, '99-99', new Context());
112  self::assertFalse($this->subject->isMountedPage());
113  }
114 
119  {
120  $this->expectException(\RuntimeException::class);
121  $this->expectExceptionCode(1343464100);
122 
123  $this->subject->__construct(1, '1-99', new Context());
124  $this->subject->_call(
125  'processMountedPage',
126  ['uid' => 1],
127  ['uid' => 99, 'doktype' => ‪PageRepository::DOKTYPE_DEFAULT]
128  );
129  }
130 
135  {
136  $this->subject->__construct(1, '1-99', new Context());
137  self::assertNotEmpty($this->subject->_call(
138  'processMountedPage',
139  ['uid' => 1],
140  ['uid' => 99, 'doktype' => ‪PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]
141  ));
142  }
143 
148  {
149  $this->subject->__construct(1, '1-99', new Context());
150  $result = $this->subject->_call(
151  'processMountedPage',
152  ['uid' => 1],
153  ['uid' => 99, 'doktype' => ‪PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]
154  );
155  self::assertTrue(isset($result['_MOUNTED_FROM']));
156  self::assertSame(1, $result['_MOUNTED_FROM']);
157  }
158 
163  {
164  $this->subject->__construct(1, '1-99', new Context());
165  $result = $this->subject->_call(
166  'processMountedPage',
167  ['uid' => 1],
168  ['uid' => 99, 'doktype' => ‪PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]
169  );
170  self::assertTrue(isset($result['_MP_PARAM']));
171  self::assertSame('1-99', $result['_MP_PARAM']);
172  }
173 
178  {
179  $this->subject->__construct(1, '1-99', new Context());
180  $result = $this->subject->_call(
181  'processMountedPage',
182  ['uid' => 1],
183  ['uid' => 99, 'doktype' => ‪PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1]
184  );
185  self::assertTrue(isset($result['_MOUNT_OL']));
186  self::assertTrue($result['_MOUNT_OL']);
187  }
188 
193  {
194  $this->subject->__construct(1, '1-99', new Context());
195  $result = $this->subject->_call('processMountedPage', ['uid' => 1], [
196  'uid' => 99,
198  'mount_pid' => 1,
199  'mount_pid_ol' => 1,
200  'pid' => 5,
201  'title' => 'TestCase',
202  ]);
203  self::assertTrue(isset($result['_MOUNT_PAGE']));
204  self::assertSame(['uid' => 99, 'pid' => 5, 'title' => 'TestCase'], $result['_MOUNT_PAGE']);
205  }
206 
211  {
212  $mountPointPageData = [
213  'uid' => 99,
215  'mount_pid' => 1,
216  'mount_pid_ol' => 0,
217  ];
218  $this->subject->__construct(1, '1-99', new Context());
219  $result = $this->subject->_call('processMountedPage', ['uid' => 1], $mountPointPageData);
220  $this->‪assertIsSubset($mountPointPageData, $result);
221  }
222 
227  {
228  self::assertFalse($this->subject->_call('columnHasRelationToResolve', [
229  'type' => 'group',
230  ]));
231  }
232 
237  {
238  self::assertTrue($this->subject->_call('columnHasRelationToResolve', [
239  'config' => [
240  'type' => 'group',
241  'MM' => 'tx_xyz',
242  ],
243  ]));
244  }
245 
250  {
251  self::assertFalse($this->subject->_call('columnHasRelationToResolve', [
252  'config' => [
253  'type' => 'inline',
254  ],
255  ]));
256  }
257 
262  {
263  self::assertTrue($this->subject->_call('columnHasRelationToResolve', [
264  'config' => [
265  'type' => 'inline',
266  'foreign_field' => 'xyz',
267  ],
268  ]));
269  }
270 
275  {
276  self::assertTrue($this->subject->_call('columnHasRelationToResolve', [
277  'config' => [
278  'type' => 'inline',
279  'MM' => 'xyz',
280  ],
281  ]));
282  }
283 
288  {
289  self::assertFalse($this->subject->_call('columnHasRelationToResolve', [
290  'config' => [
291  'type' => 'select',
292  ],
293  ]));
294  }
295 
300  {
301  self::assertTrue($this->subject->_call('columnHasRelationToResolve', [
302  'config' => [
303  'type' => 'select',
304  'MM' => 'xyz',
305  ],
306  ]));
307  }
308 
313  {
314  $this->subject->method('resolvePageId')->willReturn(42);
315 
316  $context = new Context();
317  $context->setAspect('workspace', new WorkspaceAspect(15));
318  $context->setAspect('visibility', new VisibilityAspect());
319  $context->setAspect('language', new LanguageAspect(8, 8, ‪LanguageAspect::OVERLAYS_OFF));
320  $this->subject->__construct(42, '47-11', $context);
321  self::assertSame('42_47-11_8_15_0', $this->subject->getCacheIdentifier());
322  $this->subject->__construct(42, '47-11', $context);
323  self::assertSame('42_47-11_8_15_0', $this->subject->getCacheIdentifier());
324 
325  $context->setAspect('workspace', new WorkspaceAspect(0));
326  $this->subject->__construct(42, '47-11', $context);
327  self::assertSame('42_47-11_8_0_0', $this->subject->getCacheIdentifier());
328  }
329 
335  {
336  $this->subject->method('resolvePageId')->willReturn(42);
337 
338  $cacheFrontendMock = $this->getMockForAbstractClass(
339  AbstractFrontend::class,
340  [],
341  '',
342  false
343  );
344  $context = new Context();
345  $context->setAspect('workspace', new WorkspaceAspect(15));
346  $context->setAspect('language', new LanguageAspect(8, 8, ‪LanguageAspect::OVERLAYS_OFF));
347 
348  $this->subject->__construct(42, '47-11,48-12', $context);
349  self::assertTrue($cacheFrontendMock->isValidEntryIdentifier($this->subject->getCacheIdentifier()));
350  }
351 }
‪TYPO3\CMS\Core\Context\VisibilityAspect
Definition: VisibilityAspect.php:31
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest
Definition: RootlineUtilityTest.php:39
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageWithMountedPageNotThrowsException
‪processMountedPageWithMountedPageNotThrowsException()
Definition: RootlineUtilityTest.php:132
‪TYPO3\CMS\Core\Context\WorkspaceAspect
Definition: WorkspaceAspect.php:31
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\$subject
‪RootlineUtility AccessibleObjectInterface MockObject $subject
Definition: RootlineUtilityTest.php:43
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\tearDown
‪tearDown()
Definition: RootlineUtilityTest.php:66
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\setUp
‪setUp()
Definition: RootlineUtilityTest.php:49
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_DEFAULT
‪const DOKTYPE_DEFAULT
Definition: PageRepository.php:110
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsGroupFieldWithMMAsRemote2
‪columnHasRelationToResolveDetectsGroupFieldWithMMAsRemote2()
Definition: RootlineUtilityTest.php:234
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageWithMountedPageAddsMountedFromParameter
‪processMountedPageWithMountedPageAddsMountedFromParameter()
Definition: RootlineUtilityTest.php:145
‪TYPO3\CMS\Core\Utility\RootlineUtility
Definition: RootlineUtility.php:38
‪TYPO3\CMS\Core\Utility\RootlineUtility\purgeCaches
‪static purgeCaches()
Definition: RootlineUtility.php:155
‪TYPO3\CMS\Core\Tests\Unit\Utility
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\assertIsSubset
‪assertIsSubset(array $subsetCandidate, array $superset)
Definition: RootlineUtilityTest.php:81
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageForMountPageIsOverlayAddsMountOLParameter
‪processMountedPageForMountPageIsOverlayAddsMountOLParameter()
Definition: RootlineUtilityTest.php:175
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsGroupFieldAsLocal
‪columnHasRelationToResolveDetectsGroupFieldAsLocal()
Definition: RootlineUtilityTest.php:224
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageWithNonMountedPageThrowsException
‪processMountedPageWithNonMountedPageThrowsException()
Definition: RootlineUtilityTest.php:116
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_MOUNTPOINT
‪const DOKTYPE_MOUNTPOINT
Definition: PageRepository.php:114
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsInlineFieldAsLocal
‪columnHasRelationToResolveDetectsInlineFieldAsLocal()
Definition: RootlineUtilityTest.php:247
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\isMountedPageWithNonMatchingMountPointParameterReturnsFalse
‪isMountedPageWithNonMatchingMountPointParameterReturnsFalse()
Definition: RootlineUtilityTest.php:107
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageForMountPageIsOverlayAddsDataInformationAboutMountPage
‪processMountedPageForMountPageIsOverlayAddsDataInformationAboutMountPage()
Definition: RootlineUtilityTest.php:190
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\isMountedPageWithoutMountPointsReturnsFalse
‪isMountedPageWithoutMountPointsReturnsFalse()
Definition: RootlineUtilityTest.php:89
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:36
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageForMountPageWithoutOverlayReplacesMountedPageWithMountPage
‪processMountedPageForMountPageWithoutOverlayReplacesMountedPageWithMountPage()
Definition: RootlineUtilityTest.php:208
‪TYPO3\CMS\Core\Context\LanguageAspect
Definition: LanguageAspect.php:57
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsInlineFieldWithForeignKeyAsRemote
‪columnHasRelationToResolveDetectsInlineFieldWithForeignKeyAsRemote()
Definition: RootlineUtilityTest.php:259
‪TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
Definition: FrontendInterface.php:22
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\processMountedPageWithMountedPageAddsMountPointParameterToReturnValue
‪processMountedPageWithMountedPageAddsMountPointParameterToReturnValue()
Definition: RootlineUtilityTest.php:160
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsInlineFieldWithFMMAsRemote
‪columnHasRelationToResolveDetectsInlineFieldWithFMMAsRemote()
Definition: RootlineUtilityTest.php:272
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\getCacheIdentifierReturnsValidIdentifierWithCommasInMountPointParameter
‪getCacheIdentifierReturnsValidIdentifierWithCommasInMountPointParameter()
Definition: RootlineUtilityTest.php:332
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsSelectFieldWithMMAsRemote
‪columnHasRelationToResolveDetectsSelectFieldWithMMAsRemote()
Definition: RootlineUtilityTest.php:297
‪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:98
‪TYPO3\CMS\Core\Domain\Repository\PageRepository
Definition: PageRepository.php:53
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\columnHasRelationToResolveDetectsSelectFieldAsLocal
‪columnHasRelationToResolveDetectsSelectFieldAsLocal()
Definition: RootlineUtilityTest.php:285
‪TYPO3\CMS\Core\Tests\Unit\Utility\RootlineUtilityTest\getCacheIdentifierContainsAllContextParameters
‪getCacheIdentifierContainsAllContextParameters()
Definition: RootlineUtilityTest.php:310
‪TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend
Definition: AbstractFrontend.php:26