TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
AbstractMenuContentObjectTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\ContentObject\Menu;
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 use Doctrine\DBAL\Driver\Statement;
19 
25 {
29  protected $subject = null;
30 
34  protected function setUp()
35  {
36  $proxyClassName = $this->buildAccessibleProxy(\TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject::class);
37  $this->subject = $this->getMockForAbstractClass($proxyClassName);
38  $GLOBALS['TSFE'] = $this->getMockBuilder(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class)
39  ->setConstructorArgs([$GLOBALS['TYPO3_CONF_VARS'], 1, 1])
40  ->getMock();
41  $GLOBALS['TSFE']->cObj = new \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer();
42  $GLOBALS['TSFE']->page = [];
43  }
44 
46  // Tests concerning sectionIndex
48 
53  protected function prepareSectionIndexTest()
54  {
55  $this->subject->sys_page = $this->getMockBuilder(\TYPO3\CMS\Frontend\Page\PageRepository::class)->getMock();
56  $this->subject->parent_cObj = $this->getMockBuilder(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class)->getMock();
57  }
58 
63  {
64  $this->prepareSectionIndexTest();
65  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(null));
66  $result = $this->subject->_call('sectionIndex', 'field');
67  $this->assertEquals($result, []);
68  }
69 
74  {
75  $this->prepareSectionIndexTest();
76  $this->subject->id = 10;
77  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(null))->with(10);
78  $result = $this->subject->_call('sectionIndex', 'field');
79  $this->assertEquals($result, []);
80  }
81 
86  {
87  $this->expectException(\UnexpectedValueException::class);
88  $this->expectExceptionCode(1337334849);
89  $this->prepareSectionIndexTest();
90  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue([]));
91  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')->will($this->returnValue(0));
92  $this->subject->_call('sectionIndex', 'field');
93  }
94 
99  {
100  $statementProphet = $this->prophesize(Statement::class);
101  $statementProphet->fetch()->shouldBeCalledTimes(2)->willReturn(['uid' => 0, 'header' => 'NOT_OVERLAID'], false);
102 
103  $this->prepareSectionIndexTest();
104  $this->subject->mconf['sectionIndex.']['type'] = 'all';
105  $GLOBALS['TSFE']->sys_language_contentOL = 1;
106  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(['_PAGES_OVERLAY_LANGUAGE' => 1]));
107  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')->willReturn($statementProphet->reveal());
108  $this->subject->sys_page->expects($this->once())->method('getRecordOverlay')->will($this->returnValue(['uid' => 0, 'header' => 'OVERLAID']));
109  $result = $this->subject->_call('sectionIndex', 'field');
110  $this->assertEquals($result[0]['title'], 'OVERLAID');
111  }
112 
117  {
118  return [
119  'unfiltered fields' => [
120  1,
121  [
122  'sectionIndex' => 1,
123  'header' => 'foo',
124  'header_layout' => 1
125  ]
126  ],
127  'with unset section index' => [
128  0,
129  [
130  'sectionIndex' => 0,
131  'header' => 'foo',
132  'header_layout' => 1
133  ]
134  ],
135  'with unset header' => [
136  0,
137  [
138  'sectionIndex' => 1,
139  'header' => '',
140  'header_layout' => 1
141  ]
142  ],
143  'with header layout 100' => [
144  0,
145  [
146  'sectionIndex' => 1,
147  'header' => 'foo',
148  'header_layout' => 100
149  ]
150  ]
151  ];
152  }
153 
160  public function sectionIndexFilters($expectedAmount, array $dataRow)
161  {
162  $statementProphet = $this->prophesize(Statement::class);
163  $statementProphet->fetch()->willReturn($dataRow, false);
164 
165  $this->prepareSectionIndexTest();
166  $this->subject->mconf['sectionIndex.']['type'] = 'header';
167  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue([]));
168  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')
169  ->willReturn($statementProphet->reveal());
170  $result = $this->subject->_call('sectionIndex', 'field');
171  $this->assertCount($expectedAmount, $result);
172  }
173 
178  {
179  return [
180  'no configuration' => [
181  [],
182  'colPos=0'
183  ],
184  'with useColPos 2' => [
185  ['useColPos' => 2],
186  'colPos=2'
187  ],
188  'with useColPos -1' => [
189  ['useColPos' => -1],
190  ''
191  ],
192  'with stdWrap useColPos' => [
193  [
194  'useColPos.' => [
195  'wrap' => '2|'
196  ]
197  ],
198  'colPos=2'
199  ]
200  ];
201  }
202 
209  public function sectionIndexQueriesWithDifferentColPos($configuration, $whereClausePrefix)
210  {
211  $statementProphet = $this->prophesize(Statement::class);
212  $statementProphet->fetch()->willReturn([]);
213 
214  $this->prepareSectionIndexTest();
215  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue([]));
216  $this->subject->mconf['sectionIndex.'] = $configuration;
217  $queryConfiguration = [
218  'pidInList' => 12,
219  'orderBy' => 'field',
220  'languageField' => 'sys_language_uid',
221  'where' => $whereClausePrefix
222  ];
223  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')
224  ->with('tt_content', $queryConfiguration)
225  ->willReturn($statementProphet->reveal());
226  $this->subject->_call('sectionIndex', 'field', 12);
227  }
228 
230  // Tests concerning menu item states
232 
236  {
237  return [
238  'none excluded' => [
239  [12, 34, 56],
240  '1, 23, 456',
241  true
242  ],
243  'one excluded' => [
244  [1, 234, 567],
245  '1, 23, 456',
246  true
247  ],
248  'three excluded' => [
249  [1, 23, 456],
250  '1, 23, 456',
251  false
252  ],
253  'empty excludeList' => [
254  [1, 123, 45],
255  '',
256  true
257  ],
258  'empty menu' => [
259  [],
260  '1, 23, 456',
261  false
262  ],
263  ];
264  }
265 
273  public function ifsubHasToCheckExcludeUidList($menuItems, $excludeUidList, $expectedResult)
274  {
275  $menu = [];
276  foreach ($menuItems as $page) {
277  $menu[] = ['uid' => $page];
278  }
279  $runtimeCacheMock = $this->getMockBuilder(VariableFrontend::class)->setMethods(['get', 'set'])->disableOriginalConstructor()->getMock();
280  $runtimeCacheMock->expects($this->once())->method('get')->with($this->anything())->willReturn(false);
281  $runtimeCacheMock->expects($this->once())->method('set')->with($this->anything(), ['result' => $expectedResult]);
282  $this->subject = $this->getMockBuilder(AbstractMenuContentObject::class)->setMethods(['getRuntimeCache'])->getMockForAbstractClass();
283  $this->subject->expects($this->once())->method('getRuntimeCache')->willReturn($runtimeCacheMock);
284  $this->prepareSectionIndexTest();
285  $this->subject->parent_cObj = $this->getMockBuilder(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class)->getMock();
286 
287  $this->subject->sys_page->expects($this->once())->method('getMenu')->will($this->returnValue($menu));
288  $this->subject->menuArr = [
289  0 => ['uid' => 1]
290  ];
291  $this->subject->conf['excludeUidList'] = $excludeUidList;
292 
293  $this->assertEquals($expectedResult, $this->subject->isItemState('IFSUB', 0));
294  }
295 
300  {
301  return [
302  'standard parameter without access protected setting' => [
303  [
304  'parameter' => 1,
305  'linkAccessRestrictedPages' => false,
306  'useCacheHash' => true
307  ],
308  [
309  'showAccessRestrictedPages' => false
310  ],
311  true,
312  ['uid' => 1],
313  '',
314  0,
315  '',
316  '',
317  '',
318  ''
319  ],
320  'standard parameter with access protected setting' => [
321  [
322  'parameter' => 10,
323  'linkAccessRestrictedPages' => true,
324  'useCacheHash' => true
325  ],
326  [
327  'showAccessRestrictedPages' => true
328  ],
329  true,
330  ['uid' => 10],
331  '',
332  0,
333  '',
334  '',
335  '',
336  ''
337  ],
338  'standard parameter with access protected setting "NONE" casts to boolean linkAccessRestrictedPages (delegates resolving to typoLink method internals)' => [
339  [
340  'parameter' => 10,
341  'linkAccessRestrictedPages' => true,
342  'useCacheHash' => true
343  ],
344  [
345  'showAccessRestrictedPages' => 'NONE'
346  ],
347  true,
348  ['uid' => 10],
349  '',
350  0,
351  '',
352  '',
353  '',
354  ''
355  ],
356  'standard parameter with access protected setting (int)67 casts to boolean linkAccessRestrictedPages (delegates resolving to typoLink method internals)' => [
357  [
358  'parameter' => 10,
359  'linkAccessRestrictedPages' => true,
360  'useCacheHash' => true
361  ],
362  [
363  'showAccessRestrictedPages' => 67
364  ],
365  true,
366  ['uid' => 10],
367  '',
368  0,
369  '',
370  '',
371  '',
372  ''
373  ],
374  'standard parameter with target' => [
375  [
376  'parameter' => 1,
377  'target' => '_blank',
378  'linkAccessRestrictedPages' => false,
379  'useCacheHash' => true
380  ],
381  [
382  'showAccessRestrictedPages' => false
383  ],
384  true,
385  ['uid' => 1],
386  '_blank',
387  0,
388  '',
389  '',
390  '',
391  ''
392  ],
393  'parameter with typeOverride=10' => [
394  [
395  'parameter' => '10,10',
396  'linkAccessRestrictedPages' => false,
397  'useCacheHash' => true
398  ],
399  [
400  'showAccessRestrictedPages' => false
401  ],
402  true,
403  ['uid' => 10],
404  '',
405  0,
406  '',
407  '',
408  '',
409  10
410  ],
411  'parameter with target and typeOverride=10' => [
412  [
413  'parameter' => '10,10',
414  'linkAccessRestrictedPages' => false,
415  'useCacheHash' => true,
416  'target' => '_self'
417  ],
418  [
419  'showAccessRestrictedPages' => false
420  ],
421  true,
422  ['uid' => 10],
423  '_self',
424  0,
425  '',
426  '',
427  '',
428  10
429  ],
430  'parameter with invalid value in typeOverride=foobar ignores typeOverride' => [
431  [
432  'parameter' => 20,
433  'linkAccessRestrictedPages' => false,
434  'useCacheHash' => true,
435  'target' => '_self'
436  ],
437  [
438  'showAccessRestrictedPages' => false
439  ],
440  true,
441  ['uid' => 20],
442  '_self',
443  0,
444  '',
445  '',
446  '',
447  'foobar'
448  ],
449  'standard parameter with section name' => [
450  [
451  'parameter' => 10,
452  'target' => '_blank',
453  'linkAccessRestrictedPages' => false,
454  'no_cache' => true,
455  'section' => 'section-name'
456  ],
457  [
458  'showAccessRestrictedPages' => false
459  ],
460  true,
461  [
462  'uid' => 10,
463  'sectionIndex_uid' => 'section-name'
464  ],
465  '_blank',
466  1,
467  '',
468  '',
469  '',
470  ''
471  ],
472  'standard parameter with additional parameters' => [
473  [
474  'parameter' => 10,
475  'linkAccessRestrictedPages' => false,
476  'no_cache' => true,
477  'section' => 'section-name',
478  'additionalParams' => '&test=foobar'
479  ],
480  [
481  'showAccessRestrictedPages' => false
482  ],
483  true,
484  [
485  'uid' => 10,
486  'sectionIndex_uid' => 'section-name'
487  ],
488  '',
489  1,
490  '',
491  '',
492  '&test=foobar',
493  ''
494  ],
495  'overridden page array uid value gets used as parameter' => [
496  [
497  'parameter' => 99,
498  'linkAccessRestrictedPages' => false,
499  'no_cache' => true,
500  'section' => 'section-name'
501  ],
502  [
503  'showAccessRestrictedPages' => false
504  ],
505  true,
506  [
507  'uid' => 10,
508  'sectionIndex_uid' => 'section-name'
509  ],
510  '',
511  1,
512  '',
513  ['uid' => 99],
514  '',
515  ''
516  ],
517  ];
518  }
519 
534  public function menuTypoLinkCreatesExpectedTypoLinkConfiguration(array $expected, array $mconf, $useCacheHash = true, array $page, $oTarget, $no_cache, $script, $overrideArray = '', $addParams = '', $typeOverride = '')
535  {
536  $this->subject->parent_cObj = $this->getMockBuilder(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class)
537  ->setMethods(['typoLink'])
538  ->getMock();
539  $this->subject->mconf = $mconf;
540  $this->subject->_set('useCacheHash', $useCacheHash);
541  $this->subject->parent_cObj->expects($this->once())->method('typoLink')->with('|', $expected);
542  $this->subject->menuTypoLink($page, $oTarget, $no_cache, $script, $overrideArray, $addParams, $typeOverride);
543  }
544 }
menuTypoLinkCreatesExpectedTypoLinkConfiguration(array $expected, array $mconf, $useCacheHash=true, array $page, $oTarget, $no_cache, $script, $overrideArray= '', $addParams= '', $typeOverride= '')
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']