mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 23:44:11 +01:00
Compare commits
1 Commits
feature/89
...
feature/90
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c64320b317 |
@@ -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)
|
||||
|
||||
@@ -1415,9 +1415,6 @@ class WizStepModulesChoice extends WizardStep
|
||||
$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)));
|
||||
@@ -1743,7 +1740,7 @@ EOF
|
||||
*
|
||||
* @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 @@ EOF
|
||||
}
|
||||
}
|
||||
}
|
||||
$aOptions = isset($aInfo['options']) ? $aInfo['options'] : [];
|
||||
$aOptions = $aInfo['options'] ?? [];
|
||||
foreach ($aOptions as $index => $aChoice) {
|
||||
$sChoiceId = $sParentId.self::$SEP.$index;
|
||||
$aModuleInfo = [];
|
||||
@@ -1771,6 +1768,9 @@ EOF
|
||||
(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])) {
|
||||
@@ -1793,7 +1793,6 @@ EOF
|
||||
}
|
||||
}
|
||||
}
|
||||
$sChoiceType = isset($aChoice['type']) ? $aChoice['type'] : 'wizard_option';
|
||||
if ($aSelectedExtensions !== null) {
|
||||
$aSelectedExtensions[] = $aChoice['extension_code'];
|
||||
}
|
||||
@@ -1807,7 +1806,7 @@ EOF
|
||||
}
|
||||
}
|
||||
|
||||
$aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : [];
|
||||
$aAlternatives = $aInfo['alternatives'] ?? [];
|
||||
$sChoiceName = null;
|
||||
foreach ($aAlternatives as $index => $aChoice) {
|
||||
$sChoiceId = $sParentId.self::$SEP.$index;
|
||||
|
||||
@@ -4,7 +4,7 @@ class WizStepModulesChoiceFake extends WizStepModulesChoice
|
||||
{
|
||||
public function __construct(WizardController $oWizard, $sCurrentState)
|
||||
{
|
||||
|
||||
$this->oWizard = $oWizard;
|
||||
}
|
||||
|
||||
public function setExtensionMap(iTopExtensionsMap $oMap)
|
||||
|
||||
@@ -350,4 +350,98 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user