TYPO3 CMS  TYPO3_8-7
AbstractMenuContentObjectTest.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  */
25 
29 class AbstractMenuContentObjectTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
30 {
34  protected $singletonInstances = [];
35 
39  protected $subject = null;
40 
44  protected function setUp()
45  {
46  $proxyClassName = $this->buildAccessibleProxy(AbstractMenuContentObject::class);
47  $this->subject = $this->getMockForAbstractClass($proxyClassName);
48  $GLOBALS['TSFE'] = $this->getMockBuilder(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class)
49  ->setConstructorArgs([$GLOBALS['TYPO3_CONF_VARS'], 1, 1])
50  ->getMock();
51  $GLOBALS['TSFE']->cObj = new ContentObjectRenderer();
52  $GLOBALS['TSFE']->page = [];
53  $this->singletonInstances = GeneralUtility::getSingletonInstances();
54  }
55 
59  protected function tearDown()
60  {
62  GeneralUtility::resetSingletonInstances($this->singletonInstances);
63  parent::tearDown();
64  }
65 
67  // Tests concerning sectionIndex
69 
72  protected function prepareSectionIndexTest()
73  {
74  $connectionProphet = $this->prophesize(Connection::class);
75  $connectionProphet->getExpressionBuilder()->willReturn(new ExpressionBuilder($connectionProphet->reveal()));
76  $connectionProphet->quoteIdentifier(Argument::cetera())->willReturnArgument(0);
77 
78  $connectionPoolProphet = $this->prophesize(ConnectionPool::class);
79  $connectionPoolProphet->getConnectionForTable('tt_content')->willReturn($connectionProphet->reveal());
80  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphet->reveal());
81 
82  $this->subject->sys_page = $this->getMockBuilder(\TYPO3\CMS\Frontend\Page\PageRepository::class)->getMock();
83  $this->subject->parent_cObj = $this->getMockBuilder(ContentObjectRenderer::class)->getMock();
84  }
85 
90  {
91  $this->prepareSectionIndexTest();
92  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(null));
93  $result = $this->subject->_call('sectionIndex', 'field');
94  $this->assertEquals($result, []);
95  }
96 
101  {
102  $this->prepareSectionIndexTest();
103  $this->subject->id = 10;
104  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(null))->with(10);
105  $result = $this->subject->_call('sectionIndex', 'field');
106  $this->assertEquals($result, []);
107  }
108 
113  {
114  $this->expectException(\UnexpectedValueException::class);
115  $this->expectExceptionCode(1337334849);
116  $this->prepareSectionIndexTest();
117  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue([]));
118  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')->will($this->returnValue(0));
119  $this->subject->_call('sectionIndex', 'field');
120  }
121 
126  {
127  $statementProphet = $this->prophesize(Statement::class);
128  $statementProphet->fetch()->shouldBeCalledTimes(2)->willReturn(['uid' => 0, 'header' => 'NOT_OVERLAID'], false);
129 
130  $this->prepareSectionIndexTest();
131  $this->subject->mconf['sectionIndex.']['type'] = 'all';
132  $GLOBALS['TSFE']->sys_language_contentOL = 1;
133  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(['_PAGES_OVERLAY_LANGUAGE' => 1]));
134  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')->willReturn($statementProphet->reveal());
135  $this->subject->sys_page->expects($this->once())->method('getRecordOverlay')->will($this->returnValue(['uid' => 0, 'header' => 'OVERLAID']));
136  $result = $this->subject->_call('sectionIndex', 'field');
137  $this->assertEquals($result[0]['title'], 'OVERLAID');
138  }
139 
144  {
145  return [
146  'unfiltered fields' => [
147  1,
148  [
149  'sectionIndex' => 1,
150  'header' => 'foo',
151  'header_layout' => 1
152  ]
153  ],
154  'with unset section index' => [
155  0,
156  [
157  'sectionIndex' => 0,
158  'header' => 'foo',
159  'header_layout' => 1
160  ]
161  ],
162  'with unset header' => [
163  0,
164  [
165  'sectionIndex' => 1,
166  'header' => '',
167  'header_layout' => 1
168  ]
169  ],
170  'with header layout 100' => [
171  0,
172  [
173  'sectionIndex' => 1,
174  'header' => 'foo',
175  'header_layout' => 100
176  ]
177  ]
178  ];
179  }
180 
187  public function sectionIndexFilters($expectedAmount, array $dataRow)
188  {
189  $statementProphet = $this->prophesize(Statement::class);
190  $statementProphet->fetch()->willReturn($dataRow, false);
191 
192  $this->prepareSectionIndexTest();
193  $this->subject->mconf['sectionIndex.']['type'] = 'header';
194  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue([]));
195  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')
196  ->willReturn($statementProphet->reveal());
197  $result = $this->subject->_call('sectionIndex', 'field');
198  $this->assertCount($expectedAmount, $result);
199  }
200 
205  {
206  return [
207  'no configuration' => [
208  [],
209  'colPos = 0'
210  ],
211  'with useColPos 2' => [
212  ['useColPos' => 2],
213  'colPos = 2'
214  ],
215  'with useColPos -1' => [
216  ['useColPos' => -1],
217  ''
218  ],
219  'with stdWrap useColPos' => [
220  [
221  'useColPos.' => [
222  'wrap' => '2|'
223  ]
224  ],
225  'colPos = 2'
226  ]
227  ];
228  }
229 
236  public function sectionIndexQueriesWithDifferentColPos($configuration, $whereClausePrefix)
237  {
238  $statementProphet = $this->prophesize(Statement::class);
239  $statementProphet->fetch()->willReturn([]);
240 
241  $this->prepareSectionIndexTest();
242  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue([]));
243  $this->subject->mconf['sectionIndex.'] = $configuration;
244  $queryConfiguration = [
245  'pidInList' => 12,
246  'orderBy' => 'field',
247  'languageField' => 'sys_language_uid',
248  'where' => $whereClausePrefix
249  ];
250  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')
251  ->with('tt_content', $queryConfiguration)
252  ->willReturn($statementProphet->reveal());
253  $this->subject->_call('sectionIndex', 'field', 12);
254  }
255 
257  // Tests concerning menu item states
259 
263  {
264  return [
265  'none excluded' => [
266  [12, 34, 56],
267  '1, 23, 456',
268  true
269  ],
270  'one excluded' => [
271  [1, 234, 567],
272  '1, 23, 456',
273  true
274  ],
275  'three excluded' => [
276  [1, 23, 456],
277  '1, 23, 456',
278  false
279  ],
280  'empty excludeList' => [
281  [1, 123, 45],
282  '',
283  true
284  ],
285  'empty menu' => [
286  [],
287  '1, 23, 456',
288  false
289  ],
290  ];
291  }
292 
300  public function ifsubHasToCheckExcludeUidList($menuItems, $excludeUidList, $expectedResult)
301  {
302  $menu = [];
303  foreach ($menuItems as $page) {
304  $menu[] = ['uid' => $page];
305  }
306  $runtimeCacheMock = $this->getMockBuilder(VariableFrontend::class)->setMethods(['get', 'set'])->disableOriginalConstructor()->getMock();
307  $runtimeCacheMock->expects($this->once())->method('get')->with($this->anything())->willReturn(false);
308  $runtimeCacheMock->expects($this->once())->method('set')->with($this->anything(), ['result' => $expectedResult]);
309  $this->subject = $this->getMockBuilder(AbstractMenuContentObject::class)->setMethods(['getRuntimeCache'])->getMockForAbstractClass();
310  $this->subject->expects($this->once())->method('getRuntimeCache')->willReturn($runtimeCacheMock);
311  $this->prepareSectionIndexTest();
312  $this->subject->parent_cObj = $this->getMockBuilder(ContentObjectRenderer::class)->getMock();
313 
314  $this->subject->sys_page->expects($this->once())->method('getMenu')->will($this->returnValue($menu));
315  $this->subject->menuArr = [
316  0 => ['uid' => 1]
317  ];
318  $this->subject->conf['excludeUidList'] = $excludeUidList;
319 
320  $this->assertEquals($expectedResult, $this->subject->isItemState('IFSUB', 0));
321  }
322 
327  {
328  return [
329  'standard parameter without access protected setting' => [
330  [
331  'parameter' => 1,
332  'linkAccessRestrictedPages' => false,
333  'useCacheHash' => true
334  ],
335  [
336  'showAccessRestrictedPages' => false
337  ],
338  true,
339  ['uid' => 1],
340  '',
341  0,
342  '',
343  '',
344  '',
345  ''
346  ],
347  'standard parameter with access protected setting' => [
348  [
349  'parameter' => 10,
350  'linkAccessRestrictedPages' => true,
351  'useCacheHash' => true
352  ],
353  [
354  'showAccessRestrictedPages' => true
355  ],
356  true,
357  ['uid' => 10],
358  '',
359  0,
360  '',
361  '',
362  '',
363  ''
364  ],
365  'standard parameter with access protected setting "NONE" casts to boolean linkAccessRestrictedPages (delegates resolving to typoLink method internals)' => [
366  [
367  'parameter' => 10,
368  'linkAccessRestrictedPages' => true,
369  'useCacheHash' => true
370  ],
371  [
372  'showAccessRestrictedPages' => 'NONE'
373  ],
374  true,
375  ['uid' => 10],
376  '',
377  0,
378  '',
379  '',
380  '',
381  ''
382  ],
383  'standard parameter with access protected setting (int)67 casts to boolean linkAccessRestrictedPages (delegates resolving to typoLink method internals)' => [
384  [
385  'parameter' => 10,
386  'linkAccessRestrictedPages' => true,
387  'useCacheHash' => true
388  ],
389  [
390  'showAccessRestrictedPages' => 67
391  ],
392  true,
393  ['uid' => 10],
394  '',
395  0,
396  '',
397  '',
398  '',
399  ''
400  ],
401  'standard parameter with target' => [
402  [
403  'parameter' => 1,
404  'target' => '_blank',
405  'linkAccessRestrictedPages' => false,
406  'useCacheHash' => true
407  ],
408  [
409  'showAccessRestrictedPages' => false
410  ],
411  true,
412  ['uid' => 1],
413  '_blank',
414  0,
415  '',
416  '',
417  '',
418  ''
419  ],
420  'parameter with typeOverride=10' => [
421  [
422  'parameter' => '10,10',
423  'linkAccessRestrictedPages' => false,
424  'useCacheHash' => true
425  ],
426  [
427  'showAccessRestrictedPages' => false
428  ],
429  true,
430  ['uid' => 10],
431  '',
432  0,
433  '',
434  '',
435  '',
436  10
437  ],
438  'parameter with target and typeOverride=10' => [
439  [
440  'parameter' => '10,10',
441  'linkAccessRestrictedPages' => false,
442  'useCacheHash' => true,
443  'target' => '_self'
444  ],
445  [
446  'showAccessRestrictedPages' => false
447  ],
448  true,
449  ['uid' => 10],
450  '_self',
451  0,
452  '',
453  '',
454  '',
455  10
456  ],
457  'parameter with invalid value in typeOverride=foobar ignores typeOverride' => [
458  [
459  'parameter' => 20,
460  'linkAccessRestrictedPages' => false,
461  'useCacheHash' => true,
462  'target' => '_self'
463  ],
464  [
465  'showAccessRestrictedPages' => false
466  ],
467  true,
468  ['uid' => 20],
469  '_self',
470  0,
471  '',
472  '',
473  '',
474  'foobar'
475  ],
476  'standard parameter with section name' => [
477  [
478  'parameter' => 10,
479  'target' => '_blank',
480  'linkAccessRestrictedPages' => false,
481  'no_cache' => true,
482  'section' => 'section-name'
483  ],
484  [
485  'showAccessRestrictedPages' => false
486  ],
487  true,
488  [
489  'uid' => 10,
490  'sectionIndex_uid' => 'section-name'
491  ],
492  '_blank',
493  1,
494  '',
495  '',
496  '',
497  ''
498  ],
499  'standard parameter with additional parameters' => [
500  [
501  'parameter' => 10,
502  'linkAccessRestrictedPages' => false,
503  'no_cache' => true,
504  'section' => 'section-name',
505  'additionalParams' => '&test=foobar'
506  ],
507  [
508  'showAccessRestrictedPages' => false
509  ],
510  true,
511  [
512  'uid' => 10,
513  'sectionIndex_uid' => 'section-name'
514  ],
515  '',
516  1,
517  '',
518  '',
519  '&test=foobar',
520  ''
521  ],
522  'overridden page array uid value gets used as parameter' => [
523  [
524  'parameter' => 99,
525  'linkAccessRestrictedPages' => false,
526  'no_cache' => true,
527  'section' => 'section-name'
528  ],
529  [
530  'showAccessRestrictedPages' => false
531  ],
532  true,
533  [
534  'uid' => 10,
535  'sectionIndex_uid' => 'section-name'
536  ],
537  '',
538  1,
539  '',
540  ['uid' => 99],
541  '',
542  ''
543  ],
544  ];
545  }
546 
561  public function menuTypoLinkCreatesExpectedTypoLinkConfiguration(array $expected, array $mconf, $useCacheHash = true, array $page, $oTarget, $no_cache, $script, $overrideArray = '', $addParams = '', $typeOverride = '')
562  {
563  $this->subject->parent_cObj = $this->getMockBuilder(ContentObjectRenderer::class)
564  ->setMethods(['typoLink'])
565  ->getMock();
566  $this->subject->mconf = $mconf;
567  $this->subject->_set('useCacheHash', $useCacheHash);
568  $this->subject->parent_cObj->expects($this->once())->method('typoLink')->with('|', $expected);
569  $this->subject->menuTypoLink($page, $oTarget, $no_cache, $script, $overrideArray, $addParams, $typeOverride);
570  }
571 }
menuTypoLinkCreatesExpectedTypoLinkConfiguration(array $expected, array $mconf, $useCacheHash=true, array $page, $oTarget, $no_cache, $script, $overrideArray='', $addParams='', $typeOverride='')
static addInstance($className, $instance)
static resetSingletonInstances(array $newSingletonInstances)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']