[TASK] Migrate extension install upgrade wizards to new API
[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 $this->assertTrue($subject->updateNecessary());
62 }
63
64 /**
65 * @test
66 */
67 public function performUpdateInstallsExtensionUponRequest()
68 {
69 $objectManager = $this->prophesize(ObjectManager::class);
70 GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal());
71
72 $listUtility = $this->prophesize(ListUtility::class);
73 $installUtility = $this->prophesize(InstallUtility::class);
74 $objectManager->get(InstallUtility::class)->willReturn($installUtility->reveal());
75 $objectManager->get(ListUtility::class)->willReturn($listUtility->reveal());
76 $extensionList = ['compatibility7' => ['foo' => 'bar']];
77 $listUtility->getAvailableExtensions()->willReturn($extensionList);
78 $listUtility->getAvailableAndInstalledExtensions($extensionList)->willReturn($extensionList);
79
80 $subject = new Compatibility7ExtractionUpdate();
81 $this->assertTrue($subject->executeUpdate());
82
83 $installUtility->install('compatibility7')->shouldHaveBeenCalled();
84 }
85 }