TYPO3 CMS  TYPO3_6-2
RootlineUtilityTest.php
Go to the documentation of this file.
1 <?php
3 
18 
25 
29  protected $fixture;
30 
34  protected $pageContextMock;
35 
36  protected function setUp() {
37  $this->pageContextMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
38  $this->fixture = $this->getAccessibleMock('TYPO3\\CMS\\Core\\Utility\\RootlineUtility', array('enrichWithRelationFields'), array(1, '', $this->pageContextMock));
39  }
40 
41  protected function tearDown() {
42  parent::tearDown();
44  }
45 
46  /***
47  *
48  * UTILITY FUNCTIONS
49  *
50  */
59  protected function assertIsSubset(array $subsetCandidate, array $superset) {
60  $this->assertSame($subsetCandidate, array_intersect_assoc($subsetCandidate, $superset));
61  }
62 
63  /***
64  *
65  * >TEST CASES
66  *
67  */
72  $this->fixture->__construct(1);
73  $this->assertFalse($this->fixture->isMountedPage());
74  }
75 
80  $this->fixture->__construct(1, '1-99');
81  $this->assertTrue($this->fixture->isMountedPage());
82  }
83 
88  $this->fixture->__construct(1, '99-99');
89  $this->assertFalse($this->fixture->isMountedPage());
90  }
91 
97  $this->fixture->__construct(1, '1-99');
98  $this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_DEFAULT));
99  }
100 
105  $this->fixture->__construct(1, '1-99');
106  $this->assertNotEmpty($this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1)));
107  }
108 
113  $this->fixture->__construct(1, '1-99');
114  $result = $this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
115  $this->assertTrue(isset($result['_MOUNTED_FROM']));
116  $this->assertSame(1, $result['_MOUNTED_FROM']);
117  }
118 
123  $this->fixture->__construct(1, '1-99');
124  $result = $this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1));
125  $this->assertTrue(isset($result['_MP_PARAM']));
126  $this->assertSame('1-99', $result['_MP_PARAM']);
127  }
128 
133  $this->fixture->__construct(1, '1-99');
134  $result = $this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1));
135  $this->assertTrue(isset($result['_MOUNT_OL']));
136  $this->assertSame(TRUE, $result['_MOUNT_OL']);
137  }
138 
143  $this->fixture->__construct(1, '1-99');
144  $result = $this->fixture->_call('processMountedPage', array('uid' => 1), array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1, 'pid' => 5, 'title' => 'TestCase'));
145  $this->assertTrue(isset($result['_MOUNT_PAGE']));
146  $this->assertSame(array('uid' => 99, 'pid' => 5, 'title' => 'TestCase'), $result['_MOUNT_PAGE']);
147  }
148 
153  $mountPointPageData = array('uid' => 99, 'doktype' => \TYPO3\CMS\Frontend\Page\PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 0);
154  $this->fixture->__construct(1, '1-99');
155  $result = $this->fixture->_call('processMountedPage', array('uid' => 1), $mountPointPageData);
156  $this->assertIsSubset($mountPointPageData, $result);
157  }
158 
163  $this->assertFalse($this->fixture->_call('columnHasRelationToResolve', array(
164  'type' => 'group'
165  )));
166  }
167 
172  $this->assertTrue($this->fixture->_call('columnHasRelationToResolve', array(
173  'config' => array(
174  'type' => 'group',
175  'MM' => 'tx_xyz'
176  )
177  )));
178  }
179 
184  $this->assertFalse($this->fixture->_call('columnHasRelationToResolve', array(
185  'config' => array(
186  'type' => 'inline'
187  )
188  )));
189  }
190 
195  $this->assertTrue($this->fixture->_call('columnHasRelationToResolve', array(
196  'config' => array(
197  'type' => 'inline',
198  'foreign_field' => 'xyz'
199  )
200  )));
201  }
202 
207  $this->assertTrue($this->fixture->_call('columnHasRelationToResolve', array(
208  'config' => array(
209  'type' => 'inline',
210  'MM' => 'xyz'
211  )
212  )));
213  }
214 
219  $this->assertFalse($this->fixture->_call('columnHasRelationToResolve', array(
220  'config' => array(
221  'type' => 'select'
222  )
223  )));
224  }
225 
230  $this->assertTrue($this->fixture->_call('columnHasRelationToResolve', array(
231  'config' => array(
232  'type' => 'select',
233  'MM' => 'xyz'
234  )
235  )));
236  }
237 
242  $this->pageContextMock->sys_language_uid = 8;
243  $this->pageContextMock->versioningWorkspaceId = 15;
244  $this->pageContextMock->versioningPreview = TRUE;
245  $this->fixture->__construct(42, '47-11', $this->pageContextMock);
246  $this->assertSame('42_47-11_8_15_1', $this->fixture->getCacheIdentifier());
247  $this->pageContextMock->versioningPreview = FALSE;
248  $this->fixture->__construct(42, '47-11', $this->pageContextMock);
249  $this->assertSame('42_47-11_8_15_0', $this->fixture->getCacheIdentifier());
250  $this->pageContextMock->versioningWorkspaceId = 0;
251  $this->fixture->__construct(42, '47-11', $this->pageContextMock);
252  $this->assertSame('42_47-11_8_0_0', $this->fixture->getCacheIdentifier());
253  }
254 
258  public function getCacheIdentifierReturnsValidIdentifierWithCommasInMountPointParameter() {
260  $cacheFrontendMock = $this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array(), '', FALSE);
261  $this->pageContextMock->sys_language_uid = 8;
262  $this->pageContextMock->versioningWorkspaceId = 15;
263  $this->pageContextMock->versioningPreview = TRUE;
264  $this->fixture->__construct(42, '47-11,48-12', $this->pageContextMock);
265  $this->assertTrue($cacheFrontendMock->isValidEntryIdentifier($this->fixture->getCacheIdentifier()));
266  }
267 
272  $pageData = array(
273  'uid' => 1,
274  'title' => 'Original',
275  );
276  $pageDataTranslated = array(
277  'uid' => 1,
278  'title' => 'Translated',
279  '_PAGES_OVERLAY_UID' => '2',
280  );
281 
282  $this->fixture
283  ->expects($this->any())
284  ->method('enrichWithRelationFields')
285  ->with(2, $pageDataTranslated)
286  ->will($this->returnArgument(1));
287 
288  $databaseConnectionMock = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
289  $databaseConnectionMock
290  ->expects($this->once())
291  ->method('exec_SELECTgetSingleRow')
292  ->will(
293  $this->returnValue($pageData)
294  );
295  $this->fixture->_set('databaseConnection',
296  $databaseConnectionMock
297  );
298 
299  $this->pageContextMock
300  ->expects($this->any())
301  ->method('getPageOverlay')
302  ->will($this->returnValue($pageDataTranslated));
303 
304  $this->fixture->_set('languageUid', 1);
305  $this->assertSame($pageDataTranslated, $this->fixture->_call('getRecordArray', 1));
306  }
307 
312  $mockDatabaseConnection = $this->getMock('\TYPO3\CMS\Core\Database\DatabaseConnection', array('exec_SELECTgetRows'), array(), '', FALSE);
313  $subject = $this->getAccessibleMock('\TYPO3\CMS\Core\Utility\RootlineUtility', array('columnHasRelationToResolve'), array(1, '', $this->pageContextMock));
314  $subject->_set('databaseConnection', $mockDatabaseConnection);
315  $GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields'] = '';
316  $foreign_table = $this->getUniqueId('foreign_table');
317  $foreign_field = $this->getUniqueId('foreign_field');
318  $GLOBALS['TCA'][$foreign_table]['ctrl']['enablecolumns']['disabled'] = $this->getUniqueId('disabled');
319  $GLOBALS['TCA']['pages']['columns'] = array(
320  'test' => array(
321  'config' => array(
322  'foreign_table' => $foreign_table,
323  'foreign_field' => $foreign_field
324  )
325  )
326  );
327  $expected = array(
328  $foreign_field . ' = 0',
329  $foreign_table . '.' . $GLOBALS['TCA'][$foreign_table]['ctrl']['enablecolumns']['disabled'] . ' = 0'
330  );
331  $this->pageContextMock->expects($this->once())->method('deleteClause')->will($this->returnValue(''));
332  $mockDatabaseConnection->expects(
333  $this->once())->
334  method('exec_SELECTgetRows')->
335  with('uid', $foreign_table, implode(' AND ', $expected), '', '', '', '')->
336  // the return value does not matter much, it is only here to prevent error messages from further code execution
337  will($this->returnValue(array('uid' => 17))
338  );
339  $subject->expects($this->once())->method('columnHasRelationToResolve')->will($this->returnValue(TRUE));
340  $subject->_call('enrichWithRelationFields', 17, array());
341  }
342 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
if($list_of_literals) if(!empty($literals)) if(!empty($literals)) $result
Analyse literals to prepend the N char to them if their contents aren&#39;t numeric.
assertIsSubset(array $subsetCandidate, array $superset)
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]