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