mirror of
https://github.com/Combodo/iTop.git
synced 2026-09-21 17:10:00 +02:00
N°9979 - Hide "keep current choice" setup button in case of a package upgrade (#1026)
* N°9979 - phstan cleanup * N°9979 - Hide keep current choice setup button in case of a package upgrade * N°9979 - optimize SQL queries
This commit is contained in:
134
tests/php-unit-tests/unitary-tests/setup/WizStepWelcomeTest.php
Normal file
134
tests/php-unit-tests/unitary-tests/setup/WizStepWelcomeTest.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Integration;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use WizardController;
|
||||
use ModuleInstallationRepository;
|
||||
|
||||
class WizStepWelcomeTest extends ItopDataTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
require_once(APPROOT.'/setup/wizardsteps_autoload.php');
|
||||
require_once(APPROOT.'/setup/moduleinstallation/ModuleInstallationRepository.php');
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown(); // TODO: Change the autogenerated stub
|
||||
ModuleInstallationRepository::SetInstance(null);
|
||||
}
|
||||
|
||||
public function testDisplaySetupShortcutButton_NoButtonWhenFreshInstall()
|
||||
{
|
||||
$oWizard = $this->createMock(WizardController::class);
|
||||
$this->GivenSetupMode($oWizard);
|
||||
|
||||
$oWiz = new \WizStepWelcome($oWizard, "");
|
||||
$this->assertEquals(false, $oWiz->DisplaySetupShortcutButton());
|
||||
}
|
||||
|
||||
public function testDisplaySetupShortcutButton_NoButtonWhenNoItopVersionFetched()
|
||||
{
|
||||
$oWizard = $this->createMock(WizardController::class);
|
||||
$this->GivenSetupMode($oWizard, 'upgrade');
|
||||
|
||||
$aApplicationVersion = [
|
||||
'product_name' => ITOP_APPLICATION,
|
||||
];
|
||||
$this->GivenGetApplicationVersion($aApplicationVersion);
|
||||
|
||||
$oWiz = new \WizStepWelcome($oWizard, "");
|
||||
$this->assertEquals(false, $oWiz->DisplaySetupShortcutButton());
|
||||
}
|
||||
|
||||
public function testDisplaySetupShortcutButton_NoButtonWhenNoApplicationVersionFetched()
|
||||
{
|
||||
$oWizard = $this->createMock(WizardController::class);
|
||||
$this->GivenSetupMode($oWizard, 'upgrade');
|
||||
|
||||
$aApplicationVersion = [
|
||||
'product_version' => ITOP_VERSION_FULL,
|
||||
];
|
||||
$this->GivenGetApplicationVersion($aApplicationVersion);
|
||||
|
||||
$oWiz = new \WizStepWelcome($oWizard, "");
|
||||
$this->assertEquals(false, $oWiz->DisplaySetupShortcutButton());
|
||||
}
|
||||
|
||||
public function testDisplaySetupShortcutButton_NoButtonWhenApplicationChangeDuringUpgrade()
|
||||
{
|
||||
$oWizard = $this->createMock(WizardController::class);
|
||||
$this->GivenSetupMode($oWizard, 'upgrade');
|
||||
|
||||
$aApplicationVersion = [
|
||||
'product_version' => ITOP_VERSION_FULL,
|
||||
'product_name' => 'toto',
|
||||
];
|
||||
$this->GivenGetApplicationVersion($aApplicationVersion);
|
||||
|
||||
$oWiz = new \WizStepWelcome($oWizard, "");
|
||||
$this->assertEquals(false, $oWiz->DisplaySetupShortcutButton());
|
||||
}
|
||||
|
||||
public function testDisplaySetupShortcutButton_NoButtonWhenVersionChangeDuringUpgrade()
|
||||
{
|
||||
$oWizard = $this->createMock(WizardController::class);
|
||||
$this->GivenSetupMode($oWizard, 'upgrade');
|
||||
|
||||
$aApplicationVersion = [
|
||||
'product_version' => '6.6.6',
|
||||
'product_name' => ITOP_APPLICATION,
|
||||
];
|
||||
$this->GivenGetApplicationVersion($aApplicationVersion);
|
||||
|
||||
$oWiz = new \WizStepWelcome($oWizard, "");
|
||||
$this->assertEquals(false, $oWiz->DisplaySetupShortcutButton());
|
||||
}
|
||||
|
||||
public function testDisplaySetupShortcutButton_NoButtonWhenMySQLException()
|
||||
{
|
||||
$oWizard = $this->createMock(WizardController::class);
|
||||
$this->GivenSetupMode($oWizard, 'upgrade');
|
||||
$this->GivenGetApplicationVersion(false);
|
||||
|
||||
$oWiz = new \WizStepWelcome($oWizard, "");
|
||||
$this->assertEquals(false, $oWiz->DisplaySetupShortcutButton());
|
||||
}
|
||||
|
||||
public function testDisplaySetupShortcutButton_ButtonDisplayed()
|
||||
{
|
||||
|
||||
$oWizard = $this->createMock(WizardController::class);
|
||||
$this->GivenSetupMode($oWizard, 'upgrade');
|
||||
|
||||
$aApplicationVersion = [
|
||||
'product_version' => ITOP_VERSION_FULL,
|
||||
'product_name' => ITOP_APPLICATION,
|
||||
];
|
||||
$this->GivenGetApplicationVersion($aApplicationVersion);
|
||||
|
||||
$oWiz = new \WizStepWelcome($oWizard, "");
|
||||
$this->assertEquals(true, $oWiz->DisplaySetupShortcutButton());
|
||||
}
|
||||
|
||||
private function GivenSetupMode(WizardController $oWizardMock, $sMode = 'install'): void
|
||||
{
|
||||
$oWizardMock->expects($this->once())
|
||||
->method('GetParameter')
|
||||
->with('mode')
|
||||
->willReturn($sMode);
|
||||
}
|
||||
|
||||
private function GivenGetApplicationVersion($sExpectedReturnedValue): void
|
||||
{
|
||||
$oModuleInstallationRepository = $this->createMock(ModuleInstallationRepository::class);
|
||||
ModuleInstallationRepository::SetInstance($oModuleInstallationRepository);
|
||||
|
||||
$oModuleInstallationRepository->expects($this->once())
|
||||
->method('GetApplicationVersion')
|
||||
->willReturn($sExpectedReturnedValue);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user