mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-25 21:34:12 +01:00
Compare commits
4 Commits
feature/un
...
feature/90
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ef4329077e | ||
|
|
e27508ae4a | ||
|
|
7c7dc4d5c5 | ||
|
|
b135202496 |
@@ -2150,7 +2150,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)
|
||||
|
||||
@@ -48,7 +48,7 @@ class WizStepModulesChoice extends WizardStep
|
||||
*/
|
||||
protected bool $bChoicesFromDatabase;
|
||||
|
||||
private array $aAnalyzeInstallationModules;
|
||||
private array $aAnalyzeInstallationModules = [];
|
||||
private ?MissingDependencyException $oMissingDependencyException = null;
|
||||
|
||||
public function __construct(WizardController $oWizard, $sCurrentState)
|
||||
@@ -486,7 +486,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
|
||||
@@ -499,7 +499,7 @@ EOF
|
||||
}
|
||||
}
|
||||
}
|
||||
$aOptions = isset($aInfo['options']) ? $aInfo['options'] : [];
|
||||
$aOptions = $aInfo['options'] ?? [];
|
||||
foreach ($aOptions as $index => $aChoice) {
|
||||
$sChoiceId = $sParentId.self::$SEP.$index;
|
||||
$aModuleInfo = [];
|
||||
@@ -514,16 +514,19 @@ EOF
|
||||
(isset($aSelectedChoices[$sChoiceId]) && ($aSelectedChoices[$sChoiceId] == $sChoiceId))) {
|
||||
$sDisplayChoices .= '<li>'.$aChoice['title'].'</li>';
|
||||
if (isset($aChoice['modules'])) {
|
||||
if (count($aChoice['modules']) === 0) {
|
||||
throw new Exception('Extension '.$aChoice['extension_code'].' does not have any module associated');
|
||||
}
|
||||
foreach ($aChoice['modules'] as $sModuleId) {
|
||||
$bSelected = true;
|
||||
if (isset($aModuleInfo[$sModuleId])) {
|
||||
// Test if module has 'auto_select'
|
||||
$aInfo = $aModuleInfo[$sModuleId];
|
||||
if (isset($aInfo['auto_select'])) {
|
||||
$aCurrentModuleInfo = $aModuleInfo[$sModuleId];
|
||||
if (isset($aCurrentModuleInfo['auto_select'])) {
|
||||
// Check the module selection
|
||||
try {
|
||||
SetupInfo::SetSelectedModules($aModules);
|
||||
$bSelected = $this->GetPhpExpressionEvaluator()->ParseAndEvaluateBooleanExpression($aInfo['auto_select']);
|
||||
$bSelected = $this->GetPhpExpressionEvaluator()->ParseAndEvaluateBooleanExpression($aCurrentModuleInfo['auto_select']);
|
||||
} catch (ModuleFileReaderException $e) {
|
||||
//logged already
|
||||
$bSelected = false;
|
||||
@@ -536,7 +539,6 @@ EOF
|
||||
}
|
||||
}
|
||||
}
|
||||
$sChoiceType = isset($aChoice['type']) ? $aChoice['type'] : 'wizard_option';
|
||||
if ($aSelectedExtensions !== null) {
|
||||
$aSelectedExtensions[] = $aChoice['extension_code'];
|
||||
}
|
||||
@@ -550,7 +552,7 @@ EOF
|
||||
}
|
||||
}
|
||||
|
||||
$aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : [];
|
||||
$aAlternatives = $aInfo['alternatives'] ?? [];
|
||||
$sChoiceName = null;
|
||||
foreach ($aAlternatives as $index => $aChoice) {
|
||||
$sChoiceId = $sParentId.self::$SEP.$index;
|
||||
|
||||
@@ -559,4 +559,279 @@ class WizStepModulesChoiceTest extends ItopTestCase
|
||||
|
||||
return $aSteps[$index] ?? null;
|
||||
}
|
||||
|
||||
public function ProviderGetSelectedModules()
|
||||
{
|
||||
return [
|
||||
'No extension selected' => [
|
||||
'aSelected' => [],
|
||||
'aExpectedModules' => [],
|
||||
'aExpectedExtensions' => [],
|
||||
],
|
||||
'One extension selected' => [
|
||||
'aSelected' => ['_0' => '_0'],
|
||||
'aExpectedModules' => ['combodo-sample-module' => true],
|
||||
'aExpectedExtensions' => ['combodo-sample'],
|
||||
],
|
||||
'More extensions selected' => [
|
||||
'aSelected' => ['_0' => '_0', '_1' => '_1'],
|
||||
'aExpectedModules' => ['combodo-sample-module' => true, 'combodo-test-moduleA' => true, 'combodo-test-moduleB' => true],
|
||||
'aExpectedExtensions' => ['combodo-sample', 'combodo-test'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider ProviderGetSelectedModules
|
||||
*/
|
||||
public function testGetSelectedModules($aSelectedExtensions, $aExpectedModules, $aExpectedExtensions)
|
||||
{
|
||||
$aExtensionsMapData = [
|
||||
'combodo-sample' => [
|
||||
'installed' => false,
|
||||
],
|
||||
'combodo-test' => [
|
||||
'installed' => false,
|
||||
],
|
||||
];
|
||||
$this->oStep->setExtensionMap(iTopExtensionsMapFake::createFromArray($aExtensionsMapData));
|
||||
|
||||
$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,
|
||||
],
|
||||
[
|
||||
'extension_code' => 'combodo-test',
|
||||
'title' => 'Test extension',
|
||||
'description' => '',
|
||||
'more_info' => '',
|
||||
'default' => true,
|
||||
'modules' => [
|
||||
'combodo-test-moduleA',
|
||||
'combodo-test-moduleB',
|
||||
],
|
||||
'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 testGetSelectedModulesShouldAlwaysSelectMandatoryExtension()
|
||||
{
|
||||
|
||||
$aSelectedExtensions = ['_0' => '_0'];
|
||||
|
||||
$aExtensionsMapData = [
|
||||
'combodo-sample' => [
|
||||
'installed' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$this->oStep->setExtensionMap(iTopExtensionsMapFake::createFromArray($aExtensionsMapData));
|
||||
|
||||
$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' => true,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$aExpectedModules = ['combodo-sample-module' => true];
|
||||
$aExpectedExtensions = ['combodo-sample'];
|
||||
|
||||
$aModules = [];
|
||||
$aExtensions = [];
|
||||
$this->oStep->GetSelectedModules($aStepInfo, $aSelectedExtensions, $aModules, '', '', $aExtensions);
|
||||
$this->assertEquals($aExpectedModules, $aModules);
|
||||
$this->assertEquals($aExpectedExtensions, $aExtensions);
|
||||
}
|
||||
|
||||
public function testGetSelectedModulesShouldShouldParseAutoSelectCondition()
|
||||
{
|
||||
//the 'auto_select' parameter, contrary to its name, deselect the module if its result is false
|
||||
|
||||
$aSelectedExtensions = ['_0' => '_0'];
|
||||
|
||||
$aExtensionsMapData = [
|
||||
'combodo-sample' => [
|
||||
'installed' => true,
|
||||
'module_info' => [
|
||||
'combodo-sample-module' => [
|
||||
'auto_select' => 'true && false',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->oStep->setExtensionMap(iTopExtensionsMapFake::createFromArray($aExtensionsMapData));
|
||||
|
||||
$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' => true,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$aExpectedModules = [];
|
||||
$aExpectedExtensions = ['combodo-sample'];
|
||||
|
||||
$aModules = [];
|
||||
$aExtensions = [];
|
||||
$this->oStep->GetSelectedModules($aStepInfo, $aSelectedExtensions, $aModules, '', '', $aExtensions);
|
||||
$this->assertEquals($aExpectedModules, $aModules);
|
||||
$this->assertEquals($aExpectedExtensions, $aExtensions);
|
||||
}
|
||||
|
||||
public function testGetSelectedModulesWithSubOptions()
|
||||
{
|
||||
|
||||
$aSelectedExtensions = ['_0' => '_0', '_0_0' => '_0_0'];
|
||||
|
||||
$aExtensionsMapData = [
|
||||
'combodo-sample' => [
|
||||
'installed' => false,
|
||||
],
|
||||
'combodo-sub-sample' => [
|
||||
'installed' => false,
|
||||
],
|
||||
];
|
||||
$this->oStep->setExtensionMap(iTopExtensionsMapFake::createFromArray($aExtensionsMapData));
|
||||
|
||||
$aStepInfo = [
|
||||
'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,
|
||||
'sub_options' => [
|
||||
'options' => [
|
||||
[
|
||||
'extension_code' => 'combodo-sub-sample',
|
||||
'title' => 'Sample sub extension',
|
||||
'description' => '',
|
||||
'more_info' => '',
|
||||
'default' => true,
|
||||
'modules' => [
|
||||
'combodo-sub-sample-module',
|
||||
],
|
||||
'mandatory' => false,
|
||||
'source_label' => '',
|
||||
'uninstallable' => true,
|
||||
'missing' => false,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$aExpectedModules = ['combodo-sample-module' => true, 'combodo-sub-sample-module' => true];
|
||||
$aExpectedExtensions = ['combodo-sample', 'combodo-sub-sample'];
|
||||
|
||||
$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->expectExceptionMessage('Extension combodo-sample does not have any module associated');
|
||||
$this->oStep->GetSelectedModules($aStepInfo, ['_0' => '_0'], $aModules, '', '', $aExtensions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ class iTopExtensionsMapFake extends iTopExtensionsMap
|
||||
$oExtension->aModules = $aExtension['modules'] ?? [];
|
||||
$oExtension->bCanBeUninstalled = $aExtension['uninstallable'] ?? null;
|
||||
$oExtension->sVersion = $aExtension['version'] ?? '1.0.0';
|
||||
$oExtension->aModuleInfo = [];
|
||||
$oExtension->aModuleInfo = $aExtension['module_info'] ?? [];
|
||||
$oMap->AddExtension($oExtension);
|
||||
}
|
||||
return $oMap;
|
||||
|
||||
Reference in New Issue
Block a user