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