[TASK] Add UnitTest for Compatibility7ExtractionUpdate 71/55771/5
authorAnja Leichsenring <anja.leichsenring@typo3.com>
Sat, 17 Feb 2018 12:22:48 +0000 (13:22 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 17 Feb 2018 19:00:37 +0000 (20:00 +0100)
Change-Id: I2450313e4fb470a62f9bb4e371e0200c720bb4b5
Resolves: #83950
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/55771
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/install/Tests/Unit/Updates/Compatibility7ExtractionUpdateTest.php [new file with mode: 0644]

diff --git a/typo3/sysext/install/Tests/Unit/Updates/Compatibility7ExtractionUpdateTest.php b/typo3/sysext/install/Tests/Unit/Updates/Compatibility7ExtractionUpdateTest.php
new file mode 100644 (file)
index 0000000..d61447b
--- /dev/null
@@ -0,0 +1,128 @@
+<?php
+declare(strict_types = 1);
+namespace TYPO3\CMS\Install\Tests\Unit\Updates;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Registry;
+use TYPO3\CMS\Core\SingletonInterface;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Object\ObjectManager;
+use TYPO3\CMS\Extensionmanager\Utility\InstallUtility;
+use TYPO3\CMS\Extensionmanager\Utility\ListUtility;
+use TYPO3\CMS\Install\Updates\Compatibility7ExtractionUpdate;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
+/**
+ * Class Compatibility7ExtractionUpdateTest
+ */
+class Compatibility7ExtractionUpdateTest extends UnitTestCase
+{
+    /**
+     * @var Registry
+     */
+    protected $registry;
+
+    /**
+     * @var SingletonInterface[]
+     */
+    protected $singletonInstances;
+
+    protected function setUp()
+    {
+        $this->singletonInstances = GeneralUtility::getSingletonInstances();
+        $this->registry = $this->prophesize(Registry::class);
+        GeneralUtility::setSingletonInstance(Registry::class, $this->registry->reveal());
+    }
+
+    protected function tearDown()
+    {
+        GeneralUtility::purgeInstances();
+        GeneralUtility::resetSingletonInstances($this->singletonInstances);
+        parent::tearDown();
+    }
+
+    /**
+     * @test
+     */
+    public function checkForUpdateReturnsTrueIfWizardIsNotMarkedAsDoneYet()
+    {
+        $this->registry->get('installUpdate', Compatibility7ExtractionUpdate::class, false)->willReturn(false);
+        $subject = new Compatibility7ExtractionUpdate();
+        $description = '';
+        $this->assertTrue($subject->checkForUpdate($description));
+    }
+
+    /**
+     * @test
+     */
+    public function checkForUpdateReturnsFalseIfWizardIsMarkedAsDone()
+    {
+        $this->registry->get('installUpdate', Compatibility7ExtractionUpdate::class, false)->willReturn(true);
+        $subject = new Compatibility7ExtractionUpdate();
+        $description = '';
+        $this->assertFalse($subject->checkForUpdate($description));
+    }
+
+    /**
+     * @test
+     */
+    public function performUpdateReturnsFalseIfNoUserInputWasFound()
+    {
+        $_GET['install'] = [];
+        $subject = new Compatibility7ExtractionUpdate();
+        $databaseQueries = [];
+        $customMessage = '';
+        $this->assertFalse($subject->performUpdate($databaseQueries, $customMessage));
+    }
+
+    /**
+     * @test
+     */
+    public function performUpdateReturnsTrueIfUserDeclinesInstallAndMarksWizardDone()
+    {
+        $_GET['install']['values']['compatibility7Extension']['install'] = 0;
+        $subject = new Compatibility7ExtractionUpdate();
+        $databaseQueries = [];
+        $customMessage = '';
+        $this->assertTrue($subject->performUpdate($databaseQueries, $customMessage));
+        $this->registry->set('installUpdate', Compatibility7ExtractionUpdate::class, 1)->shouldHaveBeenCalled();
+    }
+
+    /**
+     * @test
+     */
+    public function performUpdateInstallsExtensionUponRequestAndMarksWizardDone()
+    {
+        $_GET['install']['values']['compatibility7Extension']['install'] = 1;
+
+        $objectManager = $this->prophesize(ObjectManager::class);
+        GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManager->reveal());
+
+        $listUtility = $this->prophesize(ListUtility::class);
+        $installUtility = $this->prophesize(InstallUtility::class);
+        $objectManager->get(InstallUtility::class)->willReturn($installUtility->reveal());
+        $objectManager->get(ListUtility::class)->willReturn($listUtility->reveal());
+        $extensionList = ['compatibility7' => []];
+        $listUtility->getAvailableExtensions()->willReturn($extensionList);
+        $listUtility->getAvailableAndInstalledExtensions($extensionList)->willReturn($extensionList);
+        $installUtility->install('compatibility7')->shouldBeCalled();
+
+        $subject = new Compatibility7ExtractionUpdate();
+        $databaseQueries = [];
+        $customMessage = '';
+        $this->assertTrue($subject->performUpdate($databaseQueries, $customMessage));
+        $this->registry->set('installUpdate', Compatibility7ExtractionUpdate::class, 1)->shouldHaveBeenCalled();
+    }
+}