TYPO3  7.6
CoreVersionServiceTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Install\Service;
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 
18 use TYPO3\CMS\Core\Tests\UnitTestCase;
19 
23 class CoreVersionServiceTest extends UnitTestCase
24 {
28  public function updateVersionMatrixStoresVersionMatrixInRegistry()
29  {
31  $instance = $this->getAccessibleMock(CoreVersionService::class, array('fetchVersionMatrixFromRemote'), array(), '', false);
32  $registry = $this->getMock(Registry::class);
33  $versionArray = array(7 => []);
34  $registry->expects($this->once())->method('set')->with('TYPO3.CMS.Install', 'coreVersionMatrix', $versionArray);
35  $instance->_set('registry', $registry);
36  $instance->expects($this->once())->method('fetchVersionMatrixFromRemote')->will($this->returnValue($versionArray));
37  $instance->updateVersionMatrix();
38  }
39 
43  public function updateVersionMatrixRemovesOldReleasesFromMatrix()
44  {
46  $instance = $this->getAccessibleMock(CoreVersionService::class, array('fetchVersionMatrixFromRemote'), array(), '', false);
47  $registry = $this->getMock(Registry::class);
48  $versionArray = array(
49  '7' => array(),
50  '6.2' => array(),
51  );
52  $registry
53  ->expects($this->once())
54  ->method('set')
55  ->with('TYPO3.CMS.Install', 'coreVersionMatrix', $this->logicalNot($this->arrayHasKey('6.2')));
56  $instance->_set('registry', $registry);
57  $instance->expects($this->once())->method('fetchVersionMatrixFromRemote')->will($this->returnValue($versionArray));
58  $instance->updateVersionMatrix();
59  }
60 
64  public function isInstalledVersionAReleasedVersionReturnsTrueForNonDevelopmentVersion()
65  {
67  $instance = $this->getAccessibleMock(CoreVersionService::class, array('getInstalledVersion'), array(), '', false);
68  $instance->expects($this->once())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
69  $this->assertTrue($instance->isInstalledVersionAReleasedVersion());
70  }
71 
75  public function isInstalledVersionAReleasedVersionReturnsFalseForDevelopmentVersion()
76  {
78  $instance = $this->getAccessibleMock(CoreVersionService::class, array('getInstalledVersion'), array(), '', false);
79  $instance->expects($this->once())->method('getInstalledVersion')->will($this->returnValue('7.4-dev'));
80  $this->assertFalse($instance->isInstalledVersionAReleasedVersion());
81  }
82 
87  public function getTarGzSha1OfVersionThrowsExceptionIfSha1DoesNotExistInMatrix()
88  {
90  $instance = $this->getAccessibleMock(
91  CoreVersionService::class,
92  array('getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'),
93  array(),
94  '',
95  false
96  );
97  $versionMatrix = array(
98  '7' => array(
99  'releases' => array(
100  '7.2.0' => array(),
101  ),
102  ),
103  );
104  $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('7'));
105  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
106  $this->assertTrue($instance->getTarGzSha1OfVersion('7.2.0'));
107  }
108 
112  public function getTarGzSha1OfVersionReturnsSha1OfSpecifiedVersion()
113  {
114  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
116  $instance = $this->getAccessibleMock(
117  CoreVersionService::class,
118  array('getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'),
119  array(),
120  '',
121  false
122  );
123  $instance->expects($this->any())->method('getMajorVersion')->will($this->returnValue('7'));
124  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
125  $this->assertSame('3dc156eed4b99577232f537d798a8691493f8a83', $instance->getTarGzSha1OfVersion('7.2.0'));
126  }
127 
133  public function isYoungerPatchReleaseAvailableReturnsTrueIfYoungerReleaseIsAvailable()
134  {
136  $instance = $this->getAccessibleMock(
137  CoreVersionService::class,
138  array('getVersionMatrix', 'getInstalledVersion'),
139  array(),
140  '',
141  false
142  );
143  $versionMatrix = array(
144  '7' => array(
145  'releases' => array(
146  '7.2.1' => array(
147  'type' => 'security',
148  'date' => '2013-12-01 18:24:25 UTC',
149  ),
150  '7.2.0' => array(
151  'type' => 'regular',
152  'date' => '2013-11-01 18:24:25 UTC',
153  ),
154  ),
155  ),
156  );
157  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
158  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
159  $this->assertTrue($instance->isYoungerPatchReleaseAvailable());
160  }
161 
167  public function isYoungerReleaseAvailableReturnsFalseIfNoYoungerReleaseExists()
168  {
170  $instance = $this->getAccessibleMock(
171  CoreVersionService::class,
172  array('getVersionMatrix', 'getInstalledVersion'),
173  array(),
174  '',
175  false
176  );
177  $versionMatrix = array(
178  '7' => array(
179  'releases' => array(
180  '7.2.0' => array(
181  'type' => 'regular',
182  'date' => '2013-12-01 18:24:25 UTC',
183  ),
184  '7.1.0' => array(
185  'type' => 'regular',
186  'date' => '2013-11-01 18:24:25 UTC',
187  ),
188  ),
189  ),
190  );
191  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
192  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
193  $this->assertFalse($instance->isYoungerPatchReleaseAvailable());
194  }
195 
201  public function isYoungerReleaseAvailableReturnsFalseIfOnlyADevelopmentReleaseIsYounger()
202  {
204  $instance = $this->getAccessibleMock(
205  CoreVersionService::class,
206  array('getVersionMatrix', 'getInstalledVersion'),
207  array(),
208  '',
209  false
210  );
211  $versionMatrix = array(
212  '7' => array(
213  'releases' => array(
214  '7.3.0' => array(
215  'type' => 'development',
216  'date' => '2013-12-01 18:24:25 UTC',
217  ),
218  '7.2.0' => array(
219  'type' => 'regular',
220  'date' => '2013-11-01 18:24:25 UTC',
221  ),
222  ),
223  ),
224  );
225  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
226  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
227  $this->assertFalse($instance->isYoungerPatchReleaseAvailable());
228  }
229 
235  public function isYoungerDevelopmentReleaseAvailableReturnsTrueIfADevelopmentReleaseIsYounger()
236  {
238  $instance = $this->getAccessibleMock(
239  CoreVersionService::class,
240  array('getVersionMatrix', 'getInstalledVersion'),
241  array(),
242  '',
243  false
244  );
245  $versionMatrix = array(
246  '7' => array(
247  'releases' => array(
248  '7.3.0' => array(
249  'type' => 'development',
250  'date' => '2013-12-01 18:24:25 UTC',
251  ),
252  '7.2.0' => array(
253  'type' => 'regular',
254  'date' => '2013-11-01 18:24:25 UTC',
255  ),
256  ),
257  ),
258  );
259  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
260  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
261  $this->assertTrue($instance->isYoungerPatchDevelopmentReleaseAvailable());
262  }
263 
269  public function isUpdateSecurityRelevantReturnsTrueIfAnUpdateIsSecurityRelevant()
270  {
272  $instance = $this->getAccessibleMock(
273  CoreVersionService::class,
274  array('getVersionMatrix', 'getInstalledVersion'),
275  array(),
276  '',
277  false
278  );
279  $versionMatrix = array(
280  '7' => array(
281  'releases' => array(
282  '7.3.0' => array(
283  'type' => 'security',
284  'date' => '2013-12-01 18:24:25 UTC',
285  ),
286  '7.2.0' => array(
287  'type' => 'regular',
288  'date' => '2013-11-01 18:24:25 UTC',
289  ),
290  ),
291  ),
292  );
293  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
294  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
295  $this->assertTrue($instance->isUpdateSecurityRelevant());
296  }
297 
303  public function isUpdateSecurityRelevantReturnsFalseIfUpdateIsNotSecurityRelevant()
304  {
306  $instance = $this->getAccessibleMock(
307  CoreVersionService::class,
308  array('getVersionMatrix', 'getInstalledVersion'),
309  array(),
310  '',
311  false
312  );
313  $versionMatrix = array(
314  '7' => array(
315  'releases' => array(
316  '7.3.0' => array(
317  'type' => 'regular',
318  'date' => '2013-12-01 18:24:25 UTC',
319  ),
320  '7.2.0' => array(
321  'type' => 'regular',
322  'date' => '2013-11-01 18:24:25 UTC',
323  ),
324  ),
325  ),
326  );
327  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
328  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
329  $this->assertFalse($instance->isUpdateSecurityRelevant());
330  }
331 
335  public function getInstalledMajorVersionFetchesInstalledVersionNumber()
336  {
338  $instance = $this->getAccessibleMock(CoreVersionService::class, array('getInstalledVersion'), array(), '', false);
339  $instance->expects($this->once())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
340  $this->assertSame('7', $instance->_call('getInstalledMajorVersion'));
341  }
342 
346  public function getMajorVersionDataProvider()
347  {
348  return array(
349  '7.2' => array(
350  '7.2.0',
351  '7',
352  ),
353  '7.4-dev' => array(
354  '7.4-dev',
355  '7',
356  ),
357  '4.5' => array(
358  '4.5.40',
359  '4',
360  ),
361  );
362  }
363 
371  public function getMajorVersionReturnsCorrectMajorVersion($version, $expectedMajor)
372  {
374  $instance = $this->getAccessibleMock(CoreVersionService::class, array('dummy'), array(), '', false);
375  $this->assertSame($expectedMajor, $instance->_call('getMajorVersion', $version));
376  }
377 
382  public function getVersionMatrixThrowsExceptionIfVersionMatrixIsNotYetSetInRegistry()
383  {
385  $instance = $this->getAccessibleMock(CoreVersionService::class, array('fetchVersionMatrixFromRemote'), array(), '', false);
386  $registry = $this->getMock(Registry::class);
387  $registry->expects($this->once())->method('get')->will($this->returnValue(null));
388  $instance->_set('registry', $registry);
389  $instance->_call('getVersionMatrix');
390  }
391 
395  public function getVersionMatrixReturnsMatrixFromRegistry()
396  {
398  $instance = $this->getAccessibleMock(CoreVersionService::class, array('fetchVersionMatrixFromRemote'), array(), '', false);
399  $registry = $this->getMock(Registry::class);
400  $versionArray = array($this->getUniqueId());
401  $registry->expects($this->once())->method('get')->will($this->returnValue($versionArray));
402  $instance->_set('registry', $registry);
403  $this->assertSame($versionArray, $instance->_call('getVersionMatrix'));
404  }
405 
410  public function getReleaseTimestampOfVersionThrowsExceptionIfReleaseDateIsNotDefined()
411  {
412  $versionMatrix = array(
413  '7' => array(
414  'releases' => array(
415  '7.2.0' => array()
416  ),
417  ),
418  );
420  $instance = $this->getAccessibleMock(
421  CoreVersionService::class,
422  array('getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'),
423  array(),
424  '',
425  false
426  );
427  $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('7'));
428  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
429  $instance->_call('getReleaseTimestampOfVersion', '7.2.0');
430  }
431 
435  public function getReleaseTimestampOfVersionReturnsTimestamp()
436  {
437  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
439  $instance = $this->getAccessibleMock(
440  CoreVersionService::class,
441  array('getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'),
442  array(),
443  '',
444  false
445  );
446  $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('7'));
447  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
448  $this->assertSame(1398968665, $instance->_call('getReleaseTimestampOfVersion', '7.3.1'));
449  }
450 
455  public function ensureVersionExistsInMatrixThrowsExceptionIfMinorVersionDoesNotExist()
456  {
457  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
459  $instance = $this->getAccessibleMock(
460  CoreVersionService::class,
461  array('getVersionMatrix', 'getMajorVersion'),
462  array(),
463  '',
464  false
465  );
466  $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('2'));
467  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
468  $instance->_call('ensureVersionExistsInMatrix', '2.0.42');
469  }
470 
475  public function ensureVersionExistsInMatrixThrowsExceptionIfPatchLevelDoesNotExist()
476  {
477  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
479  $instance = $this->getAccessibleMock(
480  CoreVersionService::class,
481  array('getVersionMatrix', 'getMajorVersion'),
482  array(),
483  '',
484  false
485  );
486  $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('7'));
487  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
488  $instance->_call('ensureVersionExistsInMatrix', '7.2.5');
489  }
490 }