TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
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 
20 
25 {
29  public function updateVersionMatrixStoresVersionMatrixInRegistry()
30  {
32  $instance = $this->getAccessibleMock(CoreVersionService::class, ['fetchVersionMatrixFromRemote'], [], '', false);
33  $registry = $this->createMock(Registry::class);
34  $versionArray = [8 => []];
35  $registry->expects($this->once())->method('set')->with('TYPO3.CMS.Install', 'coreVersionMatrix', $versionArray);
36  $instance->_set('registry', $registry);
37  $instance->expects($this->once())->method('fetchVersionMatrixFromRemote')->will($this->returnValue($versionArray));
38  $instance->updateVersionMatrix();
39  }
40 
44  public function updateVersionMatrixRemovesOldReleasesFromMatrix()
45  {
47  $instance = $this->getAccessibleMock(CoreVersionService::class, ['fetchVersionMatrixFromRemote'], [], '', false);
48  $registry = $this->createMock(Registry::class);
49  $versionArray = [
50  '7' => [],
51  '6.2' => [],
52  ];
53  $registry
54  ->expects($this->once())
55  ->method('set')
56  ->with('TYPO3.CMS.Install', 'coreVersionMatrix', $this->logicalNot($this->arrayHasKey('6.2')));
57  $instance->_set('registry', $registry);
58  $instance->expects($this->once())->method('fetchVersionMatrixFromRemote')->will($this->returnValue($versionArray));
59  $instance->updateVersionMatrix();
60  }
61 
65  public function isInstalledVersionAReleasedVersionReturnsTrueForNonDevelopmentVersion()
66  {
68  $instance = $this->getAccessibleMock(CoreVersionService::class, ['getInstalledVersion'], [], '', false);
69  $instance->expects($this->once())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
70  $this->assertTrue($instance->isInstalledVersionAReleasedVersion());
71  }
72 
76  public function isInstalledVersionAReleasedVersionReturnsFalseForDevelopmentVersion()
77  {
79  $instance = $this->getAccessibleMock(CoreVersionService::class, ['getInstalledVersion'], [], '', false);
80  $instance->expects($this->once())->method('getInstalledVersion')->will($this->returnValue('7.4-dev'));
81  $this->assertFalse($instance->isInstalledVersionAReleasedVersion());
82  }
83 
87  public function getTarGzSha1OfVersionThrowsExceptionIfSha1DoesNotExistInMatrix()
88  {
89  $this->expectException(CoreVersionServiceException::class);
90  $this->expectExceptionCode(1381263173);
92  $instance = $this->getAccessibleMock(
93  CoreVersionService::class,
94  ['getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'],
95  [],
96  '',
97  false
98  );
99  $versionMatrix = [
100  '7' => [
101  'releases' => [
102  '7.2.0' => [],
103  ],
104  ],
105  ];
106  $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('7'));
107  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
108  $this->assertTrue($instance->getTarGzSha1OfVersion('7.2.0'));
109  }
110 
114  public function getTarGzSha1OfVersionReturnsSha1OfSpecifiedVersion()
115  {
116  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
118  $instance = $this->getAccessibleMock(
119  CoreVersionService::class,
120  ['getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'],
121  [],
122  '',
123  false
124  );
125  $instance->expects($this->any())->method('getMajorVersion')->will($this->returnValue('7'));
126  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
127  $this->assertSame('3dc156eed4b99577232f537d798a8691493f8a83', $instance->getTarGzSha1OfVersion('7.2.0'));
128  }
129 
135  public function isYoungerPatchReleaseAvailableReturnsTrueIfYoungerReleaseIsAvailable()
136  {
138  $instance = $this->getAccessibleMock(
139  CoreVersionService::class,
140  ['getVersionMatrix', 'getInstalledVersion'],
141  [],
142  '',
143  false
144  );
145  $versionMatrix = [
146  '7' => [
147  'releases' => [
148  '7.2.1' => [
149  'type' => 'security',
150  'date' => '2013-12-01 18:24:25 UTC',
151  ],
152  '7.2.0' => [
153  'type' => 'regular',
154  'date' => '2013-11-01 18:24:25 UTC',
155  ],
156  ],
157  ],
158  ];
159  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
160  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
161  $this->assertTrue($instance->isYoungerPatchReleaseAvailable());
162  }
163 
169  public function isYoungerReleaseAvailableReturnsFalseIfNoYoungerReleaseExists()
170  {
172  $instance = $this->getAccessibleMock(
173  CoreVersionService::class,
174  ['getVersionMatrix', 'getInstalledVersion'],
175  [],
176  '',
177  false
178  );
179  $versionMatrix = [
180  '7' => [
181  'releases' => [
182  '7.2.0' => [
183  'type' => 'regular',
184  'date' => '2013-12-01 18:24:25 UTC',
185  ],
186  '7.1.0' => [
187  'type' => 'regular',
188  'date' => '2013-11-01 18:24:25 UTC',
189  ],
190  ],
191  ],
192  ];
193  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
194  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
195  $this->assertFalse($instance->isYoungerPatchReleaseAvailable());
196  }
197 
203  public function isYoungerReleaseAvailableReturnsFalseIfOnlyADevelopmentReleaseIsYounger()
204  {
206  $instance = $this->getAccessibleMock(
207  CoreVersionService::class,
208  ['getVersionMatrix', 'getInstalledVersion'],
209  [],
210  '',
211  false
212  );
213  $versionMatrix = [
214  '7' => [
215  'releases' => [
216  '7.3.0' => [
217  'type' => 'development',
218  'date' => '2013-12-01 18:24:25 UTC',
219  ],
220  '7.2.0' => [
221  'type' => 'regular',
222  'date' => '2013-11-01 18:24:25 UTC',
223  ],
224  ],
225  ],
226  ];
227  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
228  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
229  $this->assertFalse($instance->isYoungerPatchReleaseAvailable());
230  }
231 
237  public function isYoungerDevelopmentReleaseAvailableReturnsTrueIfADevelopmentReleaseIsYounger()
238  {
240  $instance = $this->getAccessibleMock(
241  CoreVersionService::class,
242  ['getVersionMatrix', 'getInstalledVersion'],
243  [],
244  '',
245  false
246  );
247  $versionMatrix = [
248  '7' => [
249  'releases' => [
250  '7.3.0' => [
251  'type' => 'development',
252  'date' => '2013-12-01 18:24:25 UTC',
253  ],
254  '7.2.0' => [
255  'type' => 'regular',
256  'date' => '2013-11-01 18:24:25 UTC',
257  ],
258  ],
259  ],
260  ];
261  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
262  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
263  $this->assertTrue($instance->isYoungerPatchDevelopmentReleaseAvailable());
264  }
265 
271  public function isUpdateSecurityRelevantReturnsTrueIfAnUpdateIsSecurityRelevant()
272  {
274  $instance = $this->getAccessibleMock(
275  CoreVersionService::class,
276  ['getVersionMatrix', 'getInstalledVersion'],
277  [],
278  '',
279  false
280  );
281  $versionMatrix = [
282  '7' => [
283  'releases' => [
284  '7.3.0' => [
285  'type' => 'security',
286  'date' => '2013-12-01 18:24:25 UTC',
287  ],
288  '7.2.0' => [
289  'type' => 'regular',
290  'date' => '2013-11-01 18:24:25 UTC',
291  ],
292  ],
293  ],
294  ];
295  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
296  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
297  $this->assertTrue($instance->isUpdateSecurityRelevant());
298  }
299 
305  public function isUpdateSecurityRelevantReturnsFalseIfUpdateIsNotSecurityRelevant()
306  {
308  $instance = $this->getAccessibleMock(
309  CoreVersionService::class,
310  ['getVersionMatrix', 'getInstalledVersion'],
311  [],
312  '',
313  false
314  );
315  $versionMatrix = [
316  '7' => [
317  'releases' => [
318  '7.3.0' => [
319  'type' => 'regular',
320  'date' => '2013-12-01 18:24:25 UTC',
321  ],
322  '7.2.0' => [
323  'type' => 'regular',
324  'date' => '2013-11-01 18:24:25 UTC',
325  ],
326  ],
327  ],
328  ];
329  $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
330  $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
331  $this->assertFalse($instance->isUpdateSecurityRelevant());
332  }
333 
337  public function getInstalledMajorVersionFetchesInstalledVersionNumber()
338  {
340  $instance = $this->getAccessibleMock(CoreVersionService::class, ['getInstalledVersion'], [], '', false);
341  $instance->expects($this->once())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
342  $this->assertSame('7', $instance->_call('getInstalledMajorVersion'));
343  }
344 
348  public function getMajorVersionDataProvider()
349  {
350  return [
351  '7.2' => [
352  '7.2.0',
353  '7',
354  ],
355  '7.4-dev' => [
356  '7.4-dev',
357  '7',
358  ],
359  '4.5' => [
360  '4.5.40',
361  '4',
362  ],
363  ];
364  }
365 
373  public function getMajorVersionReturnsCorrectMajorVersion($version, $expectedMajor)
374  {
376  $instance = $this->getAccessibleMock(CoreVersionService::class, ['dummy'], [], '', false);
377  $this->assertSame($expectedMajor, $instance->_call('getMajorVersion', $version));
378  }
379 
383  public function getVersionMatrixThrowsExceptionIfVersionMatrixIsNotYetSetInRegistry()
384  {
385  $this->expectException(CoreVersionServiceException::class);
386  $this->expectExceptionCode(1380898792);
388  $instance = $this->getAccessibleMock(CoreVersionService::class, ['fetchVersionMatrixFromRemote'], [], '', false);
389  $registry = $this->createMock(Registry::class);
390  $registry->expects($this->once())->method('get')->will($this->returnValue(null));
391  $instance->_set('registry', $registry);
392  $instance->_call('getVersionMatrix');
393  }
394 
398  public function getVersionMatrixReturnsMatrixFromRegistry()
399  {
401  $instance = $this->getAccessibleMock(CoreVersionService::class, ['fetchVersionMatrixFromRemote'], [], '', false);
402  $registry = $this->createMock(Registry::class);
403  $versionArray = [$this->getUniqueId()];
404  $registry->expects($this->once())->method('get')->will($this->returnValue($versionArray));
405  $instance->_set('registry', $registry);
406  $this->assertSame($versionArray, $instance->_call('getVersionMatrix'));
407  }
408 
412  public function getReleaseTimestampOfVersionThrowsExceptionIfReleaseDateIsNotDefined()
413  {
414  $this->expectException(CoreVersionServiceException::class);
415  $this->expectExceptionCode(1380905853);
416  $versionMatrix = [
417  '7' => [
418  'releases' => [
419  '7.2.0' => []
420  ],
421  ],
422  ];
424  $instance = $this->getAccessibleMock(
425  CoreVersionService::class,
426  ['getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'],
427  [],
428  '',
429  false
430  );
431  $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('7'));
432  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
433  $instance->_call('getReleaseTimestampOfVersion', '7.2.0');
434  }
435 
439  public function getReleaseTimestampOfVersionReturnsTimestamp()
440  {
441  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
443  $instance = $this->getAccessibleMock(
444  CoreVersionService::class,
445  ['getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'],
446  [],
447  '',
448  false
449  );
450  $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('7'));
451  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
452  $this->assertSame(1398968665, $instance->_call('getReleaseTimestampOfVersion', '7.3.1'));
453  }
454 
458  public function ensureVersionExistsInMatrixThrowsExceptionIfMinorVersionDoesNotExist()
459  {
460  $this->expectException(CoreVersionServiceException::class);
461  $this->expectExceptionCode(1380905851);
462  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
464  $instance = $this->getAccessibleMock(
465  CoreVersionService::class,
466  ['getVersionMatrix', 'getMajorVersion'],
467  [],
468  '',
469  false
470  );
471  $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('2'));
472  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
473  $instance->_call('ensureVersionExistsInMatrix', '2.0.42');
474  }
475 
479  public function ensureVersionExistsInMatrixThrowsExceptionIfPatchLevelDoesNotExist()
480  {
481  $this->expectException(CoreVersionServiceException::class);
482  $this->expectExceptionCode(1380905852);
483  $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
485  $instance = $this->getAccessibleMock(
486  CoreVersionService::class,
487  ['getVersionMatrix', 'getMajorVersion'],
488  [],
489  '',
490  false
491  );
492  $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('7'));
493  $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
494  $instance->_call('ensureVersionExistsInMatrix', '7.2.5');
495  }
496 }
getAccessibleMock($originalClassName, $methods=[], array $arguments=[], $mockClassName= '', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)