[BUGFIX] EXT:reports does not recognize TYPO3 CMS 7.3.0 as released
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / Service / CoreVersionServiceTest.php
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
17 use TYPO3\CMS\Core\Registry;
18 use TYPO3\CMS\Core\Tests\UnitTestCase;
19
20 /**
21 * Test case
22 */
23 class CoreVersionServiceTest extends UnitTestCase {
24
25 /**
26 * @test
27 */
28 public function updateVersionMatrixStoresVersionMatrixInRegistry() {
29 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
30 $instance = $this->getAccessibleMock(CoreVersionService::class, array('fetchVersionMatrixFromRemote'), array(), '', FALSE);
31 $registry = $this->getMock(Registry::class);
32 $versionArray = array(7 => []);
33 $registry->expects($this->once())->method('set')->with('TYPO3.CMS.Install', 'coreVersionMatrix', $versionArray);
34 $instance->_set('registry', $registry);
35 $instance->expects($this->once())->method('fetchVersionMatrixFromRemote')->will($this->returnValue($versionArray));
36 $instance->updateVersionMatrix();
37 }
38
39 /**
40 * @test
41 */
42 public function updateVersionMatrixRemovesOldReleasesFromMatrix() {
43 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
44 $instance = $this->getAccessibleMock(CoreVersionService::class, array('fetchVersionMatrixFromRemote'), array(), '', FALSE);
45 $registry = $this->getMock(Registry::class);
46 $versionArray = array(
47 '7' => array(),
48 '6.2' => array(),
49 );
50 $registry
51 ->expects($this->once())
52 ->method('set')
53 ->with('TYPO3.CMS.Install', 'coreVersionMatrix', $this->logicalNot($this->arrayHasKey('6.2')));
54 $instance->_set('registry', $registry);
55 $instance->expects($this->once())->method('fetchVersionMatrixFromRemote')->will($this->returnValue($versionArray));
56 $instance->updateVersionMatrix();
57 }
58
59 /**
60 * @test
61 */
62 public function isInstalledVersionAReleasedVersionReturnsTrueForNonDevelopmentVersion() {
63 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
64 $instance = $this->getAccessibleMock(CoreVersionService::class, array('getInstalledVersion'), array(), '', FALSE);
65 $instance->expects($this->once())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
66 $this->assertTrue($instance->isInstalledVersionAReleasedVersion());
67 }
68
69 /**
70 * @test
71 */
72 public function isInstalledVersionAReleasedVersionReturnsFalseForDevelopmentVersion() {
73 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
74 $instance = $this->getAccessibleMock(CoreVersionService::class, array('getInstalledVersion'), array(), '', FALSE);
75 $instance->expects($this->once())->method('getInstalledVersion')->will($this->returnValue('7.4-dev'));
76 $this->assertFalse($instance->isInstalledVersionAReleasedVersion());
77 }
78
79 /**
80 * @test
81 * @expectedException \TYPO3\CMS\Install\Service\Exception\CoreVersionServiceException
82 */
83 public function getTarGzSha1OfVersionThrowsExceptionIfSha1DoesNotExistInMatrix() {
84 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
85 $instance = $this->getAccessibleMock(
86 CoreVersionService::class,
87 array('getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'),
88 array(),
89 '',
90 FALSE
91 );
92 $versionMatrix = array(
93 '7' => array(
94 'releases' => array(
95 '7.2.0' => array(),
96 ),
97 ),
98 );
99 $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('7'));
100 $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
101 $this->assertTrue($instance->getTarGzSha1OfVersion('7.2.0'));
102 }
103
104 /**
105 * @test
106 */
107 public function getTarGzSha1OfVersionReturnsSha1OfSpecifiedVersion() {
108 $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
109 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
110 $instance = $this->getAccessibleMock(
111 CoreVersionService::class,
112 array('getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'),
113 array(),
114 '',
115 FALSE
116 );
117 $instance->expects($this->any())->method('getMajorVersion')->will($this->returnValue('7'));
118 $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
119 $this->assertSame('3dc156eed4b99577232f537d798a8691493f8a83', $instance->getTarGzSha1OfVersion('7.2.0'));
120 }
121
122 /**
123 * Whitebox test of API method: This tests multiple methods, only 'current version' and 'version matrix' are mocked.
124 *
125 * @test
126 */
127 public function isYoungerPatchReleaseAvailableReturnsTrueIfYoungerReleaseIsAvailable() {
128 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
129 $instance = $this->getAccessibleMock(
130 CoreVersionService::class,
131 array('getVersionMatrix', 'getInstalledVersion'),
132 array(),
133 '',
134 FALSE
135 );
136 $versionMatrix = array(
137 '7' => array(
138 'releases' => array(
139 '7.2.1' => array(
140 'type' => 'security',
141 'date' => '2013-12-01 18:24:25 UTC',
142 ),
143 '7.2.0' => array(
144 'type' => 'regular',
145 'date' => '2013-11-01 18:24:25 UTC',
146 ),
147 ),
148 ),
149 );
150 $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
151 $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
152 $this->assertTrue($instance->isYoungerPatchReleaseAvailable());
153 }
154
155 /**
156 * Whitebox test of API method: This tests multiple methods, only 'current version' and 'version matrix' are mocked.
157 *
158 * @test
159 */
160 public function isYoungerReleaseAvailableReturnsFalseIfNoYoungerReleaseExists() {
161 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
162 $instance = $this->getAccessibleMock(
163 CoreVersionService::class,
164 array('getVersionMatrix', 'getInstalledVersion'),
165 array(),
166 '',
167 FALSE
168 );
169 $versionMatrix = array(
170 '7' => array(
171 'releases' => array(
172 '7.2.0' => array(
173 'type' => 'regular',
174 'date' => '2013-12-01 18:24:25 UTC',
175 ),
176 '7.1.0' => array(
177 'type' => 'regular',
178 'date' => '2013-11-01 18:24:25 UTC',
179 ),
180 ),
181 ),
182 );
183 $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
184 $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
185 $this->assertFalse($instance->isYoungerPatchReleaseAvailable());
186 }
187
188 /**
189 * Whitebox test of API method: This tests multiple methods, only 'current version' and 'version matrix' are mocked.
190 *
191 * @test
192 */
193 public function isYoungerReleaseAvailableReturnsFalseIfOnlyADevelopmentReleaseIsYounger() {
194 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
195 $instance = $this->getAccessibleMock(
196 CoreVersionService::class,
197 array('getVersionMatrix', 'getInstalledVersion'),
198 array(),
199 '',
200 FALSE
201 );
202 $versionMatrix = array(
203 '7' => array(
204 'releases' => array(
205 '7.3.0' => array(
206 'type' => 'development',
207 'date' => '2013-12-01 18:24:25 UTC',
208 ),
209 '7.2.0' => array(
210 'type' => 'regular',
211 'date' => '2013-11-01 18:24:25 UTC',
212 ),
213 ),
214 ),
215 );
216 $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
217 $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
218 $this->assertFalse($instance->isYoungerPatchReleaseAvailable());
219 }
220
221 /**
222 * Whitebox test of API method: This tests multiple methods, only 'current version' and 'version matrix' are mocked.
223 *
224 * @test
225 */
226 public function isYoungerDevelopmentReleaseAvailableReturnsTrueIfADevelopmentReleaseIsYounger() {
227 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
228 $instance = $this->getAccessibleMock(
229 CoreVersionService::class,
230 array('getVersionMatrix', 'getInstalledVersion'),
231 array(),
232 '',
233 FALSE
234 );
235 $versionMatrix = array(
236 '7' => array(
237 'releases' => array(
238 '7.3.0' => array(
239 'type' => 'development',
240 'date' => '2013-12-01 18:24:25 UTC',
241 ),
242 '7.2.0' => array(
243 'type' => 'regular',
244 'date' => '2013-11-01 18:24:25 UTC',
245 ),
246 ),
247 ),
248 );
249 $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
250 $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
251 $this->assertTrue($instance->isYoungerPatchDevelopmentReleaseAvailable());
252 }
253
254 /**
255 * Whitebox test of API method: This tests multiple methods, only 'current version' and 'version matrix' are mocked.
256 *
257 * @test
258 */
259 public function isUpdateSecurityRelevantReturnsTrueIfAnUpdateIsSecurityRelevant() {
260 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
261 $instance = $this->getAccessibleMock(
262 CoreVersionService::class,
263 array('getVersionMatrix', 'getInstalledVersion'),
264 array(),
265 '',
266 FALSE
267 );
268 $versionMatrix = array(
269 '7' => array(
270 'releases' => array(
271 '7.3.0' => array(
272 'type' => 'security',
273 'date' => '2013-12-01 18:24:25 UTC',
274 ),
275 '7.2.0' => array(
276 'type' => 'regular',
277 'date' => '2013-11-01 18:24:25 UTC',
278 ),
279 ),
280 ),
281 );
282 $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
283 $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
284 $this->assertTrue($instance->isUpdateSecurityRelevant());
285 }
286
287 /**
288 * Whitebox test of API method: This tests multiple methods, only 'current version' and 'version matrix' are mocked.
289 *
290 * @test
291 */
292 public function isUpdateSecurityRelevantReturnsFalseIfUpdateIsNotSecurityRelevant() {
293 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
294 $instance = $this->getAccessibleMock(
295 CoreVersionService::class,
296 array('getVersionMatrix', 'getInstalledVersion'),
297 array(),
298 '',
299 FALSE
300 );
301 $versionMatrix = array(
302 '7' => array(
303 'releases' => array(
304 '7.3.0' => array(
305 'type' => 'regular',
306 'date' => '2013-12-01 18:24:25 UTC',
307 ),
308 '7.2.0' => array(
309 'type' => 'regular',
310 'date' => '2013-11-01 18:24:25 UTC',
311 ),
312 ),
313 ),
314 );
315 $instance->expects($this->any())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
316 $instance->expects($this->any())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
317 $this->assertFalse($instance->isUpdateSecurityRelevant());
318 }
319
320 /**
321 * @test
322 */
323 public function getInstalledMajorVersionFetchesInstalledVersionNumber() {
324 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
325 $instance = $this->getAccessibleMock(CoreVersionService::class, array('getInstalledVersion'), array(), '', FALSE);
326 $instance->expects($this->once())->method('getInstalledVersion')->will($this->returnValue('7.2.0'));
327 $this->assertSame('7', $instance->_call('getInstalledMajorVersion'));
328 }
329
330 /**
331 * Data provider
332 */
333 public function getMajorVersionDataProvider() {
334 return array(
335 '7.2' => array(
336 '7.2.0',
337 '7',
338 ),
339 '7.4-dev' => array(
340 '7.4-dev',
341 '7',
342 ),
343 '4.5' => array(
344 '4.5.40',
345 '4',
346 ),
347 );
348 }
349
350 /**
351 * @test
352 * @dataProvider getMajorVersionDataProvider
353 * @param string $version
354 * @param string $expectedMajor
355 * @throws \InvalidArgumentException
356 */
357 public function getMajorVersionReturnsCorrectMajorVersion($version, $expectedMajor) {
358 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
359 $instance = $this->getAccessibleMock(CoreVersionService::class, array('dummy'), array(), '', FALSE);
360 $this->assertSame($expectedMajor, $instance->_call('getMajorVersion', $version));
361 }
362
363 /**
364 * @test
365 * @expectedException \TYPO3\CMS\Install\Service\Exception\CoreVersionServiceException
366 */
367 public function getVersionMatrixThrowsExceptionIfVersionMatrixIsNotYetSetInRegistry() {
368 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
369 $instance = $this->getAccessibleMock(CoreVersionService::class, array('fetchVersionMatrixFromRemote'), array(), '', FALSE);
370 $registry = $this->getMock(Registry::class);
371 $registry->expects($this->once())->method('get')->will($this->returnValue(NULL));
372 $instance->_set('registry', $registry);
373 $instance->_call('getVersionMatrix');
374 }
375
376 /**
377 * @test
378 */
379 public function getVersionMatrixReturnsMatrixFromRegistry() {
380 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
381 $instance = $this->getAccessibleMock(CoreVersionService::class, array('fetchVersionMatrixFromRemote'), array(), '', FALSE);
382 $registry = $this->getMock(Registry::class);
383 $versionArray = array($this->getUniqueId());
384 $registry->expects($this->once())->method('get')->will($this->returnValue($versionArray));
385 $instance->_set('registry', $registry);
386 $this->assertSame($versionArray, $instance->_call('getVersionMatrix'));
387 }
388
389 /**
390 * @test
391 * @expectedException \TYPO3\CMS\Install\Service\Exception\CoreVersionServiceException
392 */
393 public function getReleaseTimestampOfVersionThrowsExceptionIfReleaseDateIsNotDefined() {
394 $versionMatrix = array(
395 '7' => array(
396 'releases' => array(
397 '7.2.0' => array()
398 ),
399 ),
400 );
401 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
402 $instance = $this->getAccessibleMock(
403 CoreVersionService::class,
404 array('getVersionMatrix', 'getMajorVersion', 'ensureVersionExistsInMatrix'),
405 array(),
406 '',
407 FALSE
408 );
409 $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('7'));
410 $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue($versionMatrix));
411 $instance->_call('getReleaseTimestampOfVersion', '7.2.0');
412 }
413
414 /**
415 * @test
416 */
417 public function getReleaseTimestampOfVersionReturnsTimestamp() {
418 $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
419 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
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(require($versionMatrixFixtureFile)));
429 $this->assertSame(1398968665, $instance->_call('getReleaseTimestampOfVersion', '7.3.1'));
430 }
431
432 /**
433 * @test
434 * @expectedException \TYPO3\CMS\Install\Service\Exception\CoreVersionServiceException
435 */
436 public function ensureVersionExistsInMatrixThrowsExceptionIfMinorVersionDoesNotExist() {
437 $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
438 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
439 $instance = $this->getAccessibleMock(
440 CoreVersionService::class,
441 array('getVersionMatrix', 'getMajorVersion'),
442 array(),
443 '',
444 FALSE
445 );
446 $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('2'));
447 $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
448 $instance->_call('ensureVersionExistsInMatrix', '2.0.42');
449 }
450
451 /**
452 * @test
453 * @expectedException \TYPO3\CMS\Install\Service\Exception\CoreVersionServiceException
454 */
455 public function ensureVersionExistsInMatrixThrowsExceptionIfPatchLevelDoesNotExist() {
456 $versionMatrixFixtureFile = __DIR__ . '/Fixtures/VersionMatrixFixture.php';
457 /** @var $instance CoreVersionService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
458 $instance = $this->getAccessibleMock(
459 CoreVersionService::class,
460 array('getVersionMatrix', 'getMajorVersion'),
461 array(),
462 '',
463 FALSE
464 );
465 $instance->expects($this->once())->method('getMajorVersion')->will($this->returnValue('7'));
466 $instance->expects($this->once())->method('getVersionMatrix')->will($this->returnValue(require($versionMatrixFixtureFile)));
467 $instance->_call('ensureVersionExistsInMatrix', '7.2.5');
468 }
469
470 }