TYPO3 CMS  TYPO3_6-2
DependencyUtilityTest.php
Go to the documentation of this file.
1 <?php
3 
22 
26  protected $objectManagerMock;
27 
31  public function setUp() {
32  $this->objectManagerMock = $this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface');
33  }
34 
39  public function checkTypo3DependencyThrowsExceptionIfVersionNumberIsTooLow() {
41  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', 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', array('dummy'));
45 
46  $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException','', 1399144499);
47  $dependencyUtility->_call('checkTypo3Dependency', $dependencyMock);
48  }
49 
54  public function checkTypo3DependencyThrowsExceptionIfVersionNumberIsTooHigh() {
56  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', 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', array('dummy'));
61 
62  $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', '', 1399144521);
63  $dependencyUtility->_call('checkTypo3Dependency', $dependencyMock);
64  }
65 
70  public function checkTypo3DependencyThrowsExceptionIfIdentifierIsNotTypo3() {
72  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
73  $dependencyMock->setIdentifier('123');
74  $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
75 
76  $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', '', 1399144551);
77  $dependencyUtility->_call('checkTypo3Dependency', $dependencyMock);
78  }
79 
84  public function checkTypo3DependencyReturnsTrueIfVersionNumberIsInRange() {
86  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', 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', array('dummy'));
91 
92  $this->assertTrue($dependencyUtility->_call('checkTypo3Dependency', $dependencyMock));
93  }
94 
99  public function checkTypo3DependencyCanHandleEmptyVersionHighestVersion() {
101  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', 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', array('dummy'));
106 
107  $this->assertTrue($dependencyUtility->_call('checkTypo3Dependency', $dependencyMock));
108  }
109 
114  public function checkTypo3DependencyCanHandleEmptyVersionLowestVersion() {
116  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', 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', array('dummy'));
121 
122  $this->assertTrue($dependencyUtility->_call('checkTypo3Dependency', $dependencyMock));
123  }
124 
129  public function checkPhpDependencyThrowsExceptionIfVersionNumberIsTooLow() {
131  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', 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', array('dummy'));
135 
136  $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', '', 1377977857);
137  $dependencyUtility->_call('checkPhpDependency', $dependencyMock);
138  }
139 
144  public function checkPhpDependencyThrowsExceptionIfVersionNumberIsTooHigh() {
146  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', 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', array('dummy'));
151 
152  $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', '', 1377977856);
153  $dependencyUtility->_call('checkPhpDependency', $dependencyMock);
154  }
155 
160  public function checkPhpDependencyThrowsExceptionIfIdentifierIsNotTypo3() {
162  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
163  $dependencyMock->setIdentifier('123');
164  $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
165 
166  $this->setExpectedException('TYPO3\\CMS\\Extensionmanager\\Exception\\ExtensionManagerException', '', 1377977858);
167  $dependencyUtility->_call('checkPhpDependency', $dependencyMock);
168  }
169 
174  public function checkPhpDependencyReturnsTrueIfVersionNumberIsInRange() {
176  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', 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', array('dummy'));
181 
182  $this->assertTrue($dependencyUtility->_call('checkPhpDependency', $dependencyMock));
183  }
184 
189  public function checkPhpDependencyCanHandleEmptyVersionHighestVersion() {
191  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', 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', array('dummy'));
196 
197  $this->assertTrue($dependencyUtility->_call('checkPhpDependency', $dependencyMock));
198  }
199 
204  public function checkPhpDependencyCanHandleEmptyVersionLowestVersion() {
206  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', 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', array('dummy'));
211 
212  $this->assertTrue($dependencyUtility->_call('checkPhpDependency', $dependencyMock));
213  }
214 
219  public function checkDependenciesCallsMethodToCheckPhpDependencies() {
221  $extensionMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
223  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
224  $dependencyMock->setIdentifier('php');
225  $dependencyStorage = new \SplObjectStorage();
226  $dependencyStorage->attach($dependencyMock);
227  $extensionMock->setDependencies($dependencyStorage);
229  $dependencyUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('checkPhpDependency', 'checkTypo3Dependency'));
230  $dependencyUtility->expects($this->atLeastOnce())->method('checkPhpDependency');
231  $dependencyUtility->checkDependencies($extensionMock);
232  }
233 
238  public function checkDependenciesCallsMethodToCheckTypo3Dependencies() {
240  $extensionMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('dummy'));
242  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getHighestVersion', 'getLowestVersion'));
243  $dependencyMock->setIdentifier('typo3');
244  $dependencyStorage = new \SplObjectStorage();
245  $dependencyStorage->attach($dependencyMock);
246  $extensionMock->setDependencies($dependencyStorage);
248  $dependencyUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('checkPhpDependency', 'checkTypo3Dependency'));
249 
250  $dependencyUtility->expects($this->atLeastOnce())->method('checkTypo3Dependency');
251  $dependencyUtility->checkDependencies($extensionMock);
252  }
253 
258  public function isVersionCompatibleReturnsTrueForCompatibleVersion() {
260  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', 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', array('dummy'));
265 
266  $this->assertTrue($dependencyUtility->_call('isVersionCompatible', $version, $dependencyMock));
267  }
268 
273  public function isVersionCompatibleReturnsFalseForIncompatibleVersion() {
275  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', 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', array('dummy'));
280 
281  $this->assertFalse($dependencyUtility->_call('isVersionCompatible', $version, $dependencyMock));
282  }
283 
289  $availableExtensions = array(
290  'dummy' => array(),
291  'foo' => array(),
292  'bar' => array()
293  );
294  $listUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility', array('getAvailableExtensions'));
295  $listUtilityMock->expects($this->atLeastOnce())->method('getAvailableExtensions')->will($this->returnValue($availableExtensions));
296  $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
297  $dependencyUtility->_set('listUtility', $listUtilityMock);
298 
299  $this->assertTrue($dependencyUtility->_call('isDependentExtensionAvailable', 'dummy'));
300  }
301 
307  $availableExtensions = array(
308  'dummy' => array(),
309  'foo' => array(),
310  'bar' => array()
311  );
312  $listUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ListUtility', array('getAvailableExtensions'));
313  $listUtilityMock->expects($this->atLeastOnce())->method('getAvailableExtensions')->will($this->returnValue($availableExtensions));
314  $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('dummy'));
315  $dependencyUtility->_set('listUtility', $listUtilityMock);
316 
317  $this->assertFalse($dependencyUtility->_call('isDependentExtensionAvailable', '42'));
318  }
319 
325  $emConfUtility = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\EmConfUtility', 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', array('setAvailableExtensions', 'isVersionCompatible'));
331  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', 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 
349  $extensionRepositoryMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository', 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', array('dummy'));
352  $dependencyUtility->_set('extensionRepository', $extensionRepositoryMock);
353  $count = $dependencyUtility->_call('isExtensionDownloadableFromTer', 'test123');
354 
355  $this->assertTrue($count);
356  }
357 
363  $extensionRepositoryMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository', 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', array('dummy'));
366  $dependencyUtility->_set('extensionRepository', $extensionRepositoryMock);
367  $count = $dependencyUtility->_call('isExtensionDownloadableFromTer', 'test123');
368 
369  $this->assertFalse($count);
370  }
371 
377  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', 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', 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', array('dummy'));
384  $dependencyUtility->_set('extensionRepository', $extensionRepositoryMock);
385  $count = $dependencyUtility->_call('isDownloadableVersionCompatible', $dependencyMock);
386 
387  $this->assertTrue($count);
388  }
389 
395  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('getIdentifier'));
396  $dependencyMock->expects($this->once())->method('getIdentifier')->will($this->returnValue('dummy'));
397  $extensionRepositoryMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Repository\\ExtensionRepository', 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', 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 
415  $expectedVersions = array(
416  'lowestIntegerVersion' => 1000000,
417  'highestIntegerVersion' => 2000000
418  );
419 
420  $dependencyMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', 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', array('dummy'));
424  $versions = $dependencyUtility->_call('getLowestAndHighestIntegerVersions', $dependencyMock);
425 
426  $this->assertSame($expectedVersions, $versions);
427  }
428 
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 = $this->getUniqueId('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', array('getIdentifier'));
446  $dependencyMock->expects($this->once())->method('getIdentifier')->will($this->returnValue('foobar'));
447  $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', 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', 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', $extension);
458  $this->assertSame('foo', $extension->getExtensionKey());
459  }
460 
461 }
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)