TYPO3  7.6
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 
21 class AbstractMenuContentObjectTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
22 {
26  protected $subject = null;
27 
31  protected function setUp()
32  {
33  $proxyClassName = $this->buildAccessibleProxy(\TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject::class);
34  $this->subject = $this->getMockForAbstractClass($proxyClassName);
35  $GLOBALS['TYPO3_DB'] = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class);
36  $GLOBALS['TSFE'] = $this->getMock(\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class, array(), array($GLOBALS['TYPO3_CONF_VARS'], 1, 1));
37  $GLOBALS['TSFE']->cObj = new \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer();
38  $GLOBALS['TSFE']->page = array();
39  }
40 
42  // Tests concerning sectionIndex
44 
49  protected function prepareSectionIndexTest()
50  {
51  $this->subject->sys_page = $this->getMock(\TYPO3\CMS\Frontend\Page\PageRepository::class);
52  $this->subject->parent_cObj = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
53  }
54 
59  {
60  $this->prepareSectionIndexTest();
61  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(null));
62  $result = $this->subject->_call('sectionIndex', 'field');
63  $this->assertEquals($result, array());
64  }
65 
70  {
71  $this->prepareSectionIndexTest();
72  $this->subject->id = 10;
73  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(null))->with(10);
74  $result = $this->subject->_call('sectionIndex', 'field');
75  $this->assertEquals($result, array());
76  }
77 
83  {
84  $this->prepareSectionIndexTest();
85  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(array()));
86  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')->will($this->returnValue(0));
87  $this->subject->_call('sectionIndex', 'field');
88  }
89 
94  {
95  $this->prepareSectionIndexTest();
96  $this->subject->mconf['sectionIndex.']['type'] = 'all';
97  $GLOBALS['TSFE']->sys_language_contentOL = 1;
98  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(array('_PAGES_OVERLAY_LANGUAGE' => 1)));
99  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')->will($this->returnValue(1));
100  $GLOBALS['TYPO3_DB']->expects($this->exactly(2))->method('sql_fetch_assoc')->will($this->onConsecutiveCalls($this->returnValue(array('uid' => 0, 'header' => 'NOT_OVERLAID')), $this->returnValue(false)));
101  $this->subject->sys_page->expects($this->once())->method('getRecordOverlay')->will($this->returnValue(array('uid' => 0, 'header' => 'OVERLAID')));
102  $result = $this->subject->_call('sectionIndex', 'field');
103  $this->assertEquals($result[0]['title'], 'OVERLAID');
104  }
105 
110  {
111  return array(
112  'unfiltered fields' => array(
113  1,
114  array(
115  'sectionIndex' => 1,
116  'header' => 'foo',
117  'header_layout' => 1
118  )
119  ),
120  'with unset section index' => array(
121  0,
122  array(
123  'sectionIndex' => 0,
124  'header' => 'foo',
125  'header_layout' => 1
126  )
127  ),
128  'with unset header' => array(
129  0,
130  array(
131  'sectionIndex' => 1,
132  'header' => '',
133  'header_layout' => 1
134  )
135  ),
136  'with header layout 100' => array(
137  0,
138  array(
139  'sectionIndex' => 1,
140  'header' => 'foo',
141  'header_layout' => 100
142  )
143  )
144  );
145  }
146 
153  public function sectionIndexFilters($expectedAmount, array $dataRow)
154  {
155  $this->prepareSectionIndexTest();
156  $this->subject->mconf['sectionIndex.']['type'] = 'header';
157  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(array()));
158  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')->will($this->returnValue(1));
159  $GLOBALS['TYPO3_DB']->expects($this->exactly(2))->method('sql_fetch_assoc')->will($this->onConsecutiveCalls($this->returnValue($dataRow), $this->returnValue(false)));
160  $result = $this->subject->_call('sectionIndex', 'field');
161  $this->assertCount($expectedAmount, $result);
162  }
163 
168  {
169  return array(
170  'no configuration' => array(
171  array(),
172  'colPos=0'
173  ),
174  'with useColPos 2' => array(
175  array('useColPos' => 2),
176  'colPos=2'
177  ),
178  'with useColPos -1' => array(
179  array('useColPos' => -1),
180  ''
181  ),
182  'with stdWrap useColPos' => array(
183  array(
184  'useColPos.' => array(
185  'wrap' => '2|'
186  )
187  ),
188  'colPos=2'
189  )
190  );
191  }
192 
199  public function sectionIndexQueriesWithDifferentColPos($configuration, $whereClausePrefix)
200  {
201  $this->prepareSectionIndexTest();
202  $this->subject->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(array()));
203  $this->subject->mconf['sectionIndex.'] = $configuration;
204  $queryConfiguration = array(
205  'pidInList' => 12,
206  'orderBy' => 'field',
207  'languageField' => 'sys_language_uid',
208  'where' => $whereClausePrefix
209  );
210  $this->subject->parent_cObj->expects($this->once())->method('exec_getQuery')->with('tt_content', $queryConfiguration)->will($this->returnValue(1));
211  $this->subject->_call('sectionIndex', 'field', 12);
212  }
213 
215  // Tests concerning menu item states
217 
221  {
222  return array(
223  'none excluded' => array(
224  array(12, 34, 56),
225  '1, 23, 456',
226  true
227  ),
228  'one excluded' => array(
229  array(1, 234, 567),
230  '1, 23, 456',
231  true
232  ),
233  'three excluded' => array(
234  array(1, 23, 456),
235  '1, 23, 456',
236  false
237  ),
238  'empty excludeList' => array(
239  array(1, 123, 45),
240  '',
241  true
242  ),
243  'empty menu' => array(
244  array(),
245  '1, 23, 456',
246  false
247  ),
248  );
249  }
250 
258  public function ifsubHasToCheckExcludeUidList($menuItems, $excludeUidList, $expectedResult)
259  {
260  $menu = array();
261  foreach ($menuItems as $page) {
262  $menu[] = array('uid' => $page);
263  }
264 
265  $this->prepareSectionIndexTest();
266  $this->subject->parent_cObj = $this->getMock(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class, array());
267 
268  $this->subject->sys_page->expects($this->once())->method('getMenu')->will($this->returnValue($menu));
269  $this->subject->menuArr = array(
270  0 => array('uid' => 1)
271  );
272  $this->subject->conf['excludeUidList'] = $excludeUidList;
273 
274  $this->assertEquals($expectedResult, $this->subject->isItemState('IFSUB', 0));
275  }
276 }