diff --git a/setup/wizardsteps.class.inc.php b/setup/wizardsteps.class.inc.php index f8c947f85f..56fd97db03 100644 --- a/setup/wizardsteps.class.inc.php +++ b/setup/wizardsteps.class.inc.php @@ -1937,14 +1937,15 @@ protected function GetStepInfo($idx = null) public function ComputeChoiceFlags(array $aChoice, string $sChoiceId, array $aSelectedComponents, bool $bAllDisabled, bool $bDisableUninstallCheck, bool $bUpgradeMode) { $oITopExtension = $this->oExtensionsMap->GetFromExtensionCode($aChoice['extension_code']); + //If the extension is missing from disk, it won't exist in the ExtensionsMap, thus returning null $bCanBeUninstalled = isset($aChoice['uninstallable']) ? $aChoice['uninstallable'] === true || $aChoice['uninstallable'] === 'yes' : $oITopExtension->CanBeUninstalled(); $bSelected = isset($aSelectedComponents[$sChoiceId]) && ($aSelectedComponents[$sChoiceId] == $sChoiceId); - $bMandatory = (isset($aChoice['mandatory']) && $aChoice['mandatory']) || $bUpgradeMode && $oITopExtension->bInstalled && !$bCanBeUninstalled && !$bDisableUninstallCheck; - $bMissingFromDisk = isset($aChoice['missing']) && $aChoice['missing'] === true; + + $bMandatory = (isset($aChoice['mandatory']) && $aChoice['mandatory']) || $bUpgradeMode && !$bMissingFromDisk && $oITopExtension->bInstalled && !$bCanBeUninstalled && !$bDisableUninstallCheck; $bInstalled = $bMissingFromDisk || $oITopExtension->bInstalled; $bDisabled = $bMandatory || $bAllDisabled || $bMissingFromDisk; - $bChecked = $bMandatory || $bSelected; + $bChecked = !$bMissingFromDisk && ($bMandatory || $bSelected); if (isset($aChoice['sub_options'])) { $aOptions = $aChoice['sub_options']['options'] ?? []; diff --git a/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php b/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php index 742cf00bc8..152284a1ca 100644 --- a/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php +++ b/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php @@ -67,6 +67,69 @@ public function ProviderComputeChoiceFlags() 'checked' => true, ], ], + 'A missing extension should be disabled and unchecked' => [ + 'aExtensionsOnDiskOrDb' => [ + 'itop-ext1' => [ + 'installed' => true, + ], + ], + 'aWizardStepDefinition' => [ + 'extension_code' => 'itop-ext1', + 'mandatory' => false, + 'missing' => true, + 'uninstallable' => true, + ], + 'bCurrentSelected' => false, + 'aExpectedFlags' => [ + 'uninstallable' => true, + 'missing' => true, + 'installed' => true, + 'disabled' => true, + 'checked' => false, + ], + ], + 'A missing extension should always be disabled and unchecked, even when mandatory' => [ + 'aExtensionsOnDiskOrDb' => [ + 'itop-ext1' => [ + 'installed' => true, + ], + ], + 'aWizardStepDefinition' => [ + 'extension_code' => 'itop-ext1', + 'mandatory' => true, + 'missing' => true, + 'uninstallable' => true, + ], + 'bCurrentSelected' => false, + 'aExpectedFlags' => [ + 'uninstallable' => true, + 'missing' => true, + 'installed' => true, + 'disabled' => true, + 'checked' => false, + ], + ], + 'A missing extension should always be disabled and unchecked, even when non-uninstallable' => [ + 'aExtensionsOnDiskOrDb' => [ + 'itop-ext1' => [ + 'installed' => true, + ], + ], + 'aWizardStepDefinition' => [ + 'extension_code' => 'itop-ext1', + 'mandatory' => true, + 'missing' => true, + 'uninstallable' => false, + ], + 'bCurrentSelected' => false, + 'aExpectedFlags' => [ + 'uninstallable' => false, + 'missing' => true, + 'installed' => true, + 'disabled' => true, + 'checked' => false, + ], + ], 'An installed but not selected extension should not be checked and be enabled' => [ 'aExtensionsOnDiskOrDb' => [ 'itop-ext1' => [