mirror of
https://github.com/Combodo/iTop.git
synced 2026-06-04 23:22:18 +02:00
N°9597 - Switch environment to a build environment must not be available
This commit is contained in:
@@ -70,7 +70,7 @@ $oKPI->ComputeAndReport("Session Start");
|
||||
|
||||
$sSwitchEnv = utils::ReadParam('switch_env', null);
|
||||
$bAllowCache = true;
|
||||
$sEnv = StartupService::SetItopEnvironment($sSwitchEnv, $bAllowCache);
|
||||
$sEnv = (new StartupService())->SetItopEnvironment($sSwitchEnv, $bAllowCache);
|
||||
$sConfigFile = APPCONF.$sEnv.'/'.ITOP_CONFIG_FILE;
|
||||
try {
|
||||
MetaModel::Startup($sConfigFile, false /* $bModelOnly */, $bAllowCache, false /* $bTraceSourceFiles */, $sEnv);
|
||||
|
||||
@@ -10,14 +10,14 @@ class StartupService
|
||||
{
|
||||
/**
|
||||
* @param string|null $sSwitchEnv
|
||||
* @param bool $bAllowCache
|
||||
* @param bool $bAllowCache - whether to allow cache or not (will be set to false if the environment is switched)
|
||||
*
|
||||
* @return string
|
||||
* @throws CoreException
|
||||
*/
|
||||
public static function SetItopEnvironment(?string $sSwitchEnv, bool &$bAllowCache): string
|
||||
public function SetItopEnvironment(?string $sSwitchEnv, bool &$bAllowCache): string
|
||||
{
|
||||
if (static::IsBuildEnvironment($sSwitchEnv)) {
|
||||
if ($this->IsBuildEnvironment($sSwitchEnv)) {
|
||||
$oException = new CoreException("Switching to environment '$sSwitchEnv' is not allowed since it is a build environment");
|
||||
IssueLog::Exception("Trying to switch to environment '$sSwitchEnv' is not allowed since it is a build environment", $oException);
|
||||
throw $oException;
|
||||
@@ -51,7 +51,7 @@ class StartupService
|
||||
return $sEnv;
|
||||
}
|
||||
|
||||
public static function IsBuildEnvironment(?string $sEnv): bool
|
||||
public function IsBuildEnvironment(?string $sEnv): bool
|
||||
{
|
||||
return $sEnv != null && str_ends_with($sEnv, '-build');
|
||||
}
|
||||
|
||||
@@ -8,16 +8,19 @@ use CoreException;
|
||||
|
||||
class StartupServiceTest extends ItopTestCase
|
||||
{
|
||||
private StartupService $oStartupService;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->RequireOnceItopFile('application/utils.inc.php');
|
||||
$this->oStartupService = new StartupService();
|
||||
}
|
||||
|
||||
public function testSetItopEnvironmentUsesDefaultWhenEnvironmentIsNull(): void
|
||||
{
|
||||
$bAllowCache = true;
|
||||
$sEnv = StartupService::SetItopEnvironment(null, $bAllowCache);
|
||||
$sEnv = $this->oStartupService->SetItopEnvironment(null, $bAllowCache);
|
||||
$this->assertEquals(ITOP_DEFAULT_ENV, $sEnv);
|
||||
$this->assertTrue($bAllowCache);
|
||||
}
|
||||
@@ -25,7 +28,7 @@ class StartupServiceTest extends ItopTestCase
|
||||
public function testSetItopEnvironmentWithValidEnvironment(): void
|
||||
{
|
||||
$bAllowCache = true;
|
||||
$sEnv = StartupService::SetItopEnvironment('test', $bAllowCache);
|
||||
$sEnv = $this->oStartupService->SetItopEnvironment('test', $bAllowCache);
|
||||
$this->assertEquals('test', $sEnv);
|
||||
$this->assertFalse($bAllowCache);
|
||||
}
|
||||
@@ -35,13 +38,13 @@ class StartupServiceTest extends ItopTestCase
|
||||
$bAllowCache = true;
|
||||
$this->expectException(CoreException::class);
|
||||
$this->expectExceptionMessage("Switching to environment 'test-build' is not allowed since it is a build environment");
|
||||
StartupService::SetItopEnvironment('test-build', $bAllowCache);
|
||||
$this->oStartupService->SetItopEnvironment('test-build', $bAllowCache);
|
||||
}
|
||||
|
||||
public function testIsBuildEnvironment()
|
||||
{
|
||||
$this->assertTrue(StartupService::IsBuildEnvironment('test-build'));
|
||||
$this->assertFalse(StartupService::IsBuildEnvironment('test'));
|
||||
$this->assertFalse(StartupService::IsBuildEnvironment(null));
|
||||
$this->assertTrue($this->oStartupService->IsBuildEnvironment('test-build'));
|
||||
$this->assertFalse($this->oStartupService->IsBuildEnvironment('test'));
|
||||
$this->assertFalse($this->oStartupService->IsBuildEnvironment(null));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user