[BUGFIX] Do not try to download extensions in composer mode
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Tests / Unit / Updates / Compatibility7ExtractionUpdateTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Install\Tests\Unit\Updates;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Core\Registry;
19 use TYPO3\CMS\Core\SingletonInterface;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Extbase\Object\ObjectManager;
22 use TYPO3\CMS\Extensionmanager\Utility\InstallUtility;
23 use TYPO3\CMS\Extensionmanager\Utility\ListUtility;
24 use TYPO3\CMS\Install\Updates\Compatibility7ExtractionUpdate;
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26
27 /**
28 * Class Compatibility7ExtractionUpdateTest
29 */
30 class Compatibility7ExtractionUpdateTest extends UnitTestCase
31 {
32 /**
33 * @var Registry
34 */
35 protected $registry;
36
37 /**
38 * @var SingletonInterface[]
39 */
40 protected $singletonInstances;
41
42 protected function setUp()
43 {
44 $this->singletonInstances = GeneralUtility::getSingletonInstances();
45 $this->registry = $this->prophesize(Registry::class);
46 GeneralUtility::setSingletonInstance(Registry::class, $this->registry->reveal());
47 }
48
49 protected function tearDown()
50 {
51 GeneralUtility::purgeInstances();
52 GeneralUtility::resetSingletonInstances($this->singletonInstances);
53 parent::tearDown();
54 }
55
56 /**
57 * @test
58 */
59 public function checkForUpdateReturnsTrueIfWizardIsNotMarkedAsDoneYet()
60 {
61 $this->registry->get('installUpdate', Compatibility7ExtractionUpdate::class, false)->willReturn(false);
62 $subject = new Compatibility7ExtractionUpdate();
63 $description = '';
64 $this->assertTrue($subject->checkForUpdate($description));
65 }
66
67 /**
68 * @test
69 */
70 public function checkForUpdateReturnsFalseIfWizardIsMarkedAsDone()
71 {
72 $this->registry->get('installUpdate', Compatibility7ExtractionUpdate::class, false)->willReturn(true);
73 $subject = new Compatibility7ExtractionUpdate();
74 $description = '';
75 $this->assertFalse($subject->checkForUpdate($description));
76 }
77
78 /**
79 * @test
80 */
81 public function performUpdateReturnsFalseIfNoUserInputWasFound()
82 {
83 $_GET['install'] = [];
84 $subject = new Compatibility7ExtractionUpdate();
85 $databaseQueries = [];
86 $customMessage = '';
87 $this->assertFalse($subject->performUpdate($databaseQueries, $customMessage));
88 }
89
90 /**
91 * @test
92 */
93 public function performUpdateReturnsTrueIfUserDeclinesInstallAndMarksWizardDone()
94 {
95 $_GET['install']['values']['compatibility7Extension']['install'] = 0;
96 $subject = new Compatibility7ExtractionUpdate();
97 $databaseQueries = [];
98 $customMessage = '';
99 $this->assertTrue($subject->performUpdate($databaseQueries, $customMessage));
100 $this->registry->set('installUpdate', Compatibility7ExtractionUpdate::class, 1)->shouldHaveBeenCalled();
101 }
102
103 /**
104 * @test
105 */
106 public function performUpdateInstallsExtensionUponRequestAndMarksWizardDone()
107 {
108 $_GET['install']['values']['compatibility7Extension']['install'] = 1;
109
110 $objectManager = $this->prophesize(ObjectManager::class);
111 GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal());
112
113 $listUtility = $this->prophesize(ListUtility::class);
114 $installUtility = $this->prophesize(InstallUtility::class);
115 $objectManager->get(InstallUtility::class)->willReturn($installUtility->reveal());
116 $objectManager->get(ListUtility::class)->willReturn($listUtility->reveal());
117 $extensionList = ['compatibility7' => ['foo' => 'bar']];
118 $listUtility->getAvailableExtensions()->willReturn($extensionList);
119 $listUtility->getAvailableAndInstalledExtensions($extensionList)->willReturn($extensionList);
120 $installUtility->install('compatibility7')->shouldBeCalled();
121
122 $subject = new Compatibility7ExtractionUpdate();
123 $databaseQueries = [];
124 $customMessage = '';
125 $this->assertTrue($subject->performUpdate($databaseQueries, $customMessage));
126 $this->registry->set('installUpdate', Compatibility7ExtractionUpdate::class, 1)->shouldHaveBeenCalled();
127 }
128 }