From 4d2722654a56c68cc3967c09f43b3475ec8b0391 Mon Sep 17 00:00:00 2001 From: odain Date: Wed, 6 May 2026 10:46:57 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B09144=20-=20no=20audit=20in=20unattended?= =?UTF-8?q?=20+=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup/runtimeenv.class.inc.php | 3 + setup/sequencers/DataAuditSequencer.php | 4 ++ setup/wizardsteps/AbstractWizStepInstall.php | 1 + .../ApplicationInstallerSequencerTest.php | 20 +++--- .../sequencers/DataAuditSequencerTest.php | 62 ++++++++++++++++++- 5 files changed, 80 insertions(+), 10 deletions(-) diff --git a/setup/runtimeenv.class.inc.php b/setup/runtimeenv.class.inc.php index 8d0ace6239..913c58ee80 100644 --- a/setup/runtimeenv.class.inc.php +++ b/setup/runtimeenv.class.inc.php @@ -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(); diff --git a/setup/sequencers/DataAuditSequencer.php b/setup/sequencers/DataAuditSequencer.php index 36ab5fc209..eb302873d0 100644 --- a/setup/sequencers/DataAuditSequencer.php +++ b/setup/sequencers/DataAuditSequencer.php @@ -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; } diff --git a/setup/wizardsteps/AbstractWizStepInstall.php b/setup/wizardsteps/AbstractWizStepInstall.php index ab8860b385..8311488408 100644 --- a/setup/wizardsteps/AbstractWizStepInstall.php +++ b/setup/wizardsteps/AbstractWizStepInstall.php @@ -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), diff --git a/tests/php-unit-tests/unitary-tests/setup/sequencers/ApplicationInstallerSequencerTest.php b/tests/php-unit-tests/unitary-tests/setup/sequencers/ApplicationInstallerSequencerTest.php index 654f6a0bc6..b9a7d8728a 100644 --- a/tests/php-unit-tests/unitary-tests/setup/sequencers/ApplicationInstallerSequencerTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/sequencers/ApplicationInstallerSequencerTest.php @@ -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); } diff --git a/tests/php-unit-tests/unitary-tests/setup/sequencers/DataAuditSequencerTest.php b/tests/php-unit-tests/unitary-tests/setup/sequencers/DataAuditSequencerTest.php index 33ae70c74f..08721bfcd6 100644 --- a/tests/php-unit-tests/unitary-tests/setup/sequencers/DataAuditSequencerTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/sequencers/DataAuditSequencerTest.php @@ -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)); } }