TYPO3 CMS  TYPO3_7-6
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 
24 {
28  public function updateVersionMatrixStoresVersionMatrixInRegistry()
29  {
31  $instance = $this->getAccessibleMock(CoreVersionService::class, ['fetchVersionMatrixFromRemote'], [], '', false);
32  $registry = $this->getMock(Registry::class);
33  $versionArray = [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, ['fetchVersionMatrixFromRemote'], [], '', false);
47  $registry = $this->getMock(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 
87  public function getTarGzSha1OfVersionThrowsExceptionIfSha1DoesNotExistInMatrix()
88  {
90  $instance = $this->getAccessibleMock(
91  CoreVersionService::class,
92  ['getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'],
93  [],
94  '',
95  false
96  );
97  $versionMatrix = [
98  '7' => [
99  'releases' => [
100  '7.2.0' => [],
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  ['getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'],
119  [],
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  ['getVersionMatrix', 'getInstalledVersion'],
139  [],
140  '',
141  false
142  );
143  $versionMatrix = [
144  '7' => [
145  'releases' => [
146  '7.2.1' => [
147  'type' => 'security',
148  'date' => '2013-12-01 18:24:25 UTC',
149  ],
150  '7.2.0' => [
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  ['getVersionMatrix', 'getInstalledVersion'],
173  [],
174  '',
175  false
176  );
177  $versionMatrix = [
178  '7' => [
179  'releases' => [
180  '7.2.0' => [
181  'type' => 'regular',
182  'date' => '2013-12-01 18:24:25 UTC',
183  ],
184  '7.1.0' => [
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  ['getVersionMatrix', 'getInstalledVersion'],
207  [],
208  '',
209  false
210  );
211  $versionMatrix = [
212  '7' => [
213  'releases' => [
214  '7.3.0' => [
215  'type' => 'development',
216  'date' => '2013-12-01 18:24:25 UTC',
217  ],
218  '7.2.0' => [
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  ['getVersionMatrix', 'getInstalledVersion'],
241  [],
242  '',
243  false
244  );
245  $versionMatrix = [
246  '7' => [
247  'releases' => [
248  '7.3.0' => [
249  'type' => 'development',
250  'date' => '2013-12-01 18:24:25 UTC',
251  ],
252  '7.2.0' => [
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  ['getVersionMatrix', 'getInstalledVersion'],
275  [],
276  '',
277  false
278  );
279  $versionMatrix = [
280  '7' => [
281  'releases' => [
282  '7.3.0' => [
283  'type' => 'security',
284  'date' => '2013-12-01 18:24:25 UTC',
285  ],
286  '7.2.0' => [
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  ['getVersionMatrix', 'getInstalledVersion'],
309  [],
310  '',
311  false
312  );
313  $versionMatrix = [
314  '7' => [
315  'releases' => [
316  '7.3.0' => [
317  'type' => 'regular',
318  'date' => '2013-12-01 18:24:25 UTC',
319  ],
320  '7.2.0' => [
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, ['getInstalledVersion'], [], '', 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 [
349  '7.2' => [
350  '7.2.0',
351  '7',
352  ],
353  '7.4-dev' => [
354  '7.4-dev',
355  '7',
356  ],
357  '4.5' => [
358  '4.5.40',
359  '4',
360  ],
361  ];
362  }
363 
371  public function getMajorVersionReturnsCorrectMajorVersion($version, $expectedMajor)
372  {
374  $instance = $this->getAccessibleMock(CoreVersionService::class, ['dummy'], [], '', false);
375  $this->assertSame($expectedMajor, $instance->_call('getMajorVersion', $version));
376  }
377 
382  public function getVersionMatrixThrowsExceptionIfVersionMatrixIsNotYetSetInRegistry()
383  {
385  $instance = $this->getAccessibleMock(CoreVersionService::class, ['fetchVersionMatrixFromRemote'], [], '', 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, ['fetchVersionMatrixFromRemote'], [], '', false);
399  $registry = $this->getMock(Registry::class);
400  $versionArray = [$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 = [
413  '7' => [
414  'releases' => [
415  '7.2.0' => []
416  ],
417  ],
418  ];
420  $instance = $this->getAccessibleMock(
421  CoreVersionService::class,
422  ['getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'],
423  [],
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  ['getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'],
442  [],
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  ['getVersionMatrix', 'getMajorVersion'],
462  [],
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  ['getVersionMatrix', 'getMajorVersion'],
482  [],
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 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)