[TASK] Properly reset unit test singletons
[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\Utility\GeneralUtility;
20 use TYPO3\CMS\Extbase\Object\ObjectManager;
21 use TYPO3\CMS\Extensionmanager\Utility\InstallUtility;
22 use TYPO3\CMS\Extensionmanager\Utility\ListUtility;
23 use TYPO3\CMS\Install\Updates\Compatibility7ExtractionUpdate;
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25
26 /**
27 * Test case
28 */
29 class Compatibility7ExtractionUpdateTest extends UnitTestCase
30 {
31 /**
32 * @var Registry
33 */
34 protected $registry;
35
36 /**
37 * Set up
38 */
39 protected function setUp()
40 {
41 $this->registry = $this->prophesize(Registry::class);
42 GeneralUtility::setSingletonInstance(Registry::class, $this->registry->reveal());
43 }
44
45 /**
46 * Tear down
47 */
48 protected function tearDown()
49 {
50 GeneralUtility::purgeInstances();
51 parent::tearDown();
52 }
53
54 /**
55 * @test
56 */
57 public function checkForUpdateReturnsTrueIfWizardIsNotMarkedAsDoneYet()
58 {
59 $this->registry->get('installUpdate', Compatibility7ExtractionUpdate::class, false)->willReturn(false);
60 $subject = new Compatibility7ExtractionUpdate();
61 $description = '';
62 $this->assertTrue($subject->checkForUpdate($description));
63 }
64
65 /**
66 * @test
67 */
68 public function checkForUpdateReturnsFalseIfWizardIsMarkedAsDone()
69 {
70 $this->registry->get('installUpdate', Compatibility7ExtractionUpdate::class, false)->willReturn(true);
71 $subject = new Compatibility7ExtractionUpdate();
72 $description = '';
73 $this->assertFalse($subject->checkForUpdate($description));
74 }
75
76 /**
77 * @test
78 */
79 public function performUpdateReturnsFalseIfNoUserInputWasFound()
80 {
81 $_GET['install'] = [];
82 $subject = new Compatibility7ExtractionUpdate();
83 $databaseQueries = [];
84 $customMessage = '';
85 $this->assertFalse($subject->performUpdate($databaseQueries, $customMessage));
86 }
87
88 /**
89 * @test
90 */
91 public function performUpdateReturnsTrueIfUserDeclinesInstallAndMarksWizardDone()
92 {
93 $_GET['install']['values']['compatibility7Extension']['install'] = 0;
94 $subject = new Compatibility7ExtractionUpdate();
95 $databaseQueries = [];
96 $customMessage = '';
97 $this->assertTrue($subject->performUpdate($databaseQueries, $customMessage));
98 $this->registry->set('installUpdate', Compatibility7ExtractionUpdate::class, 1)->shouldHaveBeenCalled();
99 }
100
101 /**
102 * @test
103 */
104 public function performUpdateInstallsExtensionUponRequestAndMarksWizardDone()
105 {
106 $_GET['install']['values']['compatibility7Extension']['install'] = 1;
107
108 $objectManager = $this->prophesize(ObjectManager::class);
109 GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal());
110
111 $listUtility = $this->prophesize(ListUtility::class);
112 $installUtility = $this->prophesize(InstallUtility::class);
113 $objectManager->get(InstallUtility::class)->willReturn($installUtility->reveal());
114 $objectManager->get(ListUtility::class)->willReturn($listUtility->reveal());
115 $extensionList = ['compatibility7' => ['foo' => 'bar']];
116 $listUtility->getAvailableExtensions()->willReturn($extensionList);
117 $listUtility->getAvailableAndInstalledExtensions($extensionList)->willReturn($extensionList);
118 $installUtility->install('compatibility7')->shouldBeCalled();
119
120 $subject = new Compatibility7ExtractionUpdate();
121 $databaseQueries = [];
122 $customMessage = '';
123 $this->assertTrue($subject->performUpdate($databaseQueries, $customMessage));
124 $this->registry->set('installUpdate', Compatibility7ExtractionUpdate::class, 1)->shouldHaveBeenCalled();
125 }
126 }