TYPO3 CMS  TYPO3_7-6
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 
23 {
27  protected $subject;
28 
32  protected $pageContextMock;
33 
34  protected function setUp()
35  {
36  $this->pageContextMock = $this->getMock(\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 
101  {
102  $this->subject->__construct(1, '1-99');
103  $this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT]);
104  }
105 
110  {
111  $this->subject->__construct(1, '1-99');
112  $this->assertNotEmpty($this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]));
113  }
114 
119  {
120  $this->subject->__construct(1, '1-99');
121  $result = $this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]);
122  $this->assertTrue(isset($result['_MOUNTED_FROM']));
123  $this->assertSame(1, $result['_MOUNTED_FROM']);
124  }
125 
130  {
131  $this->subject->__construct(1, '1-99');
132  $result = $this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1]);
133  $this->assertTrue(isset($result['_MP_PARAM']));
134  $this->assertSame('1-99', $result['_MP_PARAM']);
135  }
136 
141  {
142  $this->subject->__construct(1, '1-99');
143  $result = $this->subject->_call('processMountedPage', ['uid' => 1], ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1]);
144  $this->assertTrue(isset($result['_MOUNT_OL']));
145  $this->assertSame(true, $result['_MOUNT_OL']);
146  }
147 
152  {
153  $this->subject->__construct(1, '1-99');
154  $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']);
155  $this->assertTrue(isset($result['_MOUNT_PAGE']));
156  $this->assertSame(['uid' => 99, 'pid' => 5, 'title' => 'TestCase'], $result['_MOUNT_PAGE']);
157  }
158 
163  {
164  $mountPointPageData = ['uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 0];
165  $this->subject->__construct(1, '1-99');
166  $result = $this->subject->_call('processMountedPage', ['uid' => 1], $mountPointPageData);
167  $this->assertIsSubset($mountPointPageData, $result);
168  }
169 
174  {
175  $this->assertFalse($this->subject->_call('columnHasRelationToResolve', [
176  'type' => 'group'
177  ]));
178  }
179 
184  {
185  $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
186  'config' => [
187  'type' => 'group',
188  'MM' => 'tx_xyz'
189  ]
190  ]));
191  }
192 
197  {
198  $this->assertFalse($this->subject->_call('columnHasRelationToResolve', [
199  'config' => [
200  'type' => 'inline'
201  ]
202  ]));
203  }
204 
209  {
210  $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
211  'config' => [
212  'type' => 'inline',
213  'foreign_field' => 'xyz'
214  ]
215  ]));
216  }
217 
222  {
223  $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
224  'config' => [
225  'type' => 'inline',
226  'MM' => 'xyz'
227  ]
228  ]));
229  }
230 
235  {
236  $this->assertFalse($this->subject->_call('columnHasRelationToResolve', [
237  'config' => [
238  'type' => 'select'
239  ]
240  ]));
241  }
242 
247  {
248  $this->assertTrue($this->subject->_call('columnHasRelationToResolve', [
249  'config' => [
250  'type' => 'select',
251  'MM' => 'xyz'
252  ]
253  ]));
254  }
255 
260  {
261  $this->pageContextMock->sys_language_uid = 8;
262  $this->pageContextMock->versioningWorkspaceId = 15;
263  $this->pageContextMock->versioningPreview = true;
264  $this->subject->__construct(42, '47-11', $this->pageContextMock);
265  $this->assertSame('42_47-11_8_15_1', $this->subject->getCacheIdentifier());
266  $this->pageContextMock->versioningPreview = false;
267  $this->subject->__construct(42, '47-11', $this->pageContextMock);
268  $this->assertSame('42_47-11_8_15_0', $this->subject->getCacheIdentifier());
269  $this->pageContextMock->versioningWorkspaceId = 0;
270  $this->subject->__construct(42, '47-11', $this->pageContextMock);
271  $this->assertSame('42_47-11_8_0_0', $this->subject->getCacheIdentifier());
272  }
273 
277  public function getCacheIdentifierReturnsValidIdentifierWithCommasInMountPointParameter()
278  {
280  $cacheFrontendMock = $this->getMockForAbstractClass(\TYPO3\CMS\Core\Cache\Frontend\AbstractFrontend::class, [], '', false);
281  $this->pageContextMock->sys_language_uid = 8;
282  $this->pageContextMock->versioningWorkspaceId = 15;
283  $this->pageContextMock->versioningPreview = true;
284  $this->subject->__construct(42, '47-11,48-12', $this->pageContextMock);
285  $this->assertTrue($cacheFrontendMock->isValidEntryIdentifier($this->subject->getCacheIdentifier()));
286  }
287 
292  {
293  $pageData = [
294  'uid' => 1,
295  'title' => 'Original',
296  ];
297  $pageDataTranslated = [
298  'uid' => 1,
299  'title' => 'Translated',
300  '_PAGES_OVERLAY_UID' => '2',
301  ];
302 
303  $this->subject
304  ->expects($this->any())
305  ->method('enrichWithRelationFields')
306  ->with(2, $pageDataTranslated)
307  ->will($this->returnArgument(1));
308 
309  $databaseConnectionMock = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class);
310  $databaseConnectionMock
311  ->expects($this->once())
312  ->method('exec_SELECTgetSingleRow')
313  ->will(
314  $this->returnValue($pageData)
315  );
316  $this->subject->_set('databaseConnection',
317  $databaseConnectionMock
318  );
319 
320  $this->pageContextMock
321  ->expects($this->any())
322  ->method('getPageOverlay')
323  ->will($this->returnValue($pageDataTranslated));
324 
325  $this->subject->_set('languageUid', 1);
326  $this->assertSame($pageDataTranslated, $this->subject->_call('getRecordArray', 1));
327  }
328 
333  {
334  $mockDatabaseConnection = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, ['exec_SELECTgetRows'], [], '', false);
335  $subject = $this->getAccessibleMock(\TYPO3\CMS\Core\Utility\RootlineUtility::class, ['columnHasRelationToResolve'], [1, '', $this->pageContextMock]);
336  $subject->_set('databaseConnection', $mockDatabaseConnection);
337  $GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields'] = '';
338  $foreign_table = $this->getUniqueId('foreign_table');
339  $foreign_field = $this->getUniqueId('foreign_field');
340  $GLOBALS['TCA'][$foreign_table]['ctrl']['enablecolumns']['disabled'] = $this->getUniqueId('disabled');
341  $GLOBALS['TCA']['pages']['columns'] = [
342  'test' => [
343  'config' => [
344  'foreign_table' => $foreign_table,
345  'foreign_field' => $foreign_field
346  ]
347  ]
348  ];
349  $expected = [
350  $foreign_field . ' = 0',
351  $foreign_table . '.' . $GLOBALS['TCA'][$foreign_table]['ctrl']['enablecolumns']['disabled'] . ' = 0'
352  ];
353  $this->pageContextMock->expects($this->once())->method('deleteClause')->will($this->returnValue(''));
354  $mockDatabaseConnection->expects(
355  $this->once())->
356  method('exec_SELECTgetRows')->
357  with('uid', $foreign_table, implode(' AND ', $expected), '', '', '', '')->
358  // the return value does not matter much, it is only here to prevent error messages from further code execution
359  will($this->returnValue(['uid' => 17])
360  );
361  $subject->expects($this->once())->method('columnHasRelationToResolve')->will($this->returnValue(true));
362  $subject->_call('enrichWithRelationFields', 17, []);
363  }
364 }
assertIsSubset(array $subsetCandidate, array $superset)
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']