00af3cc2eabd703193b22bdb8d4a182efcaa47fe
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Unit / Utility / DependencyUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012
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 /**
28 * Test for DependencyUtility
29 *
30 * @package Extension Manager
31 * @subpackage Tests
32 */
33 class DependencyUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
34
35 /**
36 * @test
37 * @return void
38 */
39 public function convertDependenciesToObjectsCreatesObjectStorage() {
40 $serializedDependencies = serialize(array(
41 'depends' => array(
42 'php' => '5.1.0-0.0.0',
43 'typo3' => '4.2.0-4.4.99',
44 'fn_lib' => ''
45 )
46 ));
47 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\DependencyUtility */
48 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
49 $objectManagerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', array('create'));
50 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('dummy'));
51 $objectManagerMock->expects($this->any())->method('create')->will($this->returnValue($dependencyModelMock));
52 $dependencyUtility->_set('objectManager', $objectManagerMock);
53 $objectStorage = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
54 $this->assertTrue($objectStorage instanceof \SplObjectStorage);
55 }
56
57 /**
58 * @test
59 * @return void
60 */
61 public function convertDependenciesToObjectsSetsIdentifier() {
62 $serializedDependencies = serialize(array(
63 'depends' => array(
64 'php' => '5.1.0-0.0.0',
65 'typo3' => '4.2.0-4.4.99',
66 'fn_lib' => ''
67 )
68 ));
69 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\DependencyUtility */
70 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
71 $objectManagerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', array('create'));
72 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('setIdentifier'));
73 $objectManagerMock->expects($this->any())->method('create')->will($this->returnValue($dependencyModelMock));
74 $dependencyUtility->_set('objectManager', $objectManagerMock);
75 $dependencyModelMock->expects($this->at(0))->method('setIdentifier')->with('php');
76 $dependencyModelMock->expects($this->at(1))->method('setIdentifier')->with('typo3');
77 $dependencyModelMock->expects($this->at(2))->method('setIdentifier')->with('fn_lib');
78 $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
79 }
80
81 /**
82 * @return array
83 */
84 public function convertDependenciesToObjectSetsVersionDataProvider() {
85 return array(
86 'everything ok' => array(
87 array(
88 'depends' => array(
89 'typo3' => '4.2.0-4.4.99'
90 )
91 ),
92 array(
93 '4.2.0',
94 '4.4.99'
95 )
96 ),
97 'empty high value' => array(
98 array(
99 'depends' => array(
100 'typo3' => '4.2.0-0.0.0'
101 )
102 ),
103 array(
104 '4.2.0',
105 ''
106 )
107 ),
108 'empty low value' => array(
109 array(
110 'depends' => array(
111 'typo3' => '0.0.0-4.4.99'
112 )
113 ),
114 array(
115 '',
116 '4.4.99'
117 )
118 )
119 );
120 }
121
122 /**
123 * @test * @return void
124 * @dataProvider convertDependenciesToObjectSetsVersionDataProvider
125 * @param $dependencyString
126 * @param $returnValue
127 * @return void
128 */
129 public function convertDependenciesToObjectSetsVersion($dependencyString, $returnValue) {
130 $serializedDependencies = serialize($dependencyString);
131 /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\DependencyUtility */
132 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
133 $objectManagerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', array('create'));
134 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('setHighestVersion', 'setLowestVersion'));
135 $objectManagerMock->expects($this->any())->method('create')->will($this->returnValue($dependencyModelMock));
136 $dependencyUtility->_set('objectManager', $objectManagerMock);
137 $dependencyModelMock->expects($this->atLeastOnce())->method('setHighestVersion')->with($returnValue[0]);
138 $dependencyModelMock->expects($this->atLeastOnce())->method('setLowestVersion')->with($returnValue[1]);
139 $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
140 }
141
142 /**
143 * @test
144 * @return void
145 */
146 public function checkTypo3DependencyThrowsExceptionIfVersionNumberIsTooLow() {
147 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
148 $dependencyModelMock->expects($this->atLeastOnce())->method('getLowestVersion')->will($this->returnValue('15.0.0'));
149 $dependencyModelMock->_set('identifier', 'typo3');
150 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
151 $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', 'Your TYPO3 version is lower than necessary. You need at least TYPO3 version 15.0.0');
152 $dependencyUtility->_call('checkTypo3Dependency', $dependencyModelMock);
153 }
154
155 /**
156 * @test
157 * @return void
158 */
159 public function checkTypo3DependencyThrowsExceptionIfVersionNumberIsTooHigh() {
160 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
161 $dependencyModelMock->expects($this->atLeastOnce())->method('getHighestVersion')->will($this->returnValue('3.0.0'));
162 $dependencyModelMock->expects($this->atLeastOnce())->method('getLowestVersion')->will($this->returnValue('1.0.0'));
163 $dependencyModelMock->_set('identifier', 'typo3');
164 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
165 $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', 'Your TYPO3 version is higher than allowed. You can use TYPO3 versions 1.0.0 - 3.0.0');
166 $dependencyUtility->_call('checkTypo3Dependency', $dependencyModelMock);
167 }
168
169 /**
170 * @test
171 * @return void
172 */
173 public function checkTypo3DependencyThrowsExceptionIfIdentifierIsNotTypo3() {
174 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
175 $dependencyModelMock->_set('identifier', '123');
176 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
177 $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', 'checkTypo3Dependency can only check TYPO3 dependencies. Found dependency with identifier "123"');
178 $dependencyUtility->_call('checkTypo3Dependency', $dependencyModelMock);
179 }
180
181 /**
182 * @test
183 * @return void
184 */
185 public function checkTypo3DependencyReturnsTrueIfVersionNumberIsInRange() {
186 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
187 $dependencyModelMock->expects($this->atLeastOnce())->method('getHighestVersion')->will($this->returnValue('15.0.0'));
188 $dependencyModelMock->expects($this->atLeastOnce())->method('getLowestVersion')->will($this->returnValue('1.0.0'));
189 $dependencyModelMock->_set('identifier', 'typo3');
190 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
191 $this->assertTrue($dependencyUtility->_call('checkTypo3Dependency', $dependencyModelMock));
192 }
193
194 /**
195 * @test
196 * @return void
197 */
198 public function checkTypo3DependencyCanHandleEmptyVersionHighestVersion() {
199 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
200 $dependencyModelMock->expects($this->atLeastOnce())->method('getHighestVersion')->will($this->returnValue(''));
201 $dependencyModelMock->expects($this->atLeastOnce())->method('getLowestVersion')->will($this->returnValue('1.0.0'));
202 $dependencyModelMock->_set('identifier', 'typo3');
203 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
204 $this->assertTrue($dependencyUtility->_call('checkTypo3Dependency', $dependencyModelMock));
205 }
206
207 /**
208 * @test
209 * @return void
210 */
211 public function checkTypo3DependencyCanHandleEmptyVersionLowestVersion() {
212 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
213 $dependencyModelMock->expects($this->atLeastOnce())->method('getHighestVersion')->will($this->returnValue('15.0.0'));
214 $dependencyModelMock->expects($this->atLeastOnce())->method('getLowestVersion')->will($this->returnValue(''));
215 $dependencyModelMock->_set('identifier', 'typo3');
216 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
217 $this->assertTrue($dependencyUtility->_call('checkTypo3Dependency', $dependencyModelMock));
218 }
219
220 /**
221 * @test
222 * @return void
223 */
224 public function checkPhpDependencyThrowsExceptionIfVersionNumberIsTooLow() {
225 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
226 $dependencyModelMock->expects($this->atLeastOnce())->method('getLowestVersion')->will($this->returnValue('15.0.0'));
227 $dependencyModelMock->_set('identifier', 'php');
228 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
229 $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', 'Your PHP version is lower than necessary. You need at least PHP version 15.0.0');
230 $dependencyUtility->_call('checkPhpDependency', $dependencyModelMock);
231 }
232
233 /**
234 * @test
235 * @return void
236 */
237 public function checkPhpDependencyThrowsExceptionIfVersionNumberIsTooHigh() {
238 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
239 $dependencyModelMock->expects($this->atLeastOnce())->method('getHighestVersion')->will($this->returnValue('3.0.0'));
240 $dependencyModelMock->expects($this->atLeastOnce())->method('getLowestVersion')->will($this->returnValue('1.0.0'));
241 $dependencyModelMock->_set('identifier', 'PHP');
242 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
243 $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', 'Your PHP version is higher than allowed. You can use PHP versions 1.0.0 - 3.0.0');
244 $dependencyUtility->_call('checkPhpDependency', $dependencyModelMock);
245 }
246
247 /**
248 * @test
249 * @return void
250 */
251 public function checkPhpDependencyThrowsExceptionIfIdentifierIsNotTypo3() {
252 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
253 $dependencyModelMock->_set('identifier', '123');
254 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
255 $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', 'checkPhpDependency can only check PHP dependencies. Found dependency with identifier "123"');
256 $dependencyUtility->_call('checkPhpDependency', $dependencyModelMock);
257 }
258
259 /**
260 * @test
261 * @return void
262 */
263 public function checkPhpDependencyReturnsTrueIfVersionNumberIsInRange() {
264 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
265 $dependencyModelMock->expects($this->atLeastOnce())->method('getHighestVersion')->will($this->returnValue('15.0.0'));
266 $dependencyModelMock->expects($this->atLeastOnce())->method('getLowestVersion')->will($this->returnValue('1.0.0'));
267 $dependencyModelMock->_set('identifier', 'PHP');
268 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
269 $this->assertTrue($dependencyUtility->_call('checkPhpDependency', $dependencyModelMock));
270 }
271
272 /**
273 * @test
274 * @return void
275 */
276 public function checkPhpDependencyCanHandleEmptyVersionHighestVersion() {
277 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
278 $dependencyModelMock->expects($this->atLeastOnce())->method('getHighestVersion')->will($this->returnValue(''));
279 $dependencyModelMock->expects($this->atLeastOnce())->method('getLowestVersion')->will($this->returnValue('1.0.0'));
280 $dependencyModelMock->_set('identifier', 'PHP');
281 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
282 $this->assertTrue($dependencyUtility->_call('checkPhpDependency', $dependencyModelMock));
283 }
284
285 /**
286 * @test
287 * @return void
288 */
289 public function checkPhpDependencyCanHandleEmptyVersionLowestVersion() {
290 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
291 $dependencyModelMock->expects($this->atLeastOnce())->method('getHighestVersion')->will($this->returnValue('15.0.0'));
292 $dependencyModelMock->expects($this->atLeastOnce())->method('getLowestVersion')->will($this->returnValue(''));
293 $dependencyModelMock->_set('identifier', 'PHP');
294 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
295 $this->assertTrue($dependencyUtility->_call('checkPhpDependency', $dependencyModelMock));
296 }
297
298 /**
299 * @test
300 * @return void
301 */
302 public function checkDependenciesCallsMethodToCheckPhpDependencies() {
303 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
304 $dependencyModelMock->_set('identifier', 'php');
305 $dependencyStorage = new \SplObjectStorage();
306 $dependencyStorage->attach($dependencyModelMock);
307 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('checkPhpDependency', 'checkTypo3Dependency'));
308 $dependencyUtility->expects($this->atLeastOnce())->method('checkPhpDependency');
309 $dependencyUtility->_call('checkDependencies', $dependencyStorage);
310 }
311
312 /**
313 * @test
314 * @return void
315 */
316 public function checkDependenciesCallsMethodToCheckTypo3Dependencies() {
317 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
318 $dependencyModelMock->_set('identifier', 'TyPo3');
319 $dependencyStorage = new \SplObjectStorage();
320 $dependencyStorage->attach($dependencyModelMock);
321 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('checkPhpDependency', 'checkTypo3Dependency'));
322 $dependencyUtility->expects($this->atLeastOnce())->method('checkTypo3Dependency');
323 $dependencyUtility->_call('checkDependencies', $dependencyStorage);
324 }
325
326 /**
327 * @test
328 * @return void
329 */
330 public function isVersionCompatibleReturnsTrueForCompatibleVersion() {
331 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
332 $dependencyModelMock->expects($this->atLeastOnce())->method('getHighestVersion')->will($this->returnValue('15.0.0'));
333 $dependencyModelMock->expects($this->atLeastOnce())->method('getLowestVersion')->will($this->returnValue('1.0.0'));
334 $version = '3.3.3';
335 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
336 $this->assertTrue($dependencyUtility->_call('isVersionCompatible', $version, $dependencyModelMock));
337 }
338
339 /**
340 * @test
341 * @return void
342 */
343 public function isVersionCompatibleReturnsFalseForIncompatibleVersion() {
344 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
345 $dependencyModelMock->expects($this->atLeastOnce())->method('getHighestVersion')->will($this->returnValue('1.0.1'));
346 $dependencyModelMock->expects($this->atLeastOnce())->method('getLowestVersion')->will($this->returnValue('1.0.0'));
347 $version = '3.3.3';
348 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
349 $this->assertFalse($dependencyUtility->_call('isVersionCompatible', $version, $dependencyModelMock));
350 }
351
352 /**
353 * @test
354 * @return void
355 */
356 public function isDependentExtensionAvailableReturnsTrueIfExtensionIsAvailable() {
357 $availableExtensions = array(
358 'dummy' => array(),
359 'foo' => array(),
360 'bar' => array()
361 );
362 $listUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility', array('getAvailableExtensions'));
363 $listUtilityMock->expects($this->atLeastOnce())->method('getAvailableExtensions')->will($this->returnValue($availableExtensions));
364 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
365 $dependencyUtility->_set('listUtility', $listUtilityMock);
366 $this->assertTrue($dependencyUtility->_call('isDependentExtensionAvailable', 'dummy'));
367 }
368
369 /**
370 * @test
371 * @return void
372 */
373 public function isDependentExtensionAvailableReturnsFalseIfExtensionIsNotAvailable() {
374 $availableExtensions = array(
375 'dummy' => array(),
376 'foo' => array(),
377 'bar' => array()
378 );
379 $listUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility', array('getAvailableExtensions'));
380 $listUtilityMock->expects($this->atLeastOnce())->method('getAvailableExtensions')->will($this->returnValue($availableExtensions));
381 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
382 $dependencyUtility->_set('listUtility', $listUtilityMock);
383 $this->assertFalse($dependencyUtility->_call('isDependentExtensionAvailable', '42'));
384 }
385
386 /**
387 * @test
388 * @return void
389 */
390 public function isAvailableVersionCompatibleCallsIsVersionCompatibleWithExtensionVersion() {
391 $emConfUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\EmConfUtility', array('includeEmConf'));
392 $emConfUtility->expects($this->once())->method('includeEmConf')->will($this->returnValue(array(
393 'key' => 'dummy',
394 'version' => '1.0.0'
395 )));
396 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('setAvailableExtensions', 'isVersionCompatible'));
397 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getIdentifier'));
398 $dependencyModelMock->expects($this->once())->method('getIdentifier')->will($this->returnValue('dummy'));
399 $dependencyUtility->_set('emConfUtility', $emConfUtility);
400 $dependencyUtility->_set('availableExtensions', array(
401 'dummy' => array(
402 'foo' => '42'
403 )
404 ));
405 $dependencyUtility->expects($this->once())->method('setAvailableExtensions');
406 $dependencyUtility->expects($this->once())->method('isVersionCompatible')->with('1.0.0', $this->anything());
407 $dependencyUtility->_call('isAvailableVersionCompatible', $dependencyModelMock);
408 }
409
410 /**
411 * @test
412 * @return void
413 */
414 public function isExtensionDownloadableFromTerReturnsTrueIfOneVersionExists() {
415 $extensionRepositoryMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository', array('countByExtensionKey'));
416 $extensionRepositoryMock->expects($this->once())->method('countByExtensionKey')->with('test123')->will($this->returnValue(1));
417 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
418 $dependencyUtility->_set('extensionRepository', $extensionRepositoryMock);
419 $count = $dependencyUtility->_call('isExtensionDownloadableFromTer', 'test123');
420 $this->assertTrue($count);
421 }
422
423 /**
424 * @test
425 * @return void
426 */
427 public function isExtensionDownloadableFromTerReturnsFalseIfNoVersionExists() {
428 $extensionRepositoryMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository', array('countByExtensionKey'));
429 $extensionRepositoryMock->expects($this->once())->method('countByExtensionKey')->with('test123')->will($this->returnValue(0));
430 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
431 $dependencyUtility->_set('extensionRepository', $extensionRepositoryMock);
432 $count = $dependencyUtility->_call('isExtensionDownloadableFromTer', 'test123');
433 $this->assertFalse($count);
434 }
435
436 /**
437 * @test
438 * @return void
439 */
440 public function isDownloadableVersionCompatibleReturnsTrueIfCompatibleVersionExists() {
441 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getIdentifier', 'getHighestVersion', 'getLowestVersion'));
442 $dependencyModelMock->expects($this->once())->method('getIdentifier')->will($this->returnValue('dummy'));
443 $dependencyModelMock->expects($this->once())->method('getHighestVersion')->will($this->returnValue('10.0.0'));
444 $dependencyModelMock->expects($this->once())->method('getLowestVersion')->will($this->returnValue('1.0.0'));
445 $extensionRepositoryMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository', array('countByVersionRangeAndExtensionKey'));
446 $extensionRepositoryMock->expects($this->once())->method('countByVersionRangeAndExtensionKey')->with('dummy', 1000000, 10000000)->will($this->returnValue(array('1234', '5678')));
447 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
448 $dependencyUtility->_set('extensionRepository', $extensionRepositoryMock);
449 $count = $dependencyUtility->_call('isDownloadableVersionCompatible', $dependencyModelMock);
450 $this->assertTrue($count);
451 }
452
453 /**
454 * @test
455 * @return void
456 */
457 public function isDownloadableVersionCompatibleReturnsFalseIfIncompatibleVersionExists() {
458 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getIdentifier'));
459 $dependencyModelMock->expects($this->once())->method('getIdentifier')->will($this->returnValue('dummy'));
460 $extensionRepositoryMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository', array('countByVersionRangeAndExtensionKey'));
461 $extensionRepositoryMock->expects($this->once())->method('countByVersionRangeAndExtensionKey')->with('dummy', 1000000, 2000000)->will($this->returnValue(array()));
462 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('getLowestAndHighestIntegerVersions'));
463 $dependencyUtility->_set('extensionRepository', $extensionRepositoryMock);
464 $dependencyUtility->expects($this->once())->method('getLowestAndHighestIntegerVersions')->will($this->returnValue(array(
465 'lowestIntegerVersion' => 1000000,
466 'highestIntegerVersion' => 2000000
467 )));
468 $count = $dependencyUtility->_call('isDownloadableVersionCompatible', $dependencyModelMock);
469 $this->assertFalse($count);
470 }
471
472 /**
473 * @test
474 * @return void
475 */
476 public function getLowestAndHighestIntegerVersionsReturnsArrayWithVersions() {
477 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
478 $dependencyModelMock->expects($this->once())->method('getHighestVersion')->will($this->returnValue('2.0.0'));
479 $dependencyModelMock->expects($this->once())->method('getLowestVersion')->will($this->returnValue('1.0.0'));
480 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
481 $versions = $dependencyUtility->_call('getLowestAndHighestIntegerVersions', $dependencyModelMock);
482 $this->assertEquals(array(
483 'lowestIntegerVersion' => 1000000,
484 'highestIntegerVersion' => 2000000
485 ), $versions);
486 }
487
488 /**
489 * @test
490 * @return void
491 */
492 public function getLatestCompatibleExtensionByIntegerVersionDependencyWillReturnExtensionModelOfLatestExtension() {
493 $extension1 = new \TYPO3\CMS\Extensionmanager\Domain\Model\Extension();
494 $extension1->setExtensionKey('foo');
495 $extension1->setVersion('1.0.0');
496 $extension2 = new \TYPO3\CMS\Extensionmanager\Domain\Model\Extension();
497 $extension2->setExtensionKey('bar');
498 $extension2->setVersion('1.0.42');
499 $className = uniqid('objectStorage');
500 eval('class ' . $className . ' {' . 'public $extensions = array();' . 'public function getFirst() {' . ' return $this->extensions[0];' . '}' . '}');
501 $myStorage = new $className();
502 $myStorage->extensions[] = $extension1;
503 $myStorage->extensions[] = $extension2;
504 $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getIdentifier'));
505 $dependencyModelMock->expects($this->once())->method('getIdentifier')->will($this->returnValue('foobar'));
506 $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('getLowestAndHighestIntegerVersions'));
507 $dependencyUtility->expects($this->once())->method('getLowestAndHighestIntegerVersions')->will($this->returnValue(array(
508 'lowestIntegerVersion' => 1000000,
509 'highestIntegerVersion' => 2000000
510 )));
511 $extensionRepositoryMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository', array('findByVersionRangeAndExtensionKeyOrderedByVersion'));
512 $extensionRepositoryMock->expects($this->once())->method('findByVersionRangeAndExtensionKeyOrderedByVersion')->with('foobar', 1000000, 2000000)->will($this->returnValue($myStorage));
513 $dependencyUtility->_set('extensionRepository', $extensionRepositoryMock);
514 $extension = $dependencyUtility->_call('getLatestCompatibleExtensionByIntegerVersionDependency', $dependencyModelMock);
515 $this->assertTrue($extension instanceof \TYPO3\CMS\Extensionmanager\Domain\Model\Extension);
516 $this->assertEquals('foo', $extension->getExtensionKey());
517 }
518
519 }
520
521
522 ?>