25cc83e1367004a525d79ffab89343a26cda2957
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / Controller / UpgradeControllerTest.php
1 <?php
2 declare(strict_types = 1);
3
4 namespace TYPO3\CMS\Install\Tests\Unit\Controller;
5
6 /*
7 * This file is part of the TYPO3 CMS project.
8 *
9 * It is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, either version 2
11 * of the License, or any later version.
12 *
13 * For the full copyright and license information, please read the
14 * LICENSE.txt file that was distributed with this source code.
15 *
16 * The TYPO3 project - inspiring people to share!
17 */
18
19 use Psr\Http\Message\ServerRequestInterface;
20 use TYPO3\CMS\Fluid\View\StandaloneView;
21 use TYPO3\CMS\Install\Controller\UpgradeController;
22
23 /**
24 * Test case
25 */
26 class UpgradeControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
27 {
28 /**
29 * @return array
30 */
31 public function versionDataProvider(): array
32 {
33 return [
34 ['master', false],
35 ['1.0', false],
36 ['1.10', false],
37 ['2.3.4', false],
38 ['2.3.20', false],
39 ['7.6.x', false],
40 ['10.0', false],
41 ['10.10', false],
42 ['10.10.5', false],
43 ['10.10.husel', true],
44 ['1.2.3.4', true],
45 ['9.8.x.x', true],
46 ['a.b.c', true],
47 ['4.3.x.1', true],
48 ['../../../../../../../etc/passwd', true],
49 ['husel', true],
50 ];
51 }
52
53 /**
54 * @param string $version
55 * @param bool $expectsException
56 * @dataProvider versionDataProvider
57 * @test
58 */
59 public function versionIsAsserted(string $version, bool $expectsException): void
60 {
61 if ($expectsException) {
62 $this->expectException(\InvalidArgumentException::class);
63 $this->expectExceptionCode(1537209128);
64 }
65 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
66 $requestProphecy->getQueryParams()->willReturn([
67 'install' => [
68 'version' => $version,
69 ],
70 ]);
71
72 /** @var UpgradeController|\PHPUnit\Framework\MockObject\MockObject $subject */
73 $subject = $this->getMockBuilder(UpgradeController::class)
74 ->setMethods(['getDocumentationFiles', 'initializeStandaloneView'])
75 ->getMock();
76
77 $subject->expects($this->any())->method('getDocumentationFiles')->willReturn([
78 'normalFiles' => [],
79 'readFiles' => [],
80 'notAffectedFiles' => [],
81 ]);
82 $subject->expects($this->any())
83 ->method('initializeStandaloneView')
84 ->willReturn($this->prophesize(StandaloneView::class)->reveal());
85 $subject->upgradeDocsGetChangelogForVersionAction($requestProphecy->reveal());
86 }
87 }