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