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