mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
* N°7306 - Use iTop configuration settings to run unattended installation (instead of XML file settings) * 7306 - fix infinite loop with db_tls.ca null * 7306 - complete fields to use from itop configuration instead of XML setup * fix using default language from conf * 6365 - temp work * 6365 - add option to select modules from installation.xml * 6365-select modules option in unattended install * 6365 - pass env to service + debug failed test * 6365 - debug ci again + separate process annotation * 6365 - fix test + cleanup * 6365 - ci using use_installation_xml mode * 6365 - ci using use_installation_xml mode * 6365 - pass selected_modules to unattended * N°6365 - Compute selected modules based on selected extensions coming from XML setup * switch constr parameters and fix call from unattended cli * 6365 - use use_installation_xml for unattended install only when no selected modules already provided * test ci XML setup including selected extensions but no modules * test ci installing iTop without selected modules/extenesions: guess via installation.xml * same but without even providing XML setup - comment it in ci_description.ini * 7306 - cleanup requires * use infra master * N°6365 - make current unattended CLI work with any iTop version (CLIPage compatibility) * N°6365 - log which modules will be installed during setup * N°6365 - unattended documentation + bash helper * 6365- fix warning due to copies index access * 6365 - enhance traces feedback to understant which and how modules are computes * 6365 - enhance bash CLI + doc * 6365 - fix require clipage compatibility * 6365 - add return for better cli ouput * 6365 - enhance ouput messages * Document the usage and harmonize argument names (still not perfect) * 6365 - fix use of new param param-file * 6365 - fix test + vardump cleanup * N°6365 - use underscore for unattended install options as advices in the PR * 6365 -enhance test by using PHP_BINARY --------- Co-authored-by: Romain Quetiez <romain.quetiez@combodo.com>
316 lines
9.4 KiB
PHP
316 lines
9.4 KiB
PHP
<?php
|
|
|
|
namespace Combodo\iTop\Test\UnitTest\Setup\UnattendedInstall;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class InstallationFileServiceTest extends TestCase {
|
|
protected function setUp(): void {
|
|
parent::setUp();
|
|
require_once(dirname(__FILE__, 6) . '/setup/unattended-install/InstallationFileService.php');
|
|
$this->sFolderToCleanup = null;
|
|
\ModuleDiscovery::ResetCache();
|
|
}
|
|
|
|
protected function tearDown(): void {
|
|
parent::tearDown();
|
|
|
|
$sModuleId = "itop-problem-mgmt";
|
|
$this->RecurseMoveDir(APPROOT."data/production-modules/$sModuleId", APPROOT . "datamodels/2.x/$sModuleId");
|
|
}
|
|
|
|
public function GetDefaultModulesProvider() {
|
|
return [
|
|
'all checked' => [ true ],
|
|
'only defaut + mandatory' => [ false ],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider GetDefaultModulesProvider
|
|
*/
|
|
public function testProcessInstallationChoices($bInstallationOptionalChoicesChecked=false) {
|
|
$sPath = realpath(dirname(__FILE__, 6)."/datamodels/2.x/installation.xml");
|
|
$this->assertTrue(is_file($sPath));
|
|
$oInstallationFileService = new \InstallationFileService($sPath, 'production', [], $bInstallationOptionalChoicesChecked);
|
|
$oInstallationFileService->ProcessInstallationChoices();
|
|
$aExpectedModules = [
|
|
"itop-config-mgmt",
|
|
"itop-attachments",
|
|
"itop-profiles-itil",
|
|
"itop-welcome-itil",
|
|
"itop-tickets",
|
|
"itop-files-information",
|
|
"combodo-db-tools",
|
|
"itop-core-update",
|
|
"itop-hub-connector",
|
|
"itop-oauth-client",
|
|
"itop-datacenter-mgmt",
|
|
"itop-endusers-devices",
|
|
"itop-storage-mgmt",
|
|
"itop-virtualization-mgmt",
|
|
"itop-service-mgmt",
|
|
"itop-request-mgmt",
|
|
"itop-portal",
|
|
"itop-portal-base",
|
|
"itop-change-mgmt",
|
|
];
|
|
|
|
$aExpectedUnselectedModules = [
|
|
'itop-change-mgmt-itil',
|
|
'itop-incident-mgmt-itil',
|
|
'itop-request-mgmt-itil',
|
|
'itop-service-mgmt-provider',
|
|
];
|
|
|
|
if ($bInstallationOptionalChoicesChecked){
|
|
$aExpectedModules []= "itop-problem-mgmt";
|
|
$aExpectedModules []= "itop-knownerror-mgmt";
|
|
} else {
|
|
$aExpectedUnselectedModules []= "itop-problem-mgmt";
|
|
$aExpectedUnselectedModules []= "itop-knownerror-mgmt";
|
|
}
|
|
|
|
sort($aExpectedModules);
|
|
$aModules = array_keys($oInstallationFileService->GetSelectedModules());
|
|
sort($aModules);
|
|
|
|
$this->assertEquals($aExpectedModules, $aModules);
|
|
|
|
$aUnselectedModules = array_keys($oInstallationFileService->GetUnSelectedModules());
|
|
sort($aExpectedUnselectedModules);
|
|
sort($aUnselectedModules);
|
|
$this->assertEquals($aExpectedUnselectedModules, $aUnselectedModules);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider GetDefaultModulesProvider
|
|
*/
|
|
public function testGetAllSelectedModules($bInstallationOptionalChoicesChecked=false) {
|
|
$sPath = realpath(dirname(__FILE__, 6)."/datamodels/2.x/installation.xml");
|
|
$oInstallationFileService = new \InstallationFileService($sPath, 'production', [], $bInstallationOptionalChoicesChecked);
|
|
$oInstallationFileService->Init();
|
|
|
|
$aSelectedModules = $oInstallationFileService->GetSelectedModules();
|
|
$aExpectedInstallationModules = [
|
|
"itop-config-mgmt",
|
|
"itop-attachments",
|
|
"itop-profiles-itil",
|
|
"itop-welcome-itil",
|
|
"itop-tickets",
|
|
"itop-files-information",
|
|
"combodo-db-tools",
|
|
"itop-core-update",
|
|
"itop-hub-connector",
|
|
"itop-oauth-client",
|
|
"itop-datacenter-mgmt",
|
|
"itop-endusers-devices",
|
|
"itop-storage-mgmt",
|
|
"itop-virtualization-mgmt",
|
|
"itop-service-mgmt",
|
|
"itop-request-mgmt",
|
|
"itop-portal",
|
|
"itop-portal-base",
|
|
"itop-change-mgmt",
|
|
];
|
|
if ($bInstallationOptionalChoicesChecked){
|
|
$aExpectedInstallationModules []= "itop-problem-mgmt";
|
|
$aExpectedInstallationModules []= "itop-knownerror-mgmt";
|
|
}
|
|
|
|
$aExpectedAuthenticationModules = [
|
|
'authent-cas',
|
|
'authent-external',
|
|
'authent-ldap',
|
|
'authent-local',
|
|
];
|
|
|
|
$aUnvisibleModules = [
|
|
'itop-backup',
|
|
'itop-config',
|
|
'itop-sla-computation',
|
|
];
|
|
|
|
$aAutoSelectedModules = [
|
|
'itop-bridge-virtualization-storage',
|
|
];
|
|
|
|
$this->checkModuleList("installation.xml choices", $aExpectedInstallationModules, $aSelectedModules);
|
|
$this->checkModuleList("authentication category", $aExpectedAuthenticationModules, $aSelectedModules);
|
|
$this->checkModuleList("unvisible", $aUnvisibleModules, $aSelectedModules);
|
|
$this->checkModuleList("auto-select", $aAutoSelectedModules, $aSelectedModules);
|
|
$this->assertEquals([], $aSelectedModules, "there should be no more modules remaining apart from below lists");
|
|
}
|
|
|
|
private function GetSelectedItilExtensions(bool $coreExtensionIncluded, bool $bKnownMgtIncluded) : array {
|
|
$aExtensions = [
|
|
'itop-config-mgmt-datacenter',
|
|
'itop-config-mgmt-end-user',
|
|
'itop-config-mgmt-storage',
|
|
'itop-config-mgmt-virtualization',
|
|
'itop-service-mgmt-enterprise',
|
|
'itop-ticket-mgmt-itil',
|
|
'itop-ticket-mgmt-itil-user-request',
|
|
'itop-ticket-mgmt-itil-incident',
|
|
'itop-ticket-mgmt-itil-enhanced-portal',
|
|
'itop-change-mgmt-itil',
|
|
];
|
|
|
|
if ($coreExtensionIncluded){
|
|
$aExtensions[]= 'itop-config-mgmt-core';
|
|
}
|
|
|
|
if ($bKnownMgtIncluded){
|
|
$aExtensions[]= 'itop-kown-error-mgmt';
|
|
}
|
|
|
|
return $aExtensions;
|
|
|
|
}
|
|
|
|
public function ItilExtensionProvider() {
|
|
return [
|
|
'all itil extensions + INCLUDING known-error-mgt' => [
|
|
'aSelectedExtensions' => $this->GetSelectedItilExtensions(true, true),
|
|
'bKnownMgtSelected' => true,
|
|
],
|
|
'all itil extensions WITHOUT known-error-mgt' => [
|
|
'aSelectedExtensions' => $this->GetSelectedItilExtensions(true, false),
|
|
'bKnownMgtSelected' => false,
|
|
],
|
|
'all itil extensions WITHOUT core mandatory ones + INCLUDING known-error-mgt' => [
|
|
'aSelectedExtensions' => $this->GetSelectedItilExtensions(false, true),
|
|
'bKnownMgtSelected' => true,
|
|
],
|
|
'all itil extensions WITHOUT core mandatory ones and WITHOUT known-error-mgt' => [
|
|
'aSelectedExtensions' => $this->GetSelectedItilExtensions(false, false),
|
|
'bKnownMgtSelected' => false,
|
|
],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider ItilExtensionProvider
|
|
*/
|
|
public function testGetAllSelectedModules_withItilExtensions(array $aSelectedExtensions, bool $bKnownMgtSelected) {
|
|
$sPath = realpath(dirname(__FILE__, 6)."/datamodels/2.x/installation.xml");
|
|
$oInstallationFileService = new \InstallationFileService($sPath, 'production', $aSelectedExtensions);
|
|
$oInstallationFileService->Init();
|
|
|
|
$aSelectedModules = $oInstallationFileService->GetSelectedModules();
|
|
$aExpectedInstallationModules = [
|
|
"itop-config-mgmt",
|
|
"itop-attachments",
|
|
"itop-profiles-itil",
|
|
"itop-welcome-itil",
|
|
"itop-tickets",
|
|
"itop-files-information",
|
|
"combodo-db-tools",
|
|
"itop-core-update",
|
|
"itop-hub-connector",
|
|
"itop-oauth-client",
|
|
"itop-datacenter-mgmt",
|
|
"itop-endusers-devices",
|
|
"itop-storage-mgmt",
|
|
"itop-virtualization-mgmt",
|
|
"itop-service-mgmt",
|
|
"itop-request-mgmt-itil",
|
|
"itop-incident-mgmt-itil",
|
|
"itop-portal",
|
|
"itop-portal-base",
|
|
"itop-change-mgmt-itil",
|
|
"itop-full-itil",
|
|
];
|
|
if ($bKnownMgtSelected){
|
|
$aExpectedInstallationModules []= "itop-knownerror-mgmt";
|
|
}
|
|
|
|
$aExpectedAuthenticationModules = [
|
|
'authent-cas',
|
|
'authent-external',
|
|
'authent-ldap',
|
|
'authent-local',
|
|
];
|
|
|
|
$aUnvisibleModules = [
|
|
'itop-backup',
|
|
'itop-config',
|
|
'itop-sla-computation',
|
|
];
|
|
|
|
$aAutoSelectedModules = [
|
|
'itop-bridge-virtualization-storage',
|
|
];
|
|
|
|
$this->checkModuleList("installation.xml choices", $aExpectedInstallationModules, $aSelectedModules);
|
|
$this->checkModuleList("authentication category", $aExpectedAuthenticationModules, $aSelectedModules);
|
|
$this->checkModuleList("unvisible", $aUnvisibleModules, $aSelectedModules);
|
|
$this->checkModuleList("auto-select", $aAutoSelectedModules, $aSelectedModules);
|
|
$this->assertEquals([], $aSelectedModules, "there should be no more modules remaining apart from below lists");
|
|
}
|
|
|
|
private function checkModuleList(string $sModuleCategory, array $aExpectedModuleList, array &$aSelectedModules) {
|
|
$aMissingModules = [];
|
|
|
|
foreach ($aExpectedModuleList as $sModuleId){
|
|
if (! array_key_exists($sModuleId, $aSelectedModules)){
|
|
$aMissingModules[]=$sModuleId;
|
|
} else {
|
|
unset($aSelectedModules[$sModuleId]);
|
|
}
|
|
}
|
|
|
|
$this->assertEquals([], $aMissingModules, "$sModuleCategory modules are missing");
|
|
|
|
}
|
|
|
|
public function ProductionModulesProvider() {
|
|
return [
|
|
'module autoload as located in production-modules' => [ true ],
|
|
'module not loaded' => [ false ],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider ProductionModulesProvider
|
|
*/
|
|
public function testGetAllSelectedModules_ProductionModules(bool $bModuleInProductionModulesFolder) {
|
|
$sModuleId = "itop-problem-mgmt";
|
|
if ($bModuleInProductionModulesFolder){
|
|
if (! is_dir(APPROOT."data/production-modules")){
|
|
@mkdir(APPROOT."data/production-modules");
|
|
}
|
|
|
|
$this->RecurseMoveDir(APPROOT . "datamodels/2.x/$sModuleId", APPROOT."data/production-modules/$sModuleId");
|
|
}
|
|
|
|
$sPath = realpath(dirname(__FILE__, 6)."/datamodels/2.x/installation.xml");
|
|
$oInstallationFileService = new \InstallationFileService($sPath, 'production', [], false);
|
|
$oInstallationFileService->Init();
|
|
|
|
$aSelectedModules = $oInstallationFileService->GetSelectedModules();
|
|
$this->assertEquals($bModuleInProductionModulesFolder, array_key_exists($sModuleId, $aSelectedModules));
|
|
}
|
|
|
|
private function RecurseMoveDir($sFromDir, $sToDir) {
|
|
if (! is_dir($sFromDir)){
|
|
return;
|
|
}
|
|
|
|
if (! is_dir($sToDir)){
|
|
@mkdir($sToDir);
|
|
}
|
|
|
|
foreach (glob("$sFromDir/*") as $sPath){
|
|
$sToPath = $sToDir.'/'.basename($sPath);
|
|
if (is_file($sPath)){
|
|
@rename($sPath, $sToPath);
|
|
} else {
|
|
$this->RecurseMoveDir($sPath, $sToPath);
|
|
}
|
|
}
|
|
|
|
@rmdir($sFromDir);
|
|
}
|
|
}
|