TYPO3 CMS  TYPO3_8-7
RootlineUtilityTest.php
Go to the documentation of this file.
1 <?php
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 
18 
22 class RootlineUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
23 {
27  protected $subject;
28 
32  protected $pageContextMock;
33 
34  protected function setUp()
35  {
36  $this->pageContextMock = $this->createMock(\TYPO3\CMS\Frontend\Page\PageRepository::class);
37  $this->subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Utility\RootlineUtility::class, ['enrichWithRelationFields'], [1, '', $this->pageContextMock]);
38  }
39 
40  protected function tearDown()
41  {
42  parent::tearDown();
44  }
45 
46  /***
47  *
48  * UTILITY FUNCTIONS
49  *
50  */
59  protected function assertIsSubset(array $subsetCandidate, array $superset)
60  {
61  $this->assertSame($subsetCandidate, array_intersect_assoc($subsetCandidate, $superset));
62  }
63 
64  /***
65  *
66  * >TEST CASES
67  *
68  */
73  {
74  $this->subject->__construct(1);
75  $this->assertFalse($this->subject->isMountedPage());
76  }
77 
82  {
83  $this->subject->__construct(1, '1-99');
84  $this->assertTrue($this->subject->isMountedPage());
85  }
86 
91  {
92  $this->subject->__construct(1, '99-99');
93  $this->assertFalse($this->subject->isMountedPage());
94  }
95 
100  {
101  $this->expectException(\RuntimeException::class);
102  $this->expectExceptionCode(1343464100);
103 
104  $this->subject->__construct(1, '1-99');
105  $this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT]);
106  }
107 
112  {
113  $this->subject->__construct(1, '1-99');
114  $this->assertNotEmpty($this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]));
115  }
116 
121  {
122  $this->subject->__construct(1, '1-99');
123  $result = $this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]);
124  $this->assertTrue(isset($result['_MOUNTED_FROM']));
125  $this->assertSame(1, $result['_MOUNTED_FROM']);
126  }
127 
132  {
133  $this->subject->__construct(1, '1-99');
134  $result = $this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]);
135  $this->assertTrue(isset($result['_MP_PARAM']));
136  $this->assertSame('1-99', $result['_MP_PARAM']);
137  }
138 
143  {
144  $this->subject->__construct(1, '1-99');
145  $result = $this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1]);
146  $this->assertTrue(isset($result['_MOUNT_OL']));
147  $this->assertSame(true, $result['_MOUNT_OL']);
148  }
149 
154  {
155  $this->subject->__construct(1, '1-99');
156  $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']);
157  $this->assertTrue(isset($result['_MOUNT_PAGE']));
158  $this->assertSame(['uid' => 99, 'pid' => 5, 'title' => 'TestCase'], $result['_MOUNT_PAGE']);
159  }
160 
165  {
166  $mountPointPageData = ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 0];
167  $this->subject->__construct(1, '1-99');
168  $result = $this->subject->_call('processMountedPage', ['uid' => 1], $mountPointPageData);
169  $this->assertIsSubset($mountPointPageData, $result);
170  }
171 
176  {
177  $this->assertFalse($this->subject->_call('columnHasRelationToResolve', [
178  'type' => 'group'
179  ]));
180  }
181 
186  {
187  $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
188  'config' => [
189  'type' => 'group',
190  'MM' => 'tx_xyz'
191  ]
192  ]));
193  }
194 
199  {
200  $this->assertFalse($this->subject->_call('columnHasRelationToResolve', [
201  'config' => [
202  'type' => 'inline'
203  ]
204  ]));
205  }
206 
211  {
212  $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
213  'config' => [
214  'type' => 'inline',
215  'foreign_field' => 'xyz'
216  ]
217  ]));
218  }
219 
224  {
225  $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
226  'config' => [
227  'type' => 'inline',
228  'MM' => 'xyz'
229  ]
230  ]));
231  }
232 
237  {
238  $this->assertFalse($this->subject->_call('columnHasRelationToResolve', [
239  'config' => [
240  'type' => 'select'
241  ]
242  ]));
243  }
244 
249  {
250  $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
251  'config' => [
252  'type' => 'select',
253  'MM' => 'xyz'
254  ]
255  ]));
256  }
257 
262  {
263  $this->pageContextMock->sys_language_uid = 8;
264  $this->pageContextMock->versioningWorkspaceId = 15;
265  $this->pageContextMock->versioningPreview = true;
266  $this->subject->__construct(42, '47-11', $this->pageContextMock);
267  $this->assertSame('42_47-11_8_15_1', $this->subject->getCacheIdentifier());
268  $this->pageContextMock->versioningPreview = false;
269  $this->subject->__construct(42, '47-11', $this->pageContextMock);
270  $this->assertSame('42_47-11_8_15_0', $this->subject->getCacheIdentifier());
271  $this->pageContextMock->versioningWorkspaceId = 0;
272  $this->subject->__construct(42, '47-11', $this->pageContextMock);
273  $this->assertSame('42_47-11_8_0_0', $this->subject->getCacheIdentifier());
274  }
275 
279  public function getCacheIdentifierReturnsValidIdentifierWithCommasInMountPointParameter()
280  {
282  $cacheFrontendMock = $this->getMockForAbstractClass(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], '', false);
283  $this->pageContextMock->sys_language_uid = 8;
284  $this->pageContextMock->versioningWorkspaceId = 15;
285  $this->pageContextMock->versioningPreview = true;
286  $this->subject->__construct(42, '47-11,48-12', $this->pageContextMock);
287  $this->assertTrue($cacheFrontendMock->isValidEntryIdentifier($this->subject->getCacheIdentifier()));
288  }
289 }
assertIsSubset(array $subsetCandidate, array $superset)