2 namespace TYPO3\CMS\Frontend\Tests\Unit\ContentObject\Menu
;
4 /***************************************************************
7 * (c) 2012-2013 Stefan Galinski <stefan.galinski@gmail.com>
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.
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
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.
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
27 * Testcase for TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject
29 * @author Stefan Galinski <stefan.galinski@gmail.com>
31 class AbstractMenuContentObjectTest
extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase
{
34 * A backup of the global database
36 * @var \TYPO3\CMS\Core\Database\DatabaseConnection
38 protected $databaseBackup = NULL;
41 * @var \TYPO3\CMS\Frontend\ContentObject\Menu\AbstractMenuContentObject
43 protected $fixture = NULL;
46 * Set up this testcase
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();
58 * Tear down this testcase
60 public function tearDown() {
61 $GLOBALS['TYPO3_DB'] = $this->databaseBackup
;
64 ////////////////////////////////
65 // Tests concerning sectionIndex
66 ////////////////////////////////
68 * Prepares a test for the method sectionIndex
72 protected function prepareSectionIndexTest() {
73 $this->fixture
->sys_page
= $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
74 $this->fixture
->parent_cObj
= $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
80 public function sectionIndexReturnsEmptyArrayIfTheRequestedPageCouldNotBeFetched() {
81 $this->prepareSectionIndexTest();
82 $this->fixture
->sys_page
->expects($this->once())->method('getPage')->will($this->returnValue(NULL));
83 $result = $this->fixture
->_call('sectionIndex', 'field');
84 $this->assertEquals($result, array());
90 public function sectionIndexUsesTheInternalIdIfNoPageIdWasGiven() {
91 $this->prepareSectionIndexTest();
92 $this->fixture
->id
= 10;
93 $this->fixture
->sys_page
->expects($this->once())->method('getPage')->will($this->returnValue(NULL))->with(10);
94 $result = $this->fixture
->_call('sectionIndex', 'field');
95 $this->assertEquals($result, array());
100 * @expectedException UnexpectedValueException
102 public function sectionIndexThrowsAnExceptionIfTheInternalQueryFails() {
103 $this->prepareSectionIndexTest();
104 $this->fixture
->sys_page
->expects($this->once())->method('getPage')->will($this->returnValue(array()));
105 $this->fixture
->parent_cObj
->expects($this->once())->method('exec_getQuery')->will($this->returnValue(0));
106 $this->fixture
->_call('sectionIndex', 'field');
112 public function sectionIndexReturnsOverlaidRowBasedOnTheLanguageOfTheGivenPage() {
113 $this->prepareSectionIndexTest();
114 $this->fixture
->mconf
['sectionIndex.']['type'] = 'all';
115 $GLOBALS['TSFE']->sys_language_contentOL
= 1;
116 $this->fixture
->sys_page
->expects($this->once())->method('getPage')->will($this->returnValue(array('_PAGES_OVERLAY_LANGUAGE' => 1)));
117 $this->fixture
->parent_cObj
->expects($this->once())->method('exec_getQuery')->will($this->returnValue(1));
118 $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)));
119 $this->fixture
->sys_page
->expects($this->once())->method('getRecordOverlay')->will($this->returnValue(array('uid' => 0, 'header' => 'OVERLAID')));
120 $result = $this->fixture
->_call('sectionIndex', 'field');
121 $this->assertEquals($result[0]['title'], 'OVERLAID');
127 public function sectionIndexFiltersDataProvider() {
129 'unfiltered fields' => array(
137 'with unset section index' => array(
145 'with unset header' => array(
153 'with header layout 100' => array(
158 'header_layout' => 100
166 * @dataProvider sectionIndexFiltersDataProvider
167 * @param integer $expectedAmount
168 * @param array $dataRow
170 public function sectionIndexFilters($expectedAmount, array $dataRow) {
171 $this->prepareSectionIndexTest();
172 $this->fixture
->mconf
['sectionIndex.']['type'] = 'header';
173 $this->fixture
->sys_page
->expects($this->once())->method('getPage')->will($this->returnValue(array()));
174 $this->fixture
->parent_cObj
->expects($this->once())->method('exec_getQuery')->will($this->returnValue(1));
175 $GLOBALS['TYPO3_DB']->expects($this->exactly(2))->method('sql_fetch_assoc')->will($this->onConsecutiveCalls($this->returnValue($dataRow), $this->returnValue(FALSE)));
176 $result = $this->fixture
->_call('sectionIndex', 'field');
177 $this->assertCount($expectedAmount, $result);
183 public function sectionIndexQueriesWithDifferentColPosDataProvider() {
185 'no configuration' => array(
189 'with useColPos 2' => array(
190 array('useColPos' => 2),
193 'with useColPos -1' => array(
194 array('useColPos' => -1),
197 'with stdWrap useColPos' => array(
199 'useColPos.' => array(
210 * @dataProvider sectionIndexQueriesWithDifferentColPosDataProvider
211 * @param array $configuration
212 * @param string $whereClausePrefix
214 public function sectionIndexQueriesWithDifferentColPos($configuration, $whereClausePrefix) {
215 $this->prepareSectionIndexTest();
216 $this->fixture
->sys_page
->expects($this->once())->method('getPage')->will($this->returnValue(array()));
217 $this->fixture
->mconf
['sectionIndex.'] = $configuration;
218 $queryConfiguration = array(
220 'orderBy' => 'field',
221 'languageField' => 'sys_language_uid',
222 'where' => $whereClausePrefix
224 $this->fixture
->parent_cObj
->expects($this->once())->method('exec_getQuery')->with('tt_content', $queryConfiguration)->will($this->returnValue(1));
225 $this->fixture
->_call('sectionIndex', 'field', 12);