TYPO3 CMS  TYPO3_7-6
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  */
18 
24 {
28  protected $subject = null;
29 
33  protected function setUp()
34  {
35  $proxyClassName = $this->buildAccessibleProxy(\TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject::class);
36  $this->subject = $this->getMockForAbstractClass($proxyClassName);
37  $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class);
38  $GLOBALS['TSFE'] = $this->getMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class, [], [$GLOBALS['TYPO3_CONF_VARS'], 1, 1]);
39  $GLOBALS['TSFE']->cObj = new \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer();
40  $GLOBALS['TSFE']->page = [];
41  }
42 
44  // Tests concerning sectionIndex
46 
51  protected function prepareSectionIndexTest()
52  {
53  $this->subject->sys_page = $this->getMock(\TYPO3\CMS\Frontend\Page\PageRepository::class);
54  $this->subject->parent_cObj = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
55  }
56 
61  {
62  $this->prepareSectionIndexTest();
63  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(null));
64  $result = $this->subject->_call('sectionIndex', 'field');
65  $this->assertEquals($result, []);
66  }
67 
72  {
73  $this->prepareSectionIndexTest();
74  $this->subject->id = 10;
75  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(null))->with(10);
76  $result = $this->subject->_call('sectionIndex', 'field');
77  $this->assertEquals($result, []);
78  }
79 
85  {
86  $this->prepareSectionIndexTest();
87  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue([]));
88  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')->will($this->returnValue(0));
89  $this->subject->_call('sectionIndex', 'field');
90  }
91 
96  {
97  $this->prepareSectionIndexTest();
98  $this->subject->mconf['sectionIndex.']['type'] = 'all';
99  $GLOBALS['TSFE']->sys_language_contentOL = 1;
100  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(['_PAGES_OVERLAY_LANGUAGE' => 1]));
101  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')->will($this->returnValue(1));
102  $GLOBALS['TYPO3_DB']->expects($this->exactly(2))->method('sql_fetch_assoc')->will($this->onConsecutiveCalls($this->returnValue(['uid' => 0, 'header' => 'NOT_OVERLAID']), $this->returnValue(false)));
103  $this->subject->sys_page->expects($this->once())->method('getRecordOverlay')->will($this->returnValue(['uid' => 0, 'header' => 'OVERLAID']));
104  $result = $this->subject->_call('sectionIndex', 'field');
105  $this->assertEquals($result[0]['title'], 'OVERLAID');
106  }
107 
112  {
113  return [
114  'unfiltered fields' => [
115  1,
116  [
117  'sectionIndex' => 1,
118  'header' => 'foo',
119  'header_layout' => 1
120  ]
121  ],
122  'with unset section index' => [
123  0,
124  [
125  'sectionIndex' => 0,
126  'header' => 'foo',
127  'header_layout' => 1
128  ]
129  ],
130  'with unset header' => [
131  0,
132  [
133  'sectionIndex' => 1,
134  'header' => '',
135  'header_layout' => 1
136  ]
137  ],
138  'with header layout 100' => [
139  0,
140  [
141  'sectionIndex' => 1,
142  'header' => 'foo',
143  'header_layout' => 100
144  ]
145  ]
146  ];
147  }
148 
155  public function sectionIndexFilters($expectedAmount, array $dataRow)
156  {
157  $this->prepareSectionIndexTest();
158  $this->subject->mconf['sectionIndex.']['type'] = 'header';
159  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue([]));
160  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')->will($this->returnValue(1));
161  $GLOBALS['TYPO3_DB']->expects($this->exactly(2))->method('sql_fetch_assoc')->will($this->onConsecutiveCalls($this->returnValue($dataRow), $this->returnValue(false)));
162  $result = $this->subject->_call('sectionIndex', 'field');
163  $this->assertCount($expectedAmount, $result);
164  }
165 
170  {
171  return [
172  'no configuration' => [
173  [],
174  'colPos=0'
175  ],
176  'with useColPos 2' => [
177  ['useColPos' => 2],
178  'colPos=2'
179  ],
180  'with useColPos -1' => [
181  ['useColPos' => -1],
182  ''
183  ],
184  'with stdWrap useColPos' => [
185  [
186  'useColPos.' => [
187  'wrap' => '2|'
188  ]
189  ],
190  'colPos=2'
191  ]
192  ];
193  }
194 
201  public function sectionIndexQueriesWithDifferentColPos($configuration, $whereClausePrefix)
202  {
203  $this->prepareSectionIndexTest();
204  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue([]));
205  $this->subject->mconf['sectionIndex.'] = $configuration;
206  $queryConfiguration = [
207  'pidInList' => 12,
208  'orderBy' => 'field',
209  'languageField' => 'sys_language_uid',
210  'where' => $whereClausePrefix
211  ];
212  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')->with('tt_content', $queryConfiguration)->will($this->returnValue(1));
213  $this->subject->_call('sectionIndex', 'field', 12);
214  }
215 
217  // Tests concerning menu item states
219 
223  {
224  return [
225  'none excluded' => [
226  [12, 34, 56],
227  '1, 23, 456',
228  true
229  ],
230  'one excluded' => [
231  [1, 234, 567],
232  '1, 23, 456',
233  true
234  ],
235  'three excluded' => [
236  [1, 23, 456],
237  '1, 23, 456',
238  false
239  ],
240  'empty excludeList' => [
241  [1, 123, 45],
242  '',
243  true
244  ],
245  'empty menu' => [
246  [],
247  '1, 23, 456',
248  false
249  ],
250  ];
251  }
252 
260  public function ifsubHasToCheckExcludeUidList($menuItems, $excludeUidList, $expectedResult)
261  {
262  $menu = [];
263  foreach ($menuItems as $page) {
264  $menu[] = ['uid' => $page];
265  }
266  $runtimeCacheMock = $this->getMockBuilder(VariableFrontend::class)->setMethods(['get', 'set'])->disableOriginalConstructor()->getMock();
267  $runtimeCacheMock->expects($this->once())->method('get')->with($this->anything())->willReturn(false);
268  $runtimeCacheMock->expects($this->once())->method('set')->with($this->anything(), ['result' => $expectedResult]);
269  $this->subject = $this->getMockBuilder(AbstractMenuContentObject::class)->setMethods(['getRuntimeCache'])->getMockForAbstractClass();
270  $this->subject->expects($this->once())->method('getRuntimeCache')->willReturn($runtimeCacheMock);
271  $this->prepareSectionIndexTest();
272  $this->subject->parent_cObj = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, []);
273 
274  $this->subject->sys_page->expects($this->once())->method('getMenu')->will($this->returnValue($menu));
275  $this->subject->menuArr = [
276  0 => ['uid' => 1]
277  ];
278  $this->subject->conf['excludeUidList'] = $excludeUidList;
279 
280  $this->assertEquals($expectedResult, $this->subject->isItemState('IFSUB', 0));
281  }
282 
287  {
288  return [
289  'standard parameter without access protected setting' => [
290  [
291  'parameter' => 1,
292  'linkAccessRestrictedPages' => false,
293  'useCacheHash' => true
294  ],
295  [
296  'showAccessRestrictedPages' => false
297  ],
298  true,
299  ['uid' => 1],
300  '',
301  0,
302  '',
303  '',
304  '',
305  ''
306  ],
307  'standard parameter with access protected setting' => [
308  [
309  'parameter' => 10,
310  'linkAccessRestrictedPages' => true,
311  'useCacheHash' => true
312  ],
313  [
314  'showAccessRestrictedPages' => true
315  ],
316  true,
317  ['uid' => 10],
318  '',
319  0,
320  '',
321  '',
322  '',
323  ''
324  ],
325  'standard parameter with access protected setting "NONE" casts to boolean linkAccessRestrictedPages (delegates resolving to typoLink method internals)' => [
326  [
327  'parameter' => 10,
328  'linkAccessRestrictedPages' => true,
329  'useCacheHash' => true
330  ],
331  [
332  'showAccessRestrictedPages' => 'NONE'
333  ],
334  true,
335  ['uid' => 10],
336  '',
337  0,
338  '',
339  '',
340  '',
341  ''
342  ],
343  'standard parameter with access protected setting (int)67 casts to boolean linkAccessRestrictedPages (delegates resolving to typoLink method internals)' => [
344  [
345  'parameter' => 10,
346  'linkAccessRestrictedPages' => true,
347  'useCacheHash' => true
348  ],
349  [
350  'showAccessRestrictedPages' => 67
351  ],
352  true,
353  ['uid' => 10],
354  '',
355  0,
356  '',
357  '',
358  '',
359  ''
360  ],
361  'standard parameter with target' => [
362  [
363  'parameter' => 1,
364  'target' => '_blank',
365  'linkAccessRestrictedPages' => false,
366  'useCacheHash' => true
367  ],
368  [
369  'showAccessRestrictedPages' => false
370  ],
371  true,
372  ['uid' => 1],
373  '_blank',
374  0,
375  '',
376  '',
377  '',
378  ''
379  ],
380  'parameter with typeOverride=10' => [
381  [
382  'parameter' => '10,10',
383  'linkAccessRestrictedPages' => false,
384  'useCacheHash' => true
385  ],
386  [
387  'showAccessRestrictedPages' => false
388  ],
389  true,
390  ['uid' => 10],
391  '',
392  0,
393  '',
394  '',
395  '',
396  10
397  ],
398  'parameter with target and typeOverride=10' => [
399  [
400  'parameter' => '10,10',
401  'linkAccessRestrictedPages' => false,
402  'useCacheHash' => true,
403  'target' => '_self'
404  ],
405  [
406  'showAccessRestrictedPages' => false
407  ],
408  true,
409  ['uid' => 10],
410  '_self',
411  0,
412  '',
413  '',
414  '',
415  10
416  ],
417  'parameter with invalid value in typeOverride=foobar ignores typeOverride' => [
418  [
419  'parameter' => 20,
420  'linkAccessRestrictedPages' => false,
421  'useCacheHash' => true,
422  'target' => '_self'
423  ],
424  [
425  'showAccessRestrictedPages' => false
426  ],
427  true,
428  ['uid' => 20],
429  '_self',
430  0,
431  '',
432  '',
433  '',
434  'foobar'
435  ],
436  'standard parameter with section name' => [
437  [
438  'parameter' => 10,
439  'target' => '_blank',
440  'linkAccessRestrictedPages' => false,
441  'no_cache' => true,
442  'section' => 'section-name'
443  ],
444  [
445  'showAccessRestrictedPages' => false
446  ],
447  true,
448  [
449  'uid' => 10,
450  'sectionIndex_uid' => 'section-name'
451  ],
452  '_blank',
453  1,
454  '',
455  '',
456  '',
457  ''
458  ],
459  'standard parameter with additional parameters' => [
460  [
461  'parameter' => 10,
462  'linkAccessRestrictedPages' => false,
463  'no_cache' => true,
464  'section' => 'section-name',
465  'additionalParams' => '&test=foobar'
466  ],
467  [
468  'showAccessRestrictedPages' => false
469  ],
470  true,
471  [
472  'uid' => 10,
473  'sectionIndex_uid' => 'section-name'
474  ],
475  '',
476  1,
477  '',
478  '',
479  '&test=foobar',
480  ''
481  ],
482  'overridden page array uid value gets used as parameter' => [
483  [
484  'parameter' => 99,
485  'linkAccessRestrictedPages' => false,
486  'no_cache' => true,
487  'section' => 'section-name'
488  ],
489  [
490  'showAccessRestrictedPages' => false
491  ],
492  true,
493  [
494  'uid' => 10,
495  'sectionIndex_uid' => 'section-name'
496  ],
497  '',
498  1,
499  '',
500  ['uid' => 99],
501  '',
502  ''
503  ],
504  ];
505  }
506 
521  public function menuTypoLinkCreatesExpectedTypoLinkConfiguration(array $expected, array $mconf, $useCacheHash = true, array $page, $oTarget, $no_cache, $script, $overrideArray = '', $addParams = '', $typeOverride = '')
522  {
523  $this->subject->parent_cObj = $this->getMockBuilder(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class)
524  ->setMethods(['typoLink'])
525  ->getMock();
526  $this->subject->mconf = $mconf;
527  $this->subject->_set('useCacheHash', $useCacheHash);
528  $this->subject->parent_cObj->expects($this->once())->method('typoLink')->with('|', $expected);
529  $this->subject->menuTypoLink($page, $oTarget, $no_cache, $script, $overrideArray, $addParams, $typeOverride);
530  }
531 }
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']