N°9144 - no audit in unattended + tests

This commit is contained in:
odain
2026-05-06 10:46:57 +02:00
parent 73ebf663d6
commit 4d2722654a
5 changed files with 80 additions and 10 deletions

View File

@@ -1331,6 +1331,9 @@ class RunTimeEnvironment
{
$oSetupAudit = new SetupAudit(ITOP_DEFAULT_ENV, $this->sBuildEnv);
//Make sure the MetaModel is started before analysing for issues
$sConfFile = utils::GetConfigFilePath(ITOP_DEFAULT_ENV);
MetaModel::Startup($sConfFile, false, false); // Start on production environment
$oSetupAudit->RunDataAudit(true);
$iCount = $oSetupAudit->GetDataToCleanupCount();

View File

@@ -94,6 +94,10 @@ class DataAuditSequencer extends StepSequencer
protected function IsDataAuditRequired(): bool
{
if (! array_key_exists('setup-audit', $this->oParams->Get('optional_steps', []))) {
return false;
}
if ('install' === $this->oParams->Get('mode')) {
return false;
}

View File

@@ -66,6 +66,7 @@ abstract class AbstractWizStepInstall extends WizardStep
'log-parameters' => true,
'migrate-before' => true,
'migrate-after' => true,
'setup-audit' => true,
// 'backup' => see below
],
'source_dir' => str_replace(APPROOT, '', $sSourceDir),

View File

@@ -62,6 +62,7 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
'optional_steps' => [
'migrate-before' => true,
],
'bCallEnterMaintenanceMode' => true,
],
];
}
@@ -69,12 +70,12 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
/**
* @dataProvider FirstStepProvider
*/
public function testFirstStep($sNextStep, $sNextLabel, $iPercent, $aOptionalSteps)
public function testFirstStep($sNextStep, $sNextLabel, $iPercent, $aOptionalSteps, bool $bCallEnterMaintenanceMode = false, bool $bCallExitMaintenanceMode = false)
{
$aAdditionalParams = [
'optional_steps' => $aOptionalSteps,
];
$this->GivenApplicationInstallSequencer($aAdditionalParams);
$this->GivenApplicationInstallSequencer($aAdditionalParams, $bCallEnterMaintenanceMode, $bCallExitMaintenanceMode);
$aRes = $this->oSequencer->ExecuteStep();
$aExpected = [
@@ -160,7 +161,7 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
'migrate-before' => true,
],
];
$this->GivenApplicationInstallSequencer($aAdditionalParams);
$this->GivenApplicationInstallSequencer($aAdditionalParams, bCallEnterMaintenanceMode: true);
$this->oRunTimeEnvironment->expects($this->once())->method('MigrateDataBeforeUpdateStructure')
->with('install', $this->oConfig);
@@ -320,7 +321,7 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
public function testCommit()
{
$this->GivenApplicationInstallSequencer();
$this->GivenApplicationInstallSequencer(bCallExitMaintenanceMode: true);
$this->oRunTimeEnvironment->expects($this->once())->method('Commit');
$this->oRunTimeEnvironment->expects($this->once())->method('ExitReadOnlyMode');
@@ -484,13 +485,18 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
$this->assertEquals(['', 100], $this->oSequencer->GetStepAfterWithPercent('commit'));
}
private function GivenRunTimeEnvironment(bool $bStepComputationOnly = false): void
private function GivenRunTimeEnvironment(bool $bStepComputationOnly = false, bool $bCallEnterMaintenanceMode = false, bool $bCallExitMaintenanceMode = false): void
{
$this->oRunTimeEnvironment = $this->createMock(RunTimeEnvironment::class);
if (! $bStepComputationOnly) {
$this->oRunTimeEnvironment->expects($this->once())->method('EnterReadOnlyMode')
->with($this->oConfig);
}
$this->oRunTimeEnvironment->expects($this->exactly($bCallEnterMaintenanceMode ? 1 : 0))->method('EnterMaintenanceMode')
->with($this->oConfig);
$this->oRunTimeEnvironment->expects($this->exactly($bCallExitMaintenanceMode ? 1 : 0))->method('ExitMaintenanceMode');
}
private function GivenConfig(): void
@@ -498,10 +504,10 @@ class ApplicationInstallerSequencerTest extends ItopTestCase
$this->oConfig = $this->createMock(Config::class);
}
private function GivenApplicationInstallSequencer(array $aAdditionalParams = [], bool $bStepComputationOnly = false): void
private function GivenApplicationInstallSequencer(array $aAdditionalParams = [], bool $bStepComputationOnly = false, bool $bCallEnterMaintenanceMode = false, bool $bCallExitMaintenanceMode = false): void
{
$this->GivenConfig();
$this->GivenRunTimeEnvironment($bStepComputationOnly);
$this->GivenRunTimeEnvironment($bStepComputationOnly, $bCallEnterMaintenanceMode, $bCallExitMaintenanceMode);
$this->oSequencer = new ApplicationInstallSequencer($this->GivenParams($aAdditionalParams), $this->oRunTimeEnvironment);
$this->SetNonPublicProperty($this->oSequencer, 'oTestConfig', $this->oConfig);
}

View File

