[TASK] Deprecate $GLOBALS['TYPO3_LOADED_EXT']
[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\Core\Package\PackageManager;
21 use TYPO3\CMS\Fluid\View\StandaloneView;
22 use TYPO3\CMS\Install\Controller\UpgradeController;
23
24 /**
25 * Test case
26 */
27 class UpgradeControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
28 {
29 /**
30 * @return array
31 */
32 public function versionDataProvider(): array
33 {
34 return [
35 ['master', false],
36 ['1.0', false],
37 ['1.10', false],
38 ['2.3.4', false],
39 ['2.3.20', false],
40 ['7.6.x', false],
41 ['10.0', false],
42 ['10.10', false],
43 ['10.10.5', false],
44 ['10.10.husel', true],
45 ['1.2.3.4', true],
46 ['9.8.x.x', true],
47 ['a.b.c', true],
48 ['4.3.x.1', true],
49 ['../../../../../../../etc/passwd', true],
50 ['husel', true],
51 ];
52 }
53
54 /**
55 * @param string $version
56 * @param bool $expectsException
57 * @dataProvider versionDataProvider
58 * @test
59 */
60 public function versionIsAsserted(string $version, bool $expectsException): void
61 {
62 if ($expectsException) {
63 $this->expectException(\InvalidArgumentException::class);
64 $this->expectExceptionCode(1537209128);
65 }
66 $requestProphecy = $this->prophesize(ServerRequestInterface::class);
67 $requestProphecy->getQueryParams()->willReturn([
68 'install' => [
69 'version' => $version,
70 ],
71 ]);
72
73 $packageManagerMock = $this->getMockBuilder(PackageManager::class)
74 ->disableOriginalConstructor()
75 ->getMock();
76 /** @var UpgradeController|\PHPUnit\Framework\MockObject\MockObject $subject */
77 $subject = $this->getMockBuilder(UpgradeController::class)
78 ->setConstructorArgs([$packageManagerMock])
79 ->setMethods(['getDocumentationFiles', 'initializeStandaloneView'])
80 ->getMock();
81
82 $subject->expects($this->any())->method('getDocumentationFiles')->willReturn([
83 'normalFiles' => [],
84 'readFiles' => [],
85 'notAffectedFiles' => [],
86 ]);
87 $subject->expects($this->any())
88 ->method('initializeStandaloneView')
89 ->willReturn($this->prophesize(StandaloneView::class)->reveal());
90 $subject->upgradeDocsGetChangelogForVersionAction($requestProphecy->reveal());
91 }
92 }