diff --git a/setup/setuputils.class.inc.php b/setup/setuputils.class.inc.php
index 95ae569eb1..c2d35c3e70 100644
--- a/setup/setuputils.class.inc.php
+++ b/setup/setuputils.class.inc.php
@@ -2155,7 +2155,7 @@ class SetupInfo
/**
* Called by the setup process to initializes the list of selected modules. Do not call this method
* from an 'auto_select' rule
- * @param hash $aModules
+ * @param array $aModules
* @return void
*/
public static function SetSelectedModules($aModules)
diff --git a/setup/wizardsteps.class.inc.php b/setup/wizardsteps.class.inc.php
index c2f9860f47..02ec0afc5c 100644
--- a/setup/wizardsteps.class.inc.php
+++ b/setup/wizardsteps.class.inc.php
@@ -1415,9 +1415,6 @@ public function ProcessParams($bMoveForward = true)
$sDisplayChoices .= $this->GetSelectedModules($aStepInfo, $aSelectedChoices[$i], $aModules, '', '', $aExtensions);
}
$sDisplayChoices .= '';
- if (class_exists('CreateITILProfilesInstaller')) {
- $this->oWizard->SetParameter('old_addon', true);
- }
[$aExtensionsAdded, $aExtensionsRemoved, $aExtensionsNotUninstallable] = $this->GetAddedAndRemovedExtensions($aExtensions);
$this->oWizard->SetParameter('selected_modules', json_encode(array_keys($aModules)));
@@ -1743,7 +1740,7 @@ private function GetPhpExpressionEvaluator(): PhpExpressionEvaluator
*
* @return string A text representation of what will be installed
*/
- protected function GetSelectedModules($aInfo, $aSelectedChoices, &$aModules, $sParentId = '', $sDisplayChoices = '', &$aSelectedExtensions = null)
+ public function GetSelectedModules($aInfo, $aSelectedChoices, &$aModules, $sParentId = '', $sDisplayChoices = '', &$aSelectedExtensions = null)
{
if ($sParentId == '') {
// Check once (before recursing) that the hidden modules are selected
@@ -1756,7 +1753,7 @@ protected function GetSelectedModules($aInfo, $aSelectedChoices, &$aModules, $sP
}
}
}
- $aOptions = isset($aInfo['options']) ? $aInfo['options'] : [];
+ $aOptions = $aInfo['options'] ?? [];
foreach ($aOptions as $index => $aChoice) {
$sChoiceId = $sParentId.self::$SEP.$index;
$aModuleInfo = [];
@@ -1771,6 +1768,9 @@ protected function GetSelectedModules($aInfo, $aSelectedChoices, &$aModules, $sP
(isset($aSelectedChoices[$sChoiceId]) && ($aSelectedChoices[$sChoiceId] == $sChoiceId))) {
$sDisplayChoices .= '
'.$aChoice['title'].'';
if (isset($aChoice['modules'])) {
+ if (count($aChoice['modules']) === 0) {
+ throw new Exception('Setup option does not have any module associated');
+ }
foreach ($aChoice['modules'] as $sModuleId) {
$bSelected = true;
if (isset($aModuleInfo[$sModuleId])) {
@@ -1793,7 +1793,6 @@ protected function GetSelectedModules($aInfo, $aSelectedChoices, &$aModules, $sP
}
}
}
- $sChoiceType = isset($aChoice['type']) ? $aChoice['type'] : 'wizard_option';
if ($aSelectedExtensions !== null) {
$aSelectedExtensions[] = $aChoice['extension_code'];
}
@@ -1807,7 +1806,7 @@ protected function GetSelectedModules($aInfo, $aSelectedChoices, &$aModules, $sP
}
}
- $aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : [];
+ $aAlternatives = $aInfo['alternatives'] ?? [];
$sChoiceName = null;
foreach ($aAlternatives as $index => $aChoice) {
$sChoiceId = $sParentId.self::$SEP.$index;
diff --git a/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceFake.php b/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceFake.php
index 69a99b3dd1..79cd0b880f 100644
--- a/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceFake.php
+++ b/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceFake.php
@@ -4,7 +4,7 @@ class WizStepModulesChoiceFake extends WizStepModulesChoice
{
public function __construct(WizardController $oWizard, $sCurrentState)
{
-
+ $this->oWizard = $oWizard;
}
public function setExtensionMap(iTopExtensionsMap $oMap)
diff --git a/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php b/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php
index 5f30de4250..ad51b565aa 100644
--- a/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php
+++ b/tests/php-unit-tests/unitary-tests/setup/WizStepModulesChoiceTest.php
@@ -350,4 +350,98 @@ public function testGetAddedAndRemovedExtensions($aExtensionsOnDiskOrDb, $aSelec
$this->assertEquals($aExpectedRemovedList, $aRemovedList);
}
+ public function ProviderGetSelectedModules()
+ {
+ return [
+ 'No extension selected' => [
+ 'aSelected' => [],
+ 'aExpectedModules' => [],
+ 'aExpectedExtensions' => [],
+ ],
+ 'One extension selected' => [
+ 'aSelected' => ['_0' => '_0'],
+ 'aExpectedModules' => ['combodo-sample-module' => true],
+ 'aExpectedExtensions' => ['combodo-sample'],
+ ],
+ ];
+ }
+
+ /**
+ * @dataProvider ProviderGetSelectedModules
+ */
+ public function testGetSelectedModules($aSelectedExtensions, $aExpectedModules, $aExpectedExtensions)
+ {
+ $aExtensionsMapData = [
+ 'combodo-sample' => [
+ 'installed' => false,
+ ],
+ ];
+ $this->oStep->setExtensionMap(iTopExtensionsMapFake::createFromArray($aExtensionsMapData, ));
+
+ //GetSelectedModules
+ $aStepInfo = [
+ 'title' => 'Extensions',
+ 'description' => '',
+ 'banner' => '',
+ 'options' => [
+ [
+ 'extension_code' => 'combodo-sample',
+ 'title' => 'Sample extension',
+ 'description' => '',
+ 'more_info' => '',
+ 'default' => true,
+ 'modules' => [
+ 'combodo-sample-module',
+ ],
+ 'mandatory' => false,
+ 'source_label' => '',
+ 'uninstallable' => true,
+ 'missing' => false,
+ ],
+ ],
+ ];
+
+ $aModules = [];
+ $aExtensions = [];
+ $this->oStep->GetSelectedModules($aStepInfo, $aSelectedExtensions, $aModules, '', '', $aExtensions);
+ $this->assertEquals($aExpectedModules, $aModules);
+ $this->assertEquals($aExpectedExtensions, $aExtensions);
+ }
+
+ public function testGetSelectedModulesShouldThrowAnExceptionWhenAnySelectedExtensionDoesNotHaveAnyAssociatedModules()
+ {
+ $aExtensionsMapData = [
+ 'combodo-sample' => [
+ 'installed' => false,
+ ],
+ ];
+ $this->oStep->setExtensionMap(iTopExtensionsMapFake::createFromArray($aExtensionsMapData, ));
+
+ //GetSelectedModules
+ $aStepInfo = [
+ 'title' => 'Extensions',
+ 'description' => '',
+ 'banner' => '',
+ 'options' => [
+ [
+ 'extension_code' => 'combodo-sample',
+ 'title' => 'Sample extension',
+ 'description' => '',
+ 'more_info' => '',
+ 'default' => true,
+ 'modules' => [],
+ 'mandatory' => false,
+ 'source_label' => '',
+ 'uninstallable' => true,
+ 'missing' => false,
+ ],
+ ],
+ ];
+
+ $aModules = [];
+ $aExtensions = [];
+ $this->expectException('Exception');
+ $this->oStep->GetSelectedModules($aStepInfo, ['_0' => '_0'], $aModules, '', '', $aExtensions);
+ }
+
}