@@ -8,6 +8,8 @@ use PHPParameters;
class DataAuditSequencerTest extends ItopTestCase
{
private $oConfig;
protected function setUp(): void
{
static::LoadRequiredItopFiles();
@@ -85,6 +87,7 @@ class DataAuditSequencerTest extends ItopTestCase
$aAdditionalParams = [
'mode' => 'update',
'optional_steps' => ['setup-audit' => true ],
];
$oSequencer = new DataAuditSequencer($this->GivenParams($aAdditionalParams), $oRunTimeEnvironment);
@@ -99,6 +102,30 @@ class DataAuditSequencerTest extends ItopTestCase
$this->assertEquals($aExpected, $aRes);
}
public function testCompileWithAuditDisabledViaOptionalSteps()
{
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
$oRunTimeEnvironment->expects($this->never())->method('GetApplicationVersion');
$oRunTimeEnvironment->expects($this->once())->method('DoCompile');
$oRunTimeEnvironment->expects($this->never())->method('GetFinalEnv')
->willReturn('production');
$aAdditionalParams = [
'mode' => 'update',
];
$oSequencer = new DataAuditSequencer($this->GivenParams($aAdditionalParams), $oRunTimeEnvironment);
$aRes = $oSequencer->ExecuteStep('compile');
$aExpected = [
'status' => 1,
'message' => '',
'next-step' => 'complete',
'next-step-label' => 'Check Completed',
'percentage-completed' => 100,
];
$this->assertEquals($aExpected, $aRes);
}
public function testCompileNoAuditInFreshInstall()
{
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
@@ -127,6 +154,7 @@ class DataAuditSequencerTest extends ItopTestCase
$aAdditionalParams = [
'mode' => 'update',
'optional_steps' => ['setup-audit' => true ],
];
$oSequencer = new DataAuditSequencer($this->GivenParams($aAdditionalParams), $oRunTimeEnvironment);
@@ -171,6 +199,7 @@ class DataAuditSequencerTest extends ItopTestCase
$aAdditionalParams = [
'mode' => 'update',
'optional_steps' => ['setup-audit' => true ],
];
$oSequencer = new DataAuditSequencer($this->GivenParams($aAdditionalParams), $oRunTimeEnvironment);
@@ -196,6 +225,7 @@ class DataAuditSequencerTest extends ItopTestCase
$aAdditionalParams = [
'mode' => 'update',
'optional_steps' => ['setup-audit' => true ],
];
$oSequencer = new DataAuditSequencer($this->GivenParams($aAdditionalParams), $oRunTimeEnvironment);
$aRes = $oSequencer->ExecuteStep('setup-audit');
@@ -272,7 +302,11 @@ class DataAuditSequencerTest extends ItopTestCase
->willReturn(['product_version' => ITOP_VERSION_FULL."_alpha"]);
$oRunTimeEnvironment->expects($this->never())->method("GetFinalEnv");
$oSequencer = new DataAuditSequencer($this->GivenParams(['mode' => 'upgrade']), $oRunTimeEnvironment);
$aAdditionalParams = [
'mode' => 'upgrade',
'optional_steps' => ['setup-audit' => true ],
];
$oSequencer = new DataAuditSequencer($this->GivenParams($aAdditionalParams), $oRunTimeEnvironment);
self::assertFalse($this->InvokeNonPublicMethod(DataAuditSequencer::class, "IsDataAuditRequired", $oSequencer));
}
@@ -283,7 +317,25 @@ class DataAuditSequencerTest extends ItopTestCase
->willReturn(['product_version' => ITOP_VERSION_FULL]);
$oRunTimeEnvironment->expects($this->once())->method("GetFinalEnv")->willReturn("production-gabuzomeu");
$oSequencer = new DataAuditSequencer($this->GivenParams(['mode' => 'upgrade']), $oRunTimeEnvironment);
$aAdditionalParams = [
'mode' => 'upgrade',
'optional_steps' => ['setup-audit' => true ],
];
$oSequencer = new DataAuditSequencer($this->GivenParams($aAdditionalParams), $oRunTimeEnvironment);
self::assertFalse($this->InvokeNonPublicMethod(DataAuditSequencer::class, "IsDataAuditRequired", $oSequencer));
}
public function testIsDataAuditRequired_NoAuditTriggeredBecauseDisabled()
{
$oRunTimeEnvironment = $this->createMock(\RunTimeEnvironment::class);
$oRunTimeEnvironment->expects($this->once())->method('GetApplicationVersion')
->willReturn(['product_version' => ITOP_VERSION_FULL]);
$oRunTimeEnvironment->expects($this->once())->method("GetFinalEnv")->willReturn("production");
$aAdditionalParams = [
'mode' => 'upgrade',
];
$oSequencer = new DataAuditSequencer($this->GivenParams($aAdditionalParams), $oRunTimeEnvironment);
self::assertFalse($this->InvokeNonPublicMethod(DataAuditSequencer::class, "IsDataAuditRequired", $oSequencer));
}
@@ -294,7 +346,11 @@ class DataAuditSequencerTest extends ItopTestCase
->willReturn(['product_version' => ITOP_VERSION_FULL]);
$oRunTimeEnvironment->expects($this->once())->method("GetFinalEnv")->willReturn("production");
$oSequencer = new DataAuditSequencer($this->GivenParams(['mode' => 'upgrade']), $oRunTimeEnvironment);
$aAdditionalParams = [
'mode' => 'upgrade',
'optional_steps' => ['setup-audit' => true ],
];
$oSequencer = new DataAuditSequencer($this->GivenParams($aAdditionalParams), $oRunTimeEnvironment);
self::assertTrue($this->InvokeNonPublicMethod(DataAuditSequencer::class, "IsDataAuditRequired", $oSequencer));
}
}