Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup/setuputils.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions setup/wizardsteps.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1415,9 +1415,6 @@ public function ProcessParams($bMoveForward = true)
$sDisplayChoices .= $this->GetSelectedModules($aStepInfo, $aSelectedChoices[$i], $aModules, '', '', $aExtensions);
}
$sDisplayChoices .= '</ul>';
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)));
Expand Down Expand Up @@ -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
Expand All @@ -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 = [];
Expand All @@ -1771,6 +1768,9 @@ protected function GetSelectedModules($aInfo, $aSelectedChoices, &$aModules, $sP
(isset($aSelectedChoices[$sChoiceId]) && ($aSelectedChoices[$sChoiceId] == $sChoiceId))) {
$sDisplayChoices .= '<li>'.$aChoice['title'].'</li>';
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])) {
Expand All @@ -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'];
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class WizStepModulesChoiceFake extends WizStepModulesChoice
{
public function __construct(WizardController $oWizard, $sCurrentState)
{

$this->oWizard = $oWizard;
}

public function setExtensionMap(iTopExtensionsMap $oMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,98 @@ public function testGetAddedAndRemovedExtensions($aExtensionsOnDiskOrDb, $aSelec
$this->assertEquals($aExpectedRemovedList, $aRemovedList);
}

public function ProviderGetSelectedModules()
{
return [
'No extension selected' => [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder : do we have other cases with different conditions and same result? How about having test cases with exclusive options ?

'aSelected' => [],
'aExpectedModules' => [],
'aExpectedExtensions' => [],
],
'One extension selected' => [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independently from the implementation, we should have tests scenarios with multiple extensions 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);
}

}