TYPO3 CMS  TYPO3_8-7
CoreVersionServiceTest.php
Go to the documentation of this file.
1 <?php
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 
19 
23 class CoreVersionServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
24 {
28  public function updateVersionMatrixStoresVersionMatrixInRegistry()
29  {
31  $instance = $this->getAccessibleMock(CoreVersionService::class, ['fetchVersionMatrixFromRemote'], [], '', false);
32  $registry = $this->createMock(Registry::class);
33  $versionArray = [8 => []];
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, ['fetchVersionMatrixFromRemote'], [], '', false);
47  $registry = $this->createMock(Registry::class);
48  $versionArray = [
49  '7' => [],
50  '6.2' => [],
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, ['getInstalledVersion'], [], '', 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, ['getInstalledVersion'], [], '', false);
79  $instance->expects($this->once())->method('getInstalledVersion')->will($this->returnValue('7.4-dev'));
80  $this->assertFalse($instance->isInstalledVersionAReleasedVersion());
81  }
82 
86  public function getTarGzSha1OfVersionThrowsExceptionIfSha1DoesNotExistInMatrix()
87  {
88  $this->expectException(CoreVersionServiceException::class);
89  $this->expectExceptionCode(1381263173);
91  $instance = $this->getAccessibleMock(
92  CoreVersionService::class,
93  ['getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'],
94  [],
95  '',
96  false
97  );
98  $versionMatrix = [
99  '7' => [
100  'releases' => [
101  '7.2.0' => [],
102  ],
103  ],
104  ];
105  $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('7'));
106  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
107  $this->assertTrue($instance->getTarGzSha1OfVersion('7.2.0'));
108  }
109 
113  public function getTarGzSha1OfVersionReturnsSha1OfSpecifiedVersion()
114  {
115  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
117  $instance = $this->getAccessibleMock(
118  CoreVersionService::class,
119  ['getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'],
120  [],
121  '',
122  false
123  );
124  $instance->expects($this->any())->method('getMajorVersion')->will($this->returnValue('7'));
125  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
126  $this->assertSame('3dc156eed4b99577232f537d798a8691493f8a83', $instance->getTarGzSha1OfVersion('7.2.0'));
127  }
128 
134  public function isYoungerPatchReleaseAvailableReturnsTrueIfYoungerReleaseIsAvailable()
135  {
137  $instance = $this->getAccessibleMock(
138  CoreVersionService::class,
139  ['getVersionMatrix', 'getInstalledVersion'],
140  [],
141  '',
142  false
143  );
144  $versionMatrix = [
145  '7' => [
146  'releases' => [
147  '7.2.1' => [
148  'type' => 'security',
149  'date' => '2013-12-01 18:24:25 UTC',
150  ],
151  '7.2.0' => [
152  'type' => 'regular',
153  'date' => '2013-11-01 18:24:25 UTC',
154  ],
155  ],
156  ],
157  ];
158  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
159  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
160  $this->assertTrue($instance->isYoungerPatchReleaseAvailable());
161  }
162 
168  public function isYoungerReleaseAvailableReturnsFalseIfNoYoungerReleaseExists()
169  {
171  $instance = $this->getAccessibleMock(
172  CoreVersionService::class,
173  ['getVersionMatrix', 'getInstalledVersion'],
174  [],
175  '',
176  false
177  );
178  $versionMatrix = [
179  '7' => [
180  'releases' => [
181  '7.2.0' => [
182  'type' => 'regular',
183  'date' => '2013-12-01 18:24:25 UTC',
184  ],
185  '7.1.0' => [
186  'type' => 'regular',
187  'date' => '2013-11-01 18:24:25 UTC',
188  ],
189  ],
190  ],
191  ];
192  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
193  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
194  $this->assertFalse($instance->isYoungerPatchReleaseAvailable());
195  }
196 
202  public function isYoungerReleaseAvailableReturnsFalseIfOnlyADevelopmentReleaseIsYounger()
203  {
205  $instance = $this->getAccessibleMock(
206  CoreVersionService::class,
207  ['getVersionMatrix', 'getInstalledVersion'],
208  [],
209  '',
210  false
211  );
212  $versionMatrix = [
213  '7' => [
214  'releases' => [
215  '7.3.0' => [
216  'type' => 'development',
217  'date' => '2013-12-01 18:24:25 UTC',
218  ],
219  '7.2.0' => [
220  'type' => 'regular',
221  'date' => '2013-11-01 18:24:25 UTC',
222  ],
223  ],
224  ],
225  ];
226  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
227  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
228  $this->assertFalse($instance->isYoungerPatchReleaseAvailable());
229  }
230 
236  public function isYoungerDevelopmentReleaseAvailableReturnsTrueIfADevelopmentReleaseIsYounger()
237  {
239  $instance = $this->getAccessibleMock(
240  CoreVersionService::class,
241  ['getVersionMatrix', 'getInstalledVersion'],
242  [],
243  '',
244  false
245  );
246  $versionMatrix = [
247  '7' => [
248  'releases' => [
249  '7.3.0' => [
250  'type' => 'development',
251  'date' => '2013-12-01 18:24:25 UTC',
252  ],
253  '7.2.0' => [
254  'type' => 'regular',
255  'date' => '2013-11-01 18:24:25 UTC',
256  ],
257  ],
258  ],
259  ];
260  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
261  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
262  $this->assertTrue($instance->isYoungerPatchDevelopmentReleaseAvailable());
263  }
264 
270  public function isUpdateSecurityRelevantReturnsTrueIfAnUpdateIsSecurityRelevant()
271  {
273  $instance = $this->getAccessibleMock(
274  CoreVersionService::class,
275  ['getVersionMatrix', 'getInstalledVersion'],
276  [],
277  '',
278  false
279  );
280  $versionMatrix = [
281  '7' => [
282  'releases' => [
283  '7.3.0' => [
284  'type' => 'security',
285  'date' => '2013-12-01 18:24:25 UTC',
286  ],
287  '7.2.0' => [
288  'type' => 'regular',
289  'date' => '2013-11-01 18:24:25 UTC',
290  ],
291  ],
292  ],
293  ];
294  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
295  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
296  $this->assertTrue($instance->isUpdateSecurityRelevant());
297  }
298 
304  public function isUpdateSecurityRelevantReturnsFalseIfUpdateIsNotSecurityRelevant()
305  {
307  $instance = $this->getAccessibleMock(
308  CoreVersionService::class,
309  ['getVersionMatrix', 'getInstalledVersion'],
310  [],
311  '',
312  false
313  );
314  $versionMatrix = [
315  '7' => [
316  'releases' => [
317  '7.3.0' => [
318  'type' => 'regular',
319  'date' => '2013-12-01 18:24:25 UTC',
320  ],
321  '7.2.0' => [
322  'type' => 'regular',
323  'date' => '2013-11-01 18:24:25 UTC',
324  ],
325  ],
326  ],
327  ];
328  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
329  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
330  $this->assertFalse($instance->isUpdateSecurityRelevant());
331  }
332 
336  public function getInstalledMajorVersionFetchesInstalledVersionNumber()
337  {
339  $instance = $this->getAccessibleMock(CoreVersionService::class, ['getInstalledVersion'], [], '', false);
340  $instance->expects($this->once())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
341  $this->assertSame('7', $instance->_call('getInstalledMajorVersion'));
342  }
343 
347  public function getMajorVersionDataProvider()
348  {
349  return [
350  '7.2' => [
351  '7.2.0',
352  '7',
353  ],
354  '7.4-dev' => [
355  '7.4-dev',
356  '7',
357  ],
358  '4.5' => [
359  '4.5.40',
360  '4',
361  ],
362  ];
363  }
364 
372  public function getMajorVersionReturnsCorrectMajorVersion($version, $expectedMajor)
373  {
375  $instance = $this->getAccessibleMock(CoreVersionService::class, ['dummy'], [], '', false);
376  $this->assertSame($expectedMajor, $instance->_call('getMajorVersion', $version));
377  }
378 
382  public function getVersionMatrixThrowsExceptionIfVersionMatrixIsNotYetSetInRegistry()
383  {
384  $this->expectException(CoreVersionServiceException::class);
385  $this->expectExceptionCode(1380898792);
387  $instance = $this->getAccessibleMock(CoreVersionService::class, ['fetchVersionMatrixFromRemote'], [], '', false);
388  $registry = $this->createMock(Registry::class);
389  $registry->expects($this->once())->method('get')->will($this->returnValue(null));
390  $instance->_set('registry', $registry);
391  $instance->_call('getVersionMatrix');
392  }
393 
397  public function getVersionMatrixReturnsMatrixFromRegistry()
398  {
400  $instance = $this->getAccessibleMock(CoreVersionService::class, ['fetchVersionMatrixFromRemote'], [], '', false);
401  $registry = $this->createMock(Registry::class);
402  $versionArray = [$this->getUniqueId()];
403  $registry->expects($this->once())->method('get')->will($this->returnValue($versionArray));
404  $instance->_set('registry', $registry);
405  $this->assertSame($versionArray, $instance->_call('getVersionMatrix'));
406  }
407 
411  public function getReleaseTimestampOfVersionThrowsExceptionIfReleaseDateIsNotDefined()
412  {
413  $this->expectException(CoreVersionServiceException::class);
414  $this->expectExceptionCode(1380905853);
415  $versionMatrix = [
416  '7' => [
417  'releases' => [
418  '7.2.0' => []
419  ],
420  ],
421  ];
423  $instance = $this->getAccessibleMock(
424  CoreVersionService::class,
425  ['getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'],
426  [],
427  '',
428  false
429  );
430  $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('7'));
431  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
432  $instance->_call('getReleaseTimestampOfVersion', '7.2.0');
433  }
434 
438  public function getReleaseTimestampOfVersionReturnsTimestamp()
439  {
440  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
442  $instance = $this->getAccessibleMock(
443  CoreVersionService::class,
444  ['getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'],
445  [],
446  '',
447  false
448  );
449  $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('7'));
450  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
451  $this->assertSame(1398968665, $instance->_call('getReleaseTimestampOfVersion', '7.3.1'));
452  }
453 
457  public function ensureVersionExistsInMatrixThrowsExceptionIfMinorVersionDoesNotExist()
458  {
459  $this->expectException(CoreVersionServiceException::class);
460  $this->expectExceptionCode(1380905851);
461  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
463  $instance = $this->getAccessibleMock(
464  CoreVersionService::class,
465  ['getVersionMatrix', 'getMajorVersion'],
466  [],
467  '',
468  false
469  );
470  $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('2'));
471  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
472  $instance->_call('ensureVersionExistsInMatrix', '2.0.42');
473  }
474 
478  public function ensureVersionExistsInMatrixThrowsExceptionIfPatchLevelDoesNotExist()
479  {
480  $this->expectException(CoreVersionServiceException::class);
481  $this->expectExceptionCode(1380905852);
482  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
484  $instance = $this->getAccessibleMock(
485  CoreVersionService::class,
486  ['getVersionMatrix', 'getMajorVersion'],
487  [],
488  '',
489  false
490  );
491  $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('7'));
492  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
493  $instance->_call('ensureVersionExistsInMatrix', '7.2.5');
494  }
495 }