[BUGFIX] Incomplete mock raises PHP 5.4 warning
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Tests / Unit / ContentObject / Menu / AbstractMenuContentObjectTest.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Tests\Unit\ContentObject\Menu;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012-2013 Stefan Galinski <stefan.galinski@gmail.com>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Testcase for TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject
28 *
29 * @author Stefan Galinski <stefan.galinski@gmail.com>
30 */
31 class AbstractMenuContentObjectTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
32
33 /**
34 * A backup of the global database
35 *
36 * @var \TYPO3\CMS\Core\Database\DatabaseConnection
37 */
38 protected $databaseBackup = NULL;
39
40 /**
41 * @var \TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject
42 */
43 protected $fixture = NULL;
44
45 /**
46 * Set up this testcase
47 */
48 public function setUp() {
49 $proxy = $this->buildAccessibleProxy('TYPO3\\CMS\\Frontend\\ContentObject\\Menu\\AbstractMenuContentObject');
50 $this->fixture = new $proxy();
51 $this->databaseBackup = $GLOBALS['TYPO3_DB'];
52 $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
53 $GLOBALS['TSFE'] = $this->getMock('TYPO3\\CMS\\Frontend\\Controller\\TypoScriptFrontendController', array(), array($GLOBALS['TYPO3_CONF_VARS'], 1, 1));
54 $GLOBALS['TSFE']->cObj = new \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer();
55 $GLOBALS['TSFE']->page = array();
56 }
57
58 /**
59 * Tear down this testcase
60 */
61 public function tearDown() {
62 $GLOBALS['TYPO3_DB'] = $this->databaseBackup;
63 }
64
65 ////////////////////////////////
66 // Tests concerning sectionIndex
67 ////////////////////////////////
68 /**
69 * Prepares a test for the method sectionIndex
70 *
71 * @return void
72 */
73 protected function prepareSectionIndexTest() {
74 $this->fixture->sys_page = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
75 $this->fixture->parent_cObj = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
76 }
77
78 /**
79 * @test
80 */
81 public function sectionIndexReturnsEmptyArrayIfTheRequestedPageCouldNotBeFetched() {
82 $this->prepareSectionIndexTest();
83 $this->fixture->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(NULL));
84 $result = $this->fixture->_call('sectionIndex', 'field');
85 $this->assertEquals($result, array());
86 }
87
88 /**
89 * @test
90 */
91 public function sectionIndexUsesTheInternalIdIfNoPageIdWasGiven() {
92 $this->prepareSectionIndexTest();
93 $this->fixture->id = 10;
94 $this->fixture->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(NULL))->with(10);
95 $result = $this->fixture->_call('sectionIndex', 'field');
96 $this->assertEquals($result, array());
97 }
98
99 /**
100 * @test
101 * @expectedException UnexpectedValueException
102 */
103 public function sectionIndexThrowsAnExceptionIfTheInternalQueryFails() {
104 $this->prepareSectionIndexTest();
105 $this->fixture->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(array()));
106 $this->fixture->parent_cObj->expects($this->once())->method('exec_getQuery')->will($this->returnValue(0));
107 $this->fixture->_call('sectionIndex', 'field');
108 }
109
110 /**
111 * @test
112 */
113 public function sectionIndexReturnsOverlaidRowBasedOnTheLanguageOfTheGivenPage() {
114 $this->prepareSectionIndexTest();
115 $this->fixture->mconf['sectionIndex.']['type'] = 'all';
116 $GLOBALS['TSFE']->sys_language_contentOL = 1;
117 $this->fixture->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(array('_PAGES_OVERLAY_LANGUAGE' => 1)));
118 $this->fixture->parent_cObj->expects($this->once())->method('exec_getQuery')->will($this->returnValue(1));
119 $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)));
120 $this->fixture->sys_page->expects($this->once())->method('getRecordOverlay')->will($this->returnValue(array('uid' => 0, 'header' => 'OVERLAID')));
121 $result = $this->fixture->_call('sectionIndex', 'field');
122 $this->assertEquals($result[0]['title'], 'OVERLAID');
123 }
124
125 /**
126 * @return array
127 */
128 public function sectionIndexFiltersDataProvider() {
129 return array(
130 'unfiltered fields' => array(
131 1,
132 array(
133 'sectionIndex' => 1,
134 'header' => 'foo',
135 'header_layout' => 1
136 )
137 ),
138 'with unset section index' => array(
139 0,
140 array(
141 'sectionIndex' => 0,
142 'header' => 'foo',
143 'header_layout' => 1
144 )
145 ),
146 'with unset header' => array(
147 0,
148 array(
149 'sectionIndex' => 1,
150 'header' => '',
151 'header_layout' => 1
152 )
153 ),
154 'with header layout 100' => array(
155 0,
156 array(
157 'sectionIndex' => 1,
158 'header' => 'foo',
159 'header_layout' => 100
160 )
161 )
162 );
163 }
164
165 /**
166 * @test
167 * @dataProvider sectionIndexFiltersDataProvider
168 * @param integer $expectedAmount
169 * @param array $dataRow
170 */
171 public function sectionIndexFilters($expectedAmount, array $dataRow) {
172 $this->prepareSectionIndexTest();
173 $this->fixture->mconf['sectionIndex.']['type'] = 'header';
174 $this->fixture->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(array()));
175 $this->fixture->parent_cObj->expects($this->once())->method('exec_getQuery')->will($this->returnValue(1));
176 $GLOBALS['TYPO3_DB']->expects($this->exactly(2))->method('sql_fetch_assoc')->will($this->onConsecutiveCalls($this->returnValue($dataRow), $this->returnValue(FALSE)));
177 $result = $this->fixture->_call('sectionIndex', 'field');
178 $this->assertCount($expectedAmount, $result);
179 }
180
181 /**
182 * @return array
183 */
184 public function sectionIndexQueriesWithDifferentColPosDataProvider() {
185 return array(
186 'no configuration' => array(
187 array(),
188 'colPos=0'
189 ),
190 'with useColPos 2' => array(
191 array('useColPos' => 2),
192 'colPos=2'
193 ),
194 'with useColPos -1' => array(
195 array('useColPos' => -1),
196 ''
197 ),
198 'with stdWrap useColPos' => array(
199 array(
200 'useColPos.' => array(
201 'wrap' => '2|'
202 )
203 ),
204 'colPos=2'
205 )
206 );
207 }
208
209 /**
210 * @test
211 * @dataProvider sectionIndexQueriesWithDifferentColPosDataProvider
212 * @param array $configuration
213 * @param string $whereClausePrefix
214 */
215 public function sectionIndexQueriesWithDifferentColPos($configuration, $whereClausePrefix) {
216 $this->prepareSectionIndexTest();
217 $this->fixture->sys_page->expects($this->once())->method('getPage')->will($this->returnValue(array()));
218 $this->fixture->mconf['sectionIndex.'] = $configuration;
219 $queryConfiguration = array(
220 'pidInList' => 12,
221 'orderBy' => 'field',
222 'languageField' => 'sys_language_uid',
223 'where' => $whereClausePrefix
224 );
225 $this->fixture->parent_cObj->expects($this->once())->method('exec_getQuery')->with('tt_content', $queryConfiguration)->will($this->returnValue(1));
226 $this->fixture->_call('sectionIndex', 'field', 12);
227 }
228
229 ////////////////////////////////////
230 // Tests concerning menu item states
231 ////////////////////////////////////
232 /**
233 * @return array
234 */
235 public function ifsubHasToCheckExcludeUidListDataProvider() {
236 return array(
237 'none excluded' => array (
238 array(12, 34, 56),
239 '1, 23, 456',
240 TRUE
241 ),
242 'one excluded' => array (
243 array(1, 234, 567),
244 '1, 23, 456',
245 TRUE
246 ),
247 'three excluded' => array (
248 array(1, 23, 456),
249 '1, 23, 456',
250 FALSE
251 ),
252 'empty excludeList' => array (
253 array(1, 123, 45),
254 '',
255 TRUE
256 ),
257 'empty menu' => array (
258 array(),
259 '1, 23, 456',
260 FALSE
261 ),
262 );
263
264 }
265
266 /**
267 * @test
268 * @dataProvider ifsubHasToCheckExcludeUidListDataProvider
269 * @param array $menuItems
270 * @param string $excludeUidList
271 * @param boolean $expectedResult
272 */
273 public function ifsubHasToCheckExcludeUidList($menuItems, $excludeUidList, $expectedResult) {
274 $menu = array();
275 foreach ($menuItems as $page) {
276 $menu[] = array('uid' => $page);
277 }
278
279 $this->prepareSectionIndexTest();
280 $this->fixture->parent_cObj = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer', array());
281
282 $this->fixture->sys_page->expects($this->once())->method('getMenu')->will($this->returnValue($menu));
283 $this->fixture->menuArr = array(
284 0 => array('uid' => 1)
285 );
286 $this->fixture->conf['excludeUidList'] = $excludeUidList;
287
288 $this->assertEquals($expectedResult, $this->fixture->isItemState('IFSUB', 0));
289 }
290 }
291
292
293 ?>