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