Raised DBAL version from 1.1.5 to 1.1.6
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Configuration / BackendConfigurationManager_testcase.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
6 * All rights reserved
7 *
8 * This class is a backport of the corresponding class of FLOW3.
9 * All credits go to the v5 team.
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 class Tx_Extbase_Configuration_BackendConfigurationManager_testcase extends Tx_Extbase_BaseTestCase {
29
30 /**
31 * @var array
32 */
33 protected $getBackup;
34
35 /**
36 * @var array
37 */
38 protected $postBackup;
39
40 /**
41 * @var t3lib_DB
42 */
43 protected $typo3DbBackup;
44
45 /**
46 * @var Tx_Extbase_Configuration_BackendConfigurationManager
47 */
48 protected $backendConfigurationManager;
49
50 /**
51 * Sets up this testcase
52 */
53 public function setUp() {
54 $this->getBackup = t3lib_div::_GET();
55 $this->postBackup = t3lib_div::_POST();
56
57 $this->typo3DbBackup = $GLOBALS['TYPO3_DB'];
58 $GLOBALS['TYPO3_DB'] = $this->getMock('t3lib_DB', array());
59
60 $this->backendConfigurationManager = $this->getMock($this->buildAccessibleProxy('Tx_Extbase_Configuration_BackendConfigurationManager'), array('dummy'));
61 }
62
63 /**
64 * Tears down this testcase
65 */
66 public function tearDown() {
67 t3lib_div::_GETset($this->getBackup);
68 $_POST = $this->postBackup;
69 }
70
71 /**
72 * @test
73 */
74 public function loadTypoScriptSetupCantBeTested() {
75 $this->markTestIncomplete('This method can\'t be tested with the current TYPO3 version, because we can\'t mock objects returned from t3lib_div::makeInstance().');
76 }
77
78 /**
79 * @test
80 */
81 public function getCurrentPageIdReturnsPageIdFromGet() {
82 t3lib_div::_GETset(array('id' => 123));
83
84 $expectedResult = 123;
85 $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
86
87 $this->assertEquals($expectedResult, $actualResult);
88 }
89
90 /**
91 * @test
92 */
93 public function getCurrentPageIdReturnsPageIdFromPost() {
94 t3lib_div::_GETset(array('id' => 123));
95 $_POST['id'] = 321;
96
97 $expectedResult = 321;
98 $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
99
100 $this->assertEquals($expectedResult, $actualResult);
101 }
102
103 /**
104 * @test
105 */
106 public function getCurrentPageIdReturnsPidFromFirstRootTemplateIfIdIsNotSet() {
107 $GLOBALS['TYPO3_DB']->expects($this->once())
108 ->method('exec_SELECTgetRows')
109 ->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1')
110 ->will(
111 $this->returnValue(
112 array(
113 array('pid' => 123)
114 )
115 )
116 );
117
118 $expectedResult = 123;
119 $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
120
121 $this->assertEquals($expectedResult, $actualResult);
122 }
123
124 /**
125 * @test
126 */
127 public function getCurrentPageIdReturnsUidFromFirstRootPageIfIdIsNotSetAndNoRootTemplateWasFound() {
128 $GLOBALS['TYPO3_DB']->expects($this->at(0))
129 ->method('exec_SELECTgetRows')
130 ->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1')
131 ->will($this->returnValue(array()));
132
133 $GLOBALS['TYPO3_DB']->expects($this->at(1))
134 ->method('exec_SELECTgetRows')
135 ->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1')
136 ->will(
137 $this->returnValue(
138 array(
139 array('uid' => 321)
140 )
141 )
142 );
143
144 $expectedResult = 321;
145 $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
146
147 $this->assertEquals($expectedResult, $actualResult);
148 }
149
150 /**
151 * @test
152 */
153 public function getCurrentPageIdReturnsDefaultStoragePidIfIdIsNotSetNoRootTemplateAndRootPageWasFound() {
154 $GLOBALS['TYPO3_DB']->expects($this->at(0))
155 ->method('exec_SELECTgetRows')
156 ->with('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1')
157 ->will($this->returnValue(array()));
158
159 $GLOBALS['TYPO3_DB']->expects($this->at(1))
160 ->method('exec_SELECTgetRows')
161 ->with('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1')
162 ->will($this->returnValue(array()));
163
164 $expectedResult = 0;
165 $actualResult = $this->backendConfigurationManager->_call('getCurrentPageId');
166
167 $this->assertEquals($expectedResult, $actualResult);
168 }
169 }
170 ?>