[BUGFIX] Do not fetch extension list on every request
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Controller / UpdateFromTerControllerTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2012 Susanne Moog, <typo3@susannemoog.de>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24
25 /**
26 * Testcase for the Tx_Extensionmanager_Utility_List class in the TYPO3 Core.
27 *
28 * @package Extension Manager
29 * @subpackage Tests
30 */
31 class Tx_Extensionmanager_Controller_UpdateFromTerControllerTest extends Tx_Extbase_Tests_Unit_BaseTestCase {
32
33 /**
34 * Enable backup of global and system variables
35 *
36 * @var boolean
37 */
38 protected $backupGlobals = TRUE;
39
40 /**
41 * Exclude TYPO3_DB from backup/ restore of $GLOBALS
42 * because resource types cannot be handled during serializing
43 *
44 * @var array
45 */
46 protected $backupGlobalsBlacklist = array('TYPO3_DB');
47
48 /**
49 * @test
50 * @return void
51 */
52 public function updateExtensionListFromTerCallsUpdateExtListIfLastUpdateIsMoreThan24HoursAgo() {
53 $controllerMock = $this->getAccessibleMock(
54 'Tx_Extensionmanager_Controller_UpdateFromTerController',
55 array('dummy')
56 );
57 $repositoryRepositoryMock = $this->getAccessibleMock(
58 'Tx_Extensionmanager_Domain_Repository_RepositoryRepository',
59 array('findOneByUid')
60 );
61 $repositoryModelMock = $this->getAccessibleMock(
62 'Tx_Extensionmanager_Domain_Model_Repository',
63 array('getLastUpdate')
64 );
65 $repositoryHelperMock = $this->getAccessibleMock(
66 'Tx_Extensionmanager_Utility_Repository_Helper',
67 array('updateExtList')
68 );
69 $viewMock = $this->getAccessibleMock(
70 'Tx_Fluid_View_TemplateView',
71 array('assign')
72 );
73
74 $requestMock = $this->getAccessibleMock(
75 'Tx_Extbase_MVC_Request',
76 array('hasArgument', 'getArgument')
77 );
78
79 $viewMock->expects($this->any())
80 ->method('assign')
81 ->will($this->returnValue($viewMock));
82
83 $lastUpdateDate = new DateTime();
84 // Wed Jul 25 18:40:02 CEST 2012
85 $lastUpdateDate->setTimestamp(1343234402);
86 $repositoryModelMock->expects($this->once())
87 ->method('getLastUpdate')
88 ->will($this->returnValue($lastUpdateDate));
89
90
91
92 $repositoryRepositoryMock
93 ->expects($this->once())
94 ->method('findOneByUid')
95 ->with(1)
96 ->will($this->returnValue($repositoryModelMock));
97
98 $repositoryHelperMock->expects($this->once())
99 ->method('updateExtList');
100 // Sat Jul 28 18:40:02 CEST 2012
101 $GLOBALS['EXEC_TIME'] = 1343493602;
102
103 $controllerMock->_set('repositoryRepository', $repositoryRepositoryMock);
104 $controllerMock->_set('repositoryHelper', $repositoryHelperMock);
105 $controllerMock->_set('settings', array('repositoryUid' => 1));
106 $controllerMock->_set('view', $viewMock);
107 $controllerMock->_set('request', $requestMock);
108 $controllerMock->updateExtensionListFromTerAction();
109 }
110
111 /**
112 * @test
113 * @return void
114 */
115 public function updateExtensionListFromTerDoesNotCallUpdateExtListIfLastUpdateIsLessThan24HoursAgo() {
116 $controllerMock = $this->getAccessibleMock(
117 'Tx_Extensionmanager_Controller_UpdateFromTerController',
118 array('dummy')
119 );
120 $repositoryRepositoryMock = $this->getAccessibleMock(
121 'Tx_Extensionmanager_Domain_Repository_RepositoryRepository',
122 array('findOneByUid')
123 );
124 $repositoryModelMock = $this->getAccessibleMock(
125 'Tx_Extensionmanager_Domain_Model_Repository',
126 array('getLastUpdate')
127 );
128 $repositoryHelperMock = $this->getAccessibleMock(
129 'Tx_Extensionmanager_Utility_Repository_Helper',
130 array('updateExtList')
131 );
132 $viewMock = $this->getAccessibleMock(
133 'Tx_Fluid_View_TemplateView',
134 array('assign')
135 );
136
137 $requestMock = $this->getAccessibleMock(
138 'Tx_Extbase_MVC_Request',
139 array('hasArgument', 'getArgument')
140 );
141
142 $viewMock->expects($this->any())
143 ->method('assign')
144 ->will($this->returnValue($viewMock));
145
146 $lastUpdateDate = new DateTime();
147 // Wed Jul 25 18:40:02 CEST 2012
148 $lastUpdateDate->setTimestamp(1343493602);
149 $repositoryModelMock->expects($this->once())
150 ->method('getLastUpdate')
151 ->will($this->returnValue($lastUpdateDate));
152
153
154
155 $repositoryRepositoryMock
156 ->expects($this->once())
157 ->method('findOneByUid')
158 ->with(1)
159 ->will($this->returnValue($repositoryModelMock));
160
161 $repositoryHelperMock->expects($this->never())
162 ->method('updateExtList');
163 // Sat Jul 28 18:40:02 CEST 2012
164 $GLOBALS['EXEC_TIME'] = 1343493602;
165
166 $controllerMock->_set('repositoryRepository', $repositoryRepositoryMock);
167 $controllerMock->_set('repositoryHelper', $repositoryHelperMock);
168 $controllerMock->_set('settings', array('repositoryUid' => 1));
169 $controllerMock->_set('view', $viewMock);
170 $controllerMock->_set('request', $requestMock);
171 $controllerMock->updateExtensionListFromTerAction();
172 }
173
174 /**
175 * @test
176 * @return void
177 */
178 public function updateExtensionListFromTerCallsUpdateExtListIfForceUpdateCheckIsSet() {
179 $controllerMock = $this->getAccessibleMock(
180 'Tx_Extensionmanager_Controller_UpdateFromTerController',
181 array('dummy')
182 );
183 $repositoryRepositoryMock = $this->getAccessibleMock(
184 'Tx_Extensionmanager_Domain_Repository_RepositoryRepository',
185 array('findOneByUid')
186 );
187 $repositoryModelMock = $this->getAccessibleMock(
188 'Tx_Extensionmanager_Domain_Model_Repository',
189 array('getLastUpdate')
190 );
191 $repositoryHelperMock = $this->getAccessibleMock(
192 'Tx_Extensionmanager_Utility_Repository_Helper',
193 array('updateExtList')
194 );
195 $viewMock = $this->getAccessibleMock(
196 'Tx_Fluid_View_TemplateView',
197 array('assign')
198 );
199
200 $viewMock->expects($this->any())
201 ->method('assign')
202 ->will($this->returnValue($viewMock));
203
204 $lastUpdateDate = new DateTime();
205 // Wed Jul 25 18:40:02 CEST 2012
206 $lastUpdateDate->setTimestamp(1343234402);
207 $repositoryModelMock->expects($this->once())
208 ->method('getLastUpdate')
209 ->will($this->returnValue($lastUpdateDate));
210
211 $repositoryRepositoryMock
212 ->expects($this->once())
213 ->method('findOneByUid')
214 ->with(1)
215 ->will($this->returnValue($repositoryModelMock));
216
217 $repositoryHelperMock->expects($this->once())
218 ->method('updateExtList');
219
220 // Sat Jul 28 18:40:02 CEST 2012
221 $GLOBALS['EXEC_TIME'] = 1343493602;
222
223 $controllerMock->_set('repositoryRepository', $repositoryRepositoryMock);
224 $controllerMock->_set('repositoryHelper', $repositoryHelperMock);
225 $controllerMock->_set('settings', array('repositoryUid' => 1));
226 $controllerMock->_set('view', $viewMock);
227 $controllerMock->_set('request', $requestMock);
228 $controllerMock->updateExtensionListFromTerAction(TRUE);
229 }
230 }
231 ?>