Skip to content

Commit

Permalink
[TASK] Add UnitTest for Compatibility7ExtractionUpdate
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Anja Leichsenring authored and lolli42 committed Feb 17, 2018
1 parent 3b15704 commit f0e1ca7
Showing 1 changed file with 128 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit f0e1ca7

Please sign in to comment.