mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
Merge branch 'support/2.7' into support/3.0
# Conflicts: # setup/applicationinstaller.class.inc.php # setup/modulediscovery.class.inc.php # setup/runtimeenv.class.inc.php # setup/unattended-install/unattended-install.php # tests/setup_params/default-params.xml
This commit is contained in:
@@ -0,0 +1,315 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -63,9 +63,12 @@ class UnattendedInstallTest extends ItopDataTestCase
|
||||
}
|
||||
|
||||
public function testCallUnattendedInstallFromCLI() {
|
||||
$cliPath = realpath(APPROOT."/setup/unattended-install/unattended-install.php");
|
||||
$res = exec("php ".$cliPath);
|
||||
$sCliPath = realpath(APPROOT."/setup/unattended-install/unattended-install.php");
|
||||
exec(sprintf("%s %s", PHP_BINARY, $sCliPath), $aOutput, $iCode);
|
||||
|
||||
$this->assertEquals("Param file `default-params.xml` doesn't exist ! Exiting...", $res);
|
||||
$sOutput = implode('\n', $aOutput);
|
||||
var_dump($sOutput);
|
||||
$this->assertStringContainsString("Missing mandatory argument `--param-file`", $sOutput);
|
||||
$this->assertEquals(255, $iCode);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user