TYPO3 CMS  TYPO3_6-2
CoreVersionServiceTest.php
Go to the documentation of this file.
1 <?php
3 
21 
25  public function updateVersionMatrixStoresVersionMatrixInRegistry() {
27  $instance = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Service\\CoreVersionService', array('fetchVersionMatrixFromRemote'), array(), '', FALSE);
28  $registry = $this->getMock('TYPO3\CMS\Core\Registry');
29  $versionArray = array(uniqId());
30  $registry->expects($this->once())->method('set')->with('TYPO3.CMS.Install', 'coreVersionMatrix', $versionArray);
31  $instance->_set('registry', $registry);
32  $instance->expects($this->once())->method('fetchVersionMatrixFromRemote')->will($this->returnValue($versionArray));
33  $instance->updateVersionMatrix();
34  }
35 
39  public function updateVersionMatrixRemovesOldReleasesFromMatrix() {
41  $instance = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Service\\CoreVersionService', array('fetchVersionMatrixFromRemote'), array(), '', FALSE);
42  $registry = $this->getMock('TYPO3\CMS\Core\Registry');
43  $versionArray = array(
44  '6.2' => array(),
45  '6.1' => array(),
46  );
47  $registry
48  ->expects($this->once())
49  ->method('set')
50  ->with('TYPO3.CMS.Install', 'coreVersionMatrix', $this->logicalNot($this->arrayHasKey('6.1')));
51  $instance->_set('registry', $registry);
52  $instance->expects($this->once())->method('fetchVersionMatrixFromRemote')->will($this->returnValue($versionArray));
53  $instance->updateVersionMatrix();
54  }
55 
59  public function isInstalledVersionAReleasedVersionReturnsTrueForNonDevelopmentVersion() {
61  $instance = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Service\\CoreVersionService', array('getInstalledVersion'), array(), '', FALSE);
62  $instance->expects($this->once())->method('getInstalledVersion')->will($this->returnValue('6.2.0'));
63  $this->assertTrue($instance->isInstalledVersionAReleasedVersion());
64  }
65 
69  public function isInstalledVersionAReleasedVersionReturnsFalseForDevelopmentVersion() {
71  $instance = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Service\\CoreVersionService', array('getInstalledVersion'), array(), '', FALSE);
72  $instance->expects($this->once())->method('getInstalledVersion')->will($this->returnValue('6.2-dev'));
73  $this->assertFalse($instance->isInstalledVersionAReleasedVersion());
74  }
75 
80  public function getTarGzSha1OfVersionThrowsExceptionIfSha1DoesNotExistInMatrix() {
82  $instance = $this->getAccessibleMock(
83  'TYPO3\\CMS\\Install\\Service\\CoreVersionService',
84  array('getVersionMatrix', 'getMinorVersion', 'ensureVersionExistsInMatrix'),
85  array(),
86  '',
87  FALSE
88  );
89  $versionMatrix = array(
90  '6.2' => array(
91  'releases' => array(
92  '6.2.42' => array(),
93  ),
94  ),
95  );
96  $instance->expects($this->once())->method('getMinorVersion')->will($this->returnValue('6.2'));
97  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
98  $this->assertTrue($instance->getTarGzSha1OfVersion('6.2.42'));
99  }
100 
104  public function getTarGzSha1OfVersionReturnsSha1OfSpecifiedVersion() {
105  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
107  $instance = $this->getAccessibleMock(
108  'TYPO3\\CMS\\Install\\Service\\CoreVersionService',
109  array('getVersionMatrix', 'getMinorVersion', 'ensureVersionExistsInMatrix'),
110  array(),
111  '',
112  FALSE
113  );
114  $instance->expects($this->any())->method('getMinorVersion')->will($this->returnValue('6.2'));
115  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
116  $this->assertSame('3dc156eed4b99577232f537d798a8691493f8a83', $instance->getTarGzSha1OfVersion('6.2.0alpha3'));
117  }
118 
124  public function isYoungerPatchReleaseAvailableReturnsTrueIfYoungerReleaseIsAvailable() {
126  $instance = $this->getAccessibleMock(
127  'TYPO3\\CMS\\Install\\Service\\CoreVersionService',
128  array('getVersionMatrix', 'getInstalledVersion'),
129  array(),
130  '',
131  FALSE
132  );
133  $versionMatrix = array(
134  '6.2' => array(
135  'releases' => array(
136  '6.2.42' => array(
137  'type' => 'regular',
138  'date' => '2013-12-01 18:24:25 UTC',
139  ),
140  '6.2.41' => array(
141  'type' => 'regular',
142  'date' => '2013-11-01 18:24:25 UTC',
143  ),
144  ),
145  ),
146  );
147  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
148  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('6.2.41'));
149  $this->assertTrue($instance->isYoungerPatchReleaseAvailable());
150  }
151 
157  public function isYoungerReleaseAvailableReturnsFalseIfNoYoungerReleaseExists() {
159  $instance = $this->getAccessibleMock(
160  'TYPO3\\CMS\\Install\\Service\\CoreVersionService',
161  array('getVersionMatrix', 'getInstalledVersion'),
162  array(),
163  '',
164  FALSE
165  );
166  $versionMatrix = array(
167  '6.2' => array(
168  'releases' => array(
169  '6.2.42' => array(
170  'type' => 'regular',
171  'date' => '2013-12-01 18:24:25 UTC',
172  ),
173  '6.2.41' => array(
174  'type' => 'regular',
175  'date' => '2013-11-01 18:24:25 UTC',
176  ),
177  ),
178  ),
179  );
180  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
181  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('6.2.42'));
182  $this->assertFalse($instance->isYoungerPatchReleaseAvailable());
183  }
184 
190  public function isYoungerReleaseAvailableReturnsFalseIfOnlyADevelopmentReleaseIsYounger() {
192  $instance = $this->getAccessibleMock(
193  'TYPO3\\CMS\\Install\\Service\\CoreVersionService',
194  array('getVersionMatrix', 'getInstalledVersion'),
195  array(),
196  '',
197  FALSE
198  );
199  $versionMatrix = array(
200  '6.2' => array(
201  'releases' => array(
202  '6.2.42' => array(
203  'type' => 'development',
204  'date' => '2013-12-01 18:24:25 UTC',
205  ),
206  '6.2.41' => array(
207  'type' => 'regular',
208  'date' => '2013-11-01 18:24:25 UTC',
209  ),
210  ),
211  ),
212  );
213  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
214  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('6.2.41'));
215  $this->assertFalse($instance->isYoungerPatchReleaseAvailable());
216  }
217 
223  public function isYoungerDevelopmentReleaseAvailableReturnsTrueIfADevelopmentReleaseIsYounger() {
225  $instance = $this->getAccessibleMock(
226  'TYPO3\\CMS\\Install\\Service\\CoreVersionService',
227  array('getVersionMatrix', 'getInstalledVersion'),
228  array(),
229  '',
230  FALSE
231  );
232  $versionMatrix = array(
233  '6.2' => array(
234  'releases' => array(
235  '6.2.42' => array(
236  'type' => 'development',
237  'date' => '2013-12-01 18:24:25 UTC',
238  ),
239  '6.2.41' => array(
240  'type' => 'regular',
241  'date' => '2013-11-01 18:24:25 UTC',
242  ),
243  ),
244  ),
245  );
246  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
247  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('6.2.41'));
248  $this->assertTrue($instance->isYoungerPatchDevelopmentReleaseAvailable());
249  }
250 
256  public function isUpdateSecurityRelevantReturnsTrueIfAnUpdateIsSecurityRelevant() {
258  $instance = $this->getAccessibleMock(
259  'TYPO3\\CMS\\Install\\Service\\CoreVersionService',
260  array('getVersionMatrix', 'getInstalledVersion'),
261  array(),
262  '',
263  FALSE
264  );
265  $versionMatrix = array(
266  '6.2' => array(
267  'releases' => array(
268  '6.2.42' => array(
269  'type' => 'security',
270  'date' => '2013-12-01 18:24:25 UTC',
271  ),
272  '6.2.41' => array(
273  'type' => 'regular',
274  'date' => '2013-11-01 18:24:25 UTC',
275  ),
276  ),
277  ),
278  );
279  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
280  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('6.2.41'));
281  $this->assertTrue($instance->isUpdateSecurityRelevant());
282  }
283 
289  public function isUpdateSecurityRelevantReturnsFalseIfUpdateIsNotSecurityRelevant() {
291  $instance = $this->getAccessibleMock(
292  'TYPO3\\CMS\\Install\\Service\\CoreVersionService',
293  array('getVersionMatrix', 'getInstalledVersion'),
294  array(),
295  '',
296  FALSE
297  );
298  $versionMatrix = array(
299  '6.2' => array(
300  'releases' => array(
301  '6.2.42' => array(
302  'type' => 'regular',
303  'date' => '2013-12-01 18:24:25 UTC',
304  ),
305  '6.2.41' => array(
306  'type' => 'regular',
307  'date' => '2013-11-01 18:24:25 UTC',
308  ),
309  ),
310  ),
311  );
312  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
313  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('6.2.41'));
314  $this->assertFalse($instance->isUpdateSecurityRelevant());
315  }
316 
320  public function getInstalledMinorVersionFetchesInstalledVersionNumber() {
322  $instance = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Service\\CoreVersionService', array('getInstalledVersion'), array(), '', FALSE);
323  $instance->expects($this->once())->method('getInstalledVersion')->will($this->returnValue('6.2.0'));
324  $this->assertSame('6.2', $instance->_call('getInstalledMinorVersion'));
325  }
326 
330  public function getMinorVersionDataProvider() {
331  return array(
332  '6.2.0' => array(
333  '6.2.0',
334  '6.2',
335  ),
336  '6.2-dev' => array(
337  '6.2-dev',
338  '6.2',
339  ),
340  '6.2.0alpha2' => array(
341  '6.2.0alpha2',
342  '6.2',
343  ),
344  '4.5.25' => array(
345  '4.5.25',
346  '4.5',
347  ),
348  );
349  }
350 
355  public function getMinorVersionReturnsCorrectMinorVersion($version, $expectedMajor) {
357  $instance = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Service\\CoreVersionService', array('dummy'), array(), '', FALSE);
358  $this->assertSame($expectedMajor, $instance->_call('getMinorVersion', $version));
359  }
360 
365  public function getVersionMatrixThrowsExceptionIfVersionMatrixIsNotYetSetInRegistry() {
367  $instance = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Service\\CoreVersionService', array('fetchVersionMatrixFromRemote'), array(), '', FALSE);
368  $registry = $this->getMock('TYPO3\CMS\Core\Registry');
369  $registry->expects($this->once())->method('get')->will($this->returnValue(NULL));
370  $instance->_set('registry', $registry);
371  $instance->_call('getVersionMatrix');
372  }
373 
377  public function getVersionMatrixReturnsMatrixFromRegistry() {
379  $instance = $this->getAccessibleMock('TYPO3\\CMS\\Install\\Service\\CoreVersionService', array('fetchVersionMatrixFromRemote'), array(), '', FALSE);
380  $registry = $this->getMock('TYPO3\CMS\Core\Registry');
381  $versionArray = array(uniqId());
382  $registry->expects($this->once())->method('get')->will($this->returnValue($versionArray));
383  $instance->_set('registry', $registry);
384  $this->assertSame($versionArray, $instance->_call('getVersionMatrix'));
385  }
386 
391  public function getReleaseTimestampOfVersionThrowsExceptionIfReleaseDateIsNotDefined() {
392  $versionMatrix = array(
393  '6.2' => array(
394  'releases' => array(
395  '6.2.42' => array()
396  ),
397  ),
398  );
400  $instance = $this->getAccessibleMock(
401  'TYPO3\\CMS\\Install\\Service\\CoreVersionService',
402  array('getVersionMatrix', 'getMinorVersion', 'ensureVersionExistsInMatrix'),
403  array(),
404  '',
405  FALSE
406  );
407  $instance->expects($this->once())->method('getMinorVersion')->will($this->returnValue('6.2'));
408  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
409  $instance->_call('getReleaseTimestampOfVersion', '6.2.42');
410  }
411 
415  public function getReleaseTimestampOfVersionReturnsTimestamp() {
416  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
418  $instance = $this->getAccessibleMock(
419  'TYPO3\\CMS\\Install\\Service\\CoreVersionService',
420  array('getVersionMatrix', 'getMinorVersion', 'ensureVersionExistsInMatrix'),
421  array(),
422  '',
423  FALSE
424  );
425  $instance->expects($this->once())->method('getMinorVersion')->will($this->returnValue('6.2'));
426  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
427  $this->assertSame(1380651865, $instance->_call('getReleaseTimestampOfVersion', '6.2.0alpha3'));
428  }
429 
434  public function ensureVersionExistsInMatrixThrowsExceptionIfMinorVersionDoesNotExist() {
435  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
437  $instance = $this->getAccessibleMock(
438  'TYPO3\\CMS\\Install\\Service\\CoreVersionService',
439  array('getVersionMatrix', 'getMinorVersion'),
440  array(),
441  '',
442  FALSE
443  );
444  $instance->expects($this->once())->method('getMinorVersion')->will($this->returnValue('2.0'));
445  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
446  $instance->_call('ensureVersionExistsInMatrix', '2.0.42');
447  }
448 
453  public function ensureVersionExistsInMatrixThrowsExceptionIfPatchLevelDoesNotExist() {
454  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
456  $instance = $this->getAccessibleMock(
457  'TYPO3\\CMS\\Install\\Service\\CoreVersionService',
458  array('getVersionMatrix', 'getMinorVersion'),
459  array(),
460  '',
461  FALSE
462  );
463  $instance->expects($this->once())->method('getMinorVersion')->will($this->returnValue('6.2'));
464  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
465  $instance->_call('ensureVersionExistsInMatrix', '6.2.5');
466  }
467 }
$registry
Definition: ext_tables.php:46
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)