N°9144 Fix unit tests

This commit is contained in:
Timothee
2026-02-12 11:19:21 +01:00
parent 44d917c79d
commit 2f14b341e8
20 changed files with 49 additions and 35 deletions

View File

@@ -38,7 +38,7 @@ class ModelReflectionSerializer
$sOutput = "";
$iRes = 0;
$sCommandLine = sprintf("$sPHPExec %s/get_model_reflection.php --env='%s'", __DIR__, $sEnv);
$sCommandLine = sprintf("$sPHPExec %s/get_model_reflection.php --env=%s", __DIR__, $sEnv);
exec($sCommandLine, $sOutput, $iRes);
if ($iRes != 0) {
$this->LogErrorWithProperLogger("Cannot get classes", null, ['env' => $sEnv, 'code' => $iRes, "output" => $sOutput]);

View File

@@ -29,21 +29,8 @@ class SetupAudit extends AbstractSetupAudit
return;
}
$sCurrentEnv = MetaModel::GetEnvironment();
$sConfFile = utils::GetConfigFilePath($sCurrentEnv);
MetaModel::Startup($sConfFile, false /* $bModelOnly */, false /* $bAllowCache */, false /* $bTraceSourceFiles */, $sCurrentEnv);
if ($sCurrentEnv === $this->sEnvBefore) {
$this->aClassesBefore = MetaModel::GetClasses();
} else {
$this->aClassesBefore = ModelReflectionSerializer::GetInstance()->GetModelFromEnvironment($this->sEnvBefore);
}
if ($sCurrentEnv === $this->sEnvAfter) {
$this->aClassesAfter = MetaModel::GetClasses();
} else {
$this->aClassesAfter = ModelReflectionSerializer::GetInstance()->GetModelFromEnvironment($this->sEnvAfter);
}
$this->aClassesBefore = ModelReflectionSerializer::GetInstance()->GetModelFromEnvironment($this->sEnvBefore);
$this->aClassesAfter = ModelReflectionSerializer::GetInstance()->GetModelFromEnvironment($this->sEnvAfter);
$this->bClassesInitialized = true;
}

View File

@@ -5,7 +5,7 @@ require_once(APPROOT.'application/application.inc.php');
$sEnv = null;
if (isset($argv)) {
foreach ($argv as $iArg => $sArg) {
if (preg_match('/^--env=\'(.*)\'$/', $sArg, $aMatches)) {
if (preg_match('/^--env=(.*)$/', $sArg, $aMatches)) {
$sEnv = $aMatches[1];
}
}

View File

@@ -176,7 +176,7 @@ class WizardController
$this->PushStep(['class' => $sCurrentStepClass, 'state' => $sCurrentState]);
}
$aPossibleSteps = $oStep->GetPossibleSteps();
$aNextStepInfo = $oStep->ProcessParams(true); // true => moving forward
$aNextStepInfo = $oStep->UpdateWizardStateAndGetNextStep(true); // true => moving forward
if (in_array($aNextStepInfo['class'], $aPossibleSteps)) {
$oNextStep = new $aNextStepInfo['class']($this, $aNextStepInfo['state']);
$this->DisplayStep($oNextStep);

View File

@@ -1,4 +1,21 @@
<?php
/**
* Copyright (C) 2013-2026 Combodo SAS
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
*/
abstract class AbstractWizStepInstall extends WizardStep
{

View File

@@ -34,7 +34,7 @@ class WizStepAdminAccount extends WizardStep
return [WizStepInstallMiscParams::class];
}
public function ProcessParams($bMoveForward = true)
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
{
$this->oWizard->SaveParameter('admin_user', '');
$this->oWizard->SaveParameter('admin_pwd', '');

View File

@@ -35,7 +35,7 @@ class WizStepDBParams extends WizardStep
return ['WizStepAdminAccount'];
}
public function ProcessParams($bMoveForward = true)
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
{
$this->oWizard->SaveParameter('db_server', '');
$this->oWizard->SaveParameter('db_user', '');

View File

@@ -52,7 +52,7 @@ class WizStepDataAudit extends WizStepInstall
}
public function ProcessParams($bMoveForward = true)
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
{
return ['class' => 'WizStepSummary', 'state' => ''];
}

View File

@@ -36,7 +36,7 @@ class WizStepDetectedInfo extends WizardStep
return ['WizStepUpgradeMiscParams', 'WizStepLicense2'];
}
public function ProcessParams($bMoveForward = true)
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
{
$sUpgradeType = utils::ReadParam('upgrade_type');

View File

@@ -34,7 +34,7 @@ class WizStepDone extends WizardStep
return [];
}
public function ProcessParams($bMoveForward = true)
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
{
return ['class' => '', 'state' => ''];
}

View File

@@ -51,7 +51,7 @@ class WizStepInstall extends AbstractWizStepInstall
}
}
public function ProcessParams($bMoveForward = true)
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
{
return ['class' => 'WizStepDone', 'state' => ''];
}

View File

@@ -35,7 +35,7 @@ class WizStepInstallMiscParams extends AbstractWizStepMiscParams
return ['WizStepModulesChoice'];
}
public function ProcessParams($bMoveForward = true)
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
{
$this->oWizard->SaveParameter('default_language', '');
$this->oWizard->SaveParameter('application_url', '');

View File

@@ -34,7 +34,7 @@ class WizStepInstallOrUpgrade extends WizardStep
return ['WizStepDetectedInfo', 'WizStepLicense'];
}
public function ProcessParams($bMoveForward = true)
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
{
$sNextStep = '';
$sInstallMode = utils::ReadParam('install_mode');

View File

@@ -35,7 +35,7 @@ class WizStepLicense extends WizardStep
return ['WizStepDBParams'];
}
public function ProcessParams($bMoveForward = true)
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
{
$this->oWizard->SaveParameter('accept_license', 'no');
return ['class' => 'WizStepDBParams', 'state' => ''];

View File

@@ -28,7 +28,7 @@ class WizStepLicense2 extends WizStepLicense
return ['WizStepUpgradeMiscParams'];
}
public function ProcessParams($bMoveForward = true)
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
{
return ['class' => 'WizStepUpgradeMiscParams', 'state' => ''];
}

View File

@@ -118,7 +118,17 @@ class WizStepModulesChoice extends WizardStep
return [$aExtensionsAdded, $aExtensionsRemoved, $aExtensionsNotUninstallable];
}
public function ProcessParams($bMoveForward = true)
public function IsDataAuditEnabled(): bool {
$sPath = APPROOT.'env-production';
if (!is_dir($sPath)) {
SetupLog::Info("Reinstallation of an iTop from a backup (No env-production found). Setup data audit disabled");
return false;
}
return true;
}
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
{
// Accumulates the selected modules:
$index = $this->GetStepIndex();
@@ -156,7 +166,7 @@ class WizStepModulesChoice extends WizardStep
$this->oWizard->SetParameter('removed_extensions', json_encode($aExtensionsRemoved));
$this->oWizard->SetParameter('extensions_not_uninstallable', json_encode(array_keys($aExtensionsNotUninstallable)));
$sMode = $this->oWizard->GetParameter('mode', 'install');
if ($sMode == 'install') {
if ($sMode == 'install' || !$this->IsDataAuditEnabled()) {
return ['class' => 'WizStepSummary', 'state' => ''];
} else {
return ['class' => 'WizStepDataAudit', 'state' => ''];
@@ -824,7 +834,7 @@ EOF
return 'Non-uninstallable extension missing';
}
if ($this->GetStepInfo(1 + $this->GetStepIndex()) === null) {
if ($this->GetStepInfo(1 + $this->GetStepIndex()) === null && $this->IsDataAuditEnabled()) {
return 'Check compatibility';
}

View File

@@ -58,7 +58,7 @@ class WizStepSummary extends AbstractWizStepInstall
}
}
public function ProcessParams($bMoveForward = true)
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
{
$this->oWizard->SaveParameter('db_backup', false);
$this->oWizard->SaveParameter('db_backup_path', '');

View File

@@ -34,7 +34,7 @@ class WizStepUpgradeMiscParams extends AbstractWizStepMiscParams
return ['WizStepModulesChoice'];
}
public function ProcessParams($bMoveForward = true)
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
{
$this->oWizard->SaveParameter('application_url', '');
$this->oWizard->SaveParameter('graphviz_path', '');

View File

@@ -46,7 +46,7 @@ class WizStepWelcome extends WizardStep
return ['WizStepInstallOrUpgrade'];
}
public function ProcessParams($bMoveForward = true)
public function UpdateWizardStateAndGetNextStep($bMoveForward = true)
{
$sUID = SetupUtils::CreateSetupToken();
$this->oWizard->SetParameter('authent', $sUID);

View File

@@ -106,7 +106,7 @@ abstract class WizardStep
* @param bool $bMoveForward True if the wizard is moving forward 'Next >>' button pressed, false otherwise
* @return hash array('class' => $sNextClass, 'state' => $sNextState)
*/
abstract public function ProcessParams($bMoveForward = true);
abstract public function UpdateWizardStateAndGetNextStep($bMoveForward = true);
/**
* Returns the list of possible steps from this step forward