mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Merge branch 'support/3.1' into support/3.2
This commit is contained in:
@@ -2,31 +2,133 @@
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Setup\UnattendedInstall;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
||||
use ItopExtensionsMap;
|
||||
use iTopExtension;
|
||||
use RunTimeEnvironment;
|
||||
use InstallationFileService;
|
||||
use ModuleDiscovery;
|
||||
|
||||
/**
|
||||
* @group itop-clone-only
|
||||
*/
|
||||
class InstallationFileServiceTest extends TestCase {
|
||||
class InstallationFileServiceTest extends ItopTestCase {
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
require_once(dirname(__FILE__, 6) . '/setup/unattended-install/InstallationFileService.php');
|
||||
$this->sFolderToCleanup = null;
|
||||
\ModuleDiscovery::ResetCache();
|
||||
|
||||
$this->RequireOnceItopFile('/setup/unattended-install/InstallationFileService.php');
|
||||
ModuleDiscovery::ResetCache();
|
||||
}
|
||||
|
||||
protected function tearDown(): void {
|
||||
parent::tearDown();
|
||||
|
||||
$sModuleId = "itop-problem-mgmt";
|
||||
$this->RecurseMoveDir(APPROOT."data/production-modules/$sModuleId", APPROOT . "datamodels/2.x/$sModuleId");
|
||||
}
|
||||
|
||||
private function GetInstallationPath() {
|
||||
return realpath(__DIR__ . '/installation.xml');
|
||||
private function GetInstallationPath() : string {
|
||||
return realpath(__DIR__ . '/resources/installation.xml');
|
||||
}
|
||||
|
||||
public function GetDefaultModulesProvider() {
|
||||
private function GetModuleData($sCategory, bool $bIsVisible, bool $bIsAutoSelect, bool $bProductionModulesInRootDir=false) : array {
|
||||
$sRootDir = str_replace('//', '/', $bProductionModulesInRootDir ? $this->GetAppRoot() .'data/production-modules/' : '');
|
||||
|
||||
var_dump($sRootDir);
|
||||
|
||||
$aModuleData = [
|
||||
'category' => $sCategory,
|
||||
'visible' => $bIsVisible,
|
||||
'root_dir' => $sRootDir,
|
||||
];
|
||||
|
||||
if ($bIsAutoSelect){
|
||||
$aModuleData['auto_select'] = true;
|
||||
}
|
||||
|
||||
return $aModuleData;
|
||||
}
|
||||
|
||||
public function ProcessDefaultModulesProvider() {
|
||||
return [
|
||||
'root module' => [
|
||||
'aAllFoundModules' => [
|
||||
'_Root_' => $this->GetModuleData('authentication', false, false, true),
|
||||
],
|
||||
'aExpectedSelectedModules' => [],
|
||||
'aExpectedAutoSelectModules' => [],
|
||||
],
|
||||
'auto-select root module' => [
|
||||
'aAllFoundModules' => [
|
||||
'_Root_' => $this->GetModuleData('authentication', false, true, true),
|
||||
],
|
||||
'aExpectedSelectedModules' => [],
|
||||
'aExpectedAutoSelectModules' => [],
|
||||
],
|
||||
'autoselect module only' => [
|
||||
'aAllFoundModules' => [
|
||||
'autoselect-only' => $this->GetModuleData('mycategory', true, true),
|
||||
],
|
||||
'aExpectedSelectedModules' => [],
|
||||
'aExpectedAutoSelectModules' => ['autoselect-only'],
|
||||
],
|
||||
'autoselect/invisible module' => [
|
||||
'aAllFoundModules' => [
|
||||
'autoselect-only' => $this->GetModuleData('mycategory', false, true),
|
||||
],
|
||||
'aExpectedSelectedModules' => [],
|
||||
'aExpectedAutoSelectModules' => ['autoselect-only'],
|
||||
],
|
||||
'autoselect/invisible/in-root-dir module' => [
|
||||
'aAllFoundModules' => [
|
||||
'autoselect-only' => $this->GetModuleData('mycategory', false, true , true),
|
||||
],
|
||||
'aExpectedSelectedModules' => [],
|
||||
'aExpectedAutoSelectModules' => ['autoselect-only'],
|
||||
],
|
||||
'visible/authent module' => [
|
||||
'aAllFoundModules' => [
|
||||
'authent-module' => $this->GetModuleData('authentication', true, false , false),
|
||||
],
|
||||
'aExpectedSelectedModules' => ['authent-module'],
|
||||
'aExpectedAutoSelectModules' => [],
|
||||
],
|
||||
'invisible module' => [
|
||||
'aAllFoundModules' => [
|
||||
'visible-module' => $this->GetModuleData('mycategory', false, false , false),
|
||||
],
|
||||
'aExpectedSelectedModules' => ['visible-module'],
|
||||
'aExpectedAutoSelectModules' => [],
|
||||
],
|
||||
'in-root-dir module' => [
|
||||
'aAllFoundModules' => [
|
||||
'in-root-dir-module' => $this->GetModuleData('mycategory', true, false , true),
|
||||
],
|
||||
'aExpectedSelectedModules' => ['in-root-dir-module'],
|
||||
'aExpectedAutoSelectModules' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
/**
|
||||
* @dataProvider ProcessDefaultModulesProvider
|
||||
*/
|
||||
public function testProcessDefaultModules(array $aAllFoundModules, array $aExpectedSelectedModules, array $aExpectedAutoSelectModules) {
|
||||
$oInstallationFileService = new InstallationFileService('', 'production', [], true);
|
||||
|
||||
$oProductionEnv = $this->createMock(RunTimeEnvironment::class);
|
||||
$oProductionEnv->expects($this->once())
|
||||
->method('AnalyzeInstallation')
|
||||
->willReturn($aAllFoundModules);
|
||||
|
||||
$oInstallationFileService->SetProductionEnv($oProductionEnv);
|
||||
$oInstallationFileService->ProcessDefaultModules();
|
||||
|
||||
sort($aExpectedSelectedModules);
|
||||
$aModules = array_keys($oInstallationFileService->GetSelectedModules());
|
||||
sort($aModules);
|
||||
|
||||
$this->assertEquals($aExpectedSelectedModules, $aModules);
|
||||
|
||||
$aAutoSelectModules = array_keys($oInstallationFileService->GetAutoSelectModules());
|
||||
sort($aAutoSelectModules);
|
||||
$this->assertEquals($aExpectedAutoSelectModules, $aAutoSelectModules);
|
||||
}
|
||||
|
||||
public function ProcessInstallationChoicesProvider() {
|
||||
return [
|
||||
'all checked' => [ true ],
|
||||
'only defaut + mandatory' => [ false ],
|
||||
@@ -34,12 +136,16 @@ class InstallationFileServiceTest extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider GetDefaultModulesProvider
|
||||
* @dataProvider ProcessInstallationChoicesProvider
|
||||
*/
|
||||
public function testProcessInstallationChoices($bInstallationOptionalChoicesChecked=false) {
|
||||
$sPath = realpath($this->GetInstallationPath());
|
||||
$this->assertTrue(is_file($sPath));
|
||||
$oInstallationFileService = new \InstallationFileService($sPath, 'production', [], $bInstallationOptionalChoicesChecked);
|
||||
public function testProcessInstallationChoices($bInstallationOptionalChoicesChecked) {
|
||||
$sPath = $this->GetInstallationPath();
|
||||
$oInstallationFileService = new InstallationFileService($sPath, 'production', [], $bInstallationOptionalChoicesChecked);
|
||||
$oProductionEnv = $this->createMock(RunTimeEnvironment::class);
|
||||
$oProductionEnv->expects($this->never())
|
||||
->method('AnalyzeInstallation');
|
||||
$oInstallationFileService->SetProductionEnv($oProductionEnv);
|
||||
|
||||
$oInstallationFileService->ProcessInstallationChoices();
|
||||
$aExpectedModules = [
|
||||
"itop-config-mgmt",
|
||||
@@ -88,23 +194,127 @@ class InstallationFileServiceTest extends TestCase {
|
||||
sort($aExpectedUnselectedModules);
|
||||
sort($aUnselectedModules);
|
||||
$this->assertEquals($aExpectedUnselectedModules, $aUnselectedModules);
|
||||
|
||||
$aGetAfterComputationSelectedExtensions = $oInstallationFileService->GetAfterComputationSelectedExtensions();
|
||||
sort($aGetAfterComputationSelectedExtensions);
|
||||
$aExpectedExtensions = [
|
||||
'itop-change-mgmt-simple',
|
||||
'itop-config-mgmt-core',
|
||||
'itop-config-mgmt-datacenter',
|
||||
'itop-config-mgmt-end-user',
|
||||
'itop-config-mgmt-storage',
|
||||
'itop-config-mgmt-virtualization',
|
||||
'itop-service-mgmt-enterprise',
|
||||
'itop-ticket-mgmt-simple-ticket',
|
||||
'itop-ticket-mgmt-simple-ticket-enhanced-portal',
|
||||
];
|
||||
if ($bInstallationOptionalChoicesChecked){
|
||||
$aExpectedExtensions []= "itop-problem-mgmt";
|
||||
$aExpectedExtensions []= 'itop-kown-error-mgmt';
|
||||
}
|
||||
sort($aExpectedExtensions);
|
||||
$this->assertEquals($aExpectedExtensions, $aGetAfterComputationSelectedExtensions);
|
||||
|
||||
$this->ValidateNonItilExtensionComputation($oInstallationFileService, $bInstallationOptionalChoicesChecked);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider ItilExtensionProvider
|
||||
*/
|
||||
public function testProcessInstallationChoicesWithItilChoices(array $aSelectedExtensions, bool $bKnownMgtSelected, bool $bCoreMgtSelected) {
|
||||
$sPath = $this->GetInstallationPath();
|
||||
$oInstallationFileService = new InstallationFileService($sPath, 'production', $aSelectedExtensions, false);
|
||||
$oProductionEnv = $this->createMock(RunTimeEnvironment::class);
|
||||
$oProductionEnv->expects($this->never())
|
||||
->method('AnalyzeInstallation');
|
||||
$oInstallationFileService->SetProductionEnv($oProductionEnv);
|
||||
|
||||
$oInstallationFileService->ProcessInstallationChoices();
|
||||
|
||||
$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",
|
||||
];
|
||||
if ($bKnownMgtSelected){
|
||||
$aExpectedInstallationModules []= "itop-knownerror-mgmt";
|
||||
}
|
||||
|
||||
sort($aExpectedInstallationModules);
|
||||
$aModules = array_keys($oInstallationFileService->GetSelectedModules());
|
||||
sort($aModules);
|
||||
|
||||
$this->assertEquals($aExpectedInstallationModules, $aModules);
|
||||
|
||||
$aExpectedUnselectedModules = [
|
||||
'itop-change-mgmt',
|
||||
'itop-problem-mgmt',
|
||||
'itop-request-mgmt',
|
||||
'itop-service-mgmt-provider',
|
||||
];
|
||||
if (!$bKnownMgtSelected){
|
||||
$aExpectedUnselectedModules[]='itop-knownerror-mgmt';
|
||||
}
|
||||
$aUnselectedModules = array_keys($oInstallationFileService->GetUnSelectedModules());
|
||||
sort($aExpectedUnselectedModules);
|
||||
sort($aUnselectedModules);
|
||||
$this->assertEquals($aExpectedUnselectedModules, $aUnselectedModules);
|
||||
|
||||
$this->ValidateItilExtensionComputation($oInstallationFileService, $bKnownMgtSelected, $bCoreMgtSelected);
|
||||
}
|
||||
|
||||
public function GetDefaultModulesProvider() {
|
||||
return [
|
||||
'check all possible modules' => [true],
|
||||
'only minimum defaul/mandatory from installation.xml' => [false],
|
||||
];
|
||||
}
|
||||
|
||||
private function GetMockListOfFoundModules() : array {
|
||||
$sJsonContent = file_get_contents(realpath(__DIR__ . '/resources/AnalyzeInstallation.json'));
|
||||
$sJsonContent = str_replace('ROOTDIR_TOREPLACE', APPROOT, $sJsonContent);
|
||||
return json_decode($sJsonContent, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider GetDefaultModulesProvider
|
||||
*/
|
||||
public function testGetAllSelectedModules($bInstallationOptionalChoicesChecked=false) {
|
||||
$sPath = realpath($this->GetInstallationPath());
|
||||
$oInstallationFileService = new \InstallationFileService($sPath, 'production', [], $bInstallationOptionalChoicesChecked);
|
||||
$sPath = $this->GetInstallationPath();
|
||||
$oInstallationFileService = new InstallationFileService($sPath, 'production', [], $bInstallationOptionalChoicesChecked);
|
||||
|
||||
$oProductionEnv = $this->createMock(RunTimeEnvironment::class);
|
||||
$oProductionEnv->expects($this->once())
|
||||
->method('AnalyzeInstallation')
|
||||
->willReturn($this->GetMockListOfFoundModules());
|
||||
$oInstallationFileService->SetProductionEnv($oProductionEnv);
|
||||
|
||||
$oItopExtensionsMap = $this->createMock(ItopExtensionsMap::class);
|
||||
$oItopExtensionsMap->expects($this->once())
|
||||
->method('GetAllExtensions')
|
||||
->willReturn([]);
|
||||
$oInstallationFileService->SetItopExtensionsMap($oItopExtensionsMap);
|
||||
|
||||
$oInstallationFileService->Init();
|
||||
|
||||
$aSelectedModules = $oInstallationFileService->GetSelectedModules();
|
||||
$aExpectedInstallationModules = [
|
||||
'combodo-backoffice-darkmoon-theme',
|
||||
'combodo-backoffice-fullmoon-high-contrast-theme',
|
||||
'combodo-backoffice-fullmoon-protanopia-deuteranopia-theme',
|
||||
'combodo-backoffice-fullmoon-tritanopia-theme',
|
||||
'itop-structure',
|
||||
"itop-config-mgmt",
|
||||
"itop-attachments",
|
||||
"itop-profiles-itil",
|
||||
@@ -124,40 +334,75 @@ class InstallationFileServiceTest extends TestCase {
|
||||
"itop-portal",
|
||||
"itop-portal-base",
|
||||
"itop-change-mgmt",
|
||||
'authent-cas',
|
||||
'authent-external',
|
||||
'authent-ldap',
|
||||
'authent-local',
|
||||
'itop-backup',
|
||||
'itop-config',
|
||||
'itop-sla-computation',
|
||||
'itop-bridge-virtualization-storage',
|
||||
];
|
||||
|
||||
if ($bInstallationOptionalChoicesChecked){
|
||||
$aExpectedInstallationModules []= "itop-problem-mgmt";
|
||||
$aExpectedInstallationModules []= "itop-knownerror-mgmt";
|
||||
}
|
||||
|
||||
$aExpectedAuthenticationModules = [
|
||||
'authent-cas',
|
||||
'authent-external',
|
||||
'authent-ldap',
|
||||
'authent-local',
|
||||
];
|
||||
sort($aExpectedInstallationModules);
|
||||
|
||||
$aUnvisibleModules = [
|
||||
'itop-backup',
|
||||
'itop-config',
|
||||
'itop-sla-computation',
|
||||
];
|
||||
$aSelectedModules = array_keys($oInstallationFileService->GetSelectedModules());
|
||||
sort($aSelectedModules);
|
||||
$this->assertEquals($aExpectedInstallationModules, $aSelectedModules);
|
||||
|
||||
$aAutoSelectedModules = [
|
||||
'itop-bridge-cmdb-services',
|
||||
'itop-bridge-virtualization-storage',
|
||||
'itop-bridge-cmdb-ticket',
|
||||
'itop-bridge-datacenter-mgmt-services',
|
||||
'itop-bridge-endusers-devices-services',
|
||||
'itop-bridge-storage-mgmt-services',
|
||||
'itop-bridge-virtualization-mgmt-services',
|
||||
];
|
||||
$this->ValidateNonItilExtensionComputation($oInstallationFileService, $bInstallationOptionalChoicesChecked);
|
||||
}
|
||||
|
||||
$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 ValidateNonItilExtensionComputation($oInstallationFileService, bool $bInstallationOptionalChoicesChecked, array $aAdditionalExtensions=[]) {
|
||||
$aGetAfterComputationSelectedExtensions = $oInstallationFileService->GetAfterComputationSelectedExtensions();
|
||||
sort($aGetAfterComputationSelectedExtensions);
|
||||
$aExpectedExtensions = array_merge($aAdditionalExtensions, [
|
||||
'itop-change-mgmt-simple',
|
||||
'itop-config-mgmt-core',
|
||||
'itop-config-mgmt-datacenter',
|
||||
'itop-config-mgmt-end-user',
|
||||
'itop-config-mgmt-storage',
|
||||
'itop-config-mgmt-virtualization',
|
||||
'itop-service-mgmt-enterprise',
|
||||
'itop-ticket-mgmt-simple-ticket',
|
||||
'itop-ticket-mgmt-simple-ticket-enhanced-portal',
|
||||
]);
|
||||
if ($bInstallationOptionalChoicesChecked){
|
||||
$aExpectedExtensions []= "itop-problem-mgmt";
|
||||
$aExpectedExtensions []= 'itop-kown-error-mgmt';
|
||||
}
|
||||
sort($aExpectedExtensions);
|
||||
$this->assertEquals($aExpectedExtensions, $aGetAfterComputationSelectedExtensions);
|
||||
}
|
||||
|
||||
private function ValidateItilExtensionComputation($oInstallationFileService, bool $bKnownMgtSelected, bool $bCoreMgtSelected) {
|
||||
$aGetAfterComputationSelectedExtensions = $oInstallationFileService->GetAfterComputationSelectedExtensions();
|
||||
sort($aGetAfterComputationSelectedExtensions);
|
||||
$aExpectedExtensions = [
|
||||
'itop-change-mgmt-itil',
|
||||
'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-enhanced-portal',
|
||||
'itop-ticket-mgmt-itil-incident',
|
||||
'itop-ticket-mgmt-itil-user-request',
|
||||
];
|
||||
if ($bCoreMgtSelected){
|
||||
$aExpectedExtensions []= 'itop-config-mgmt-core';
|
||||
}
|
||||
if ($bKnownMgtSelected){
|
||||
$aExpectedExtensions []= 'itop-kown-error-mgmt';
|
||||
}
|
||||
sort($aExpectedExtensions);
|
||||
$this->assertEquals($aExpectedExtensions, $aGetAfterComputationSelectedExtensions);
|
||||
}
|
||||
|
||||
private function GetSelectedItilExtensions(bool $coreExtensionIncluded, bool $bKnownMgtIncluded) : array {
|
||||
@@ -191,18 +436,22 @@ class InstallationFileServiceTest extends TestCase {
|
||||
'all itil extensions + INCLUDING known-error-mgt' => [
|
||||
'aSelectedExtensions' => $this->GetSelectedItilExtensions(true, true),
|
||||
'bKnownMgtSelected' => true,
|
||||
'bCoreMgtSelected' => true,
|
||||
],
|
||||
'all itil extensions WITHOUT known-error-mgt' => [
|
||||
'aSelectedExtensions' => $this->GetSelectedItilExtensions(true, false),
|
||||
'bKnownMgtSelected' => false,
|
||||
'bCoreMgtSelected' => true,
|
||||
],
|
||||
'all itil extensions WITHOUT core mandatory ones + INCLUDING known-error-mgt' => [
|
||||
'aSelectedExtensions' => $this->GetSelectedItilExtensions(false, true),
|
||||
'bKnownMgtSelected' => true,
|
||||
'bCoreMgtSelected' => false,
|
||||
],
|
||||
'all itil extensions WITHOUT core mandatory ones and WITHOUT known-error-mgt' => [
|
||||
'aSelectedExtensions' => $this->GetSelectedItilExtensions(false, false),
|
||||
'bKnownMgtSelected' => false,
|
||||
'bCoreMgtSelected' => false,
|
||||
],
|
||||
];
|
||||
}
|
||||
@@ -210,18 +459,26 @@ class InstallationFileServiceTest extends TestCase {
|
||||
/**
|
||||
* @dataProvider ItilExtensionProvider
|
||||
*/
|
||||
public function testGetAllSelectedModules_withItilExtensions(array $aSelectedExtensions, bool $bKnownMgtSelected) {
|
||||
$sPath = realpath($this->GetInstallationPath());
|
||||
$oInstallationFileService = new \InstallationFileService($sPath, 'production', $aSelectedExtensions);
|
||||
public function testGetAllSelectedModules_withItilExtensions(array $aSelectedExtensions, bool $bKnownMgtSelected, bool $bCoreMgtSelected) {
|
||||
$sPath = $this->GetInstallationPath();
|
||||
$oInstallationFileService = new InstallationFileService($sPath, 'production', $aSelectedExtensions);
|
||||
|
||||
$oProductionEnv = $this->createMock(RunTimeEnvironment::class);
|
||||
$oProductionEnv->expects($this->once())
|
||||
->method('AnalyzeInstallation')
|
||||
->willReturn($this->GetMockListOfFoundModules());
|
||||
$oInstallationFileService->SetProductionEnv($oProductionEnv);
|
||||
|
||||
$oItopExtensionsMap = $this->createMock(ItopExtensionsMap::class);
|
||||
$oItopExtensionsMap->expects($this->once())
|
||||
->method('GetAllExtensions')
|
||||
->willReturn([]);
|
||||
$oInstallationFileService->SetItopExtensionsMap($oItopExtensionsMap);
|
||||
|
||||
$oInstallationFileService->Init();
|
||||
|
||||
$aSelectedModules = $oInstallationFileService->GetSelectedModules();
|
||||
$aSelectedModules = array_keys($oInstallationFileService->GetSelectedModules());
|
||||
$aExpectedInstallationModules = [
|
||||
'combodo-backoffice-darkmoon-theme',
|
||||
'combodo-backoffice-fullmoon-high-contrast-theme',
|
||||
'combodo-backoffice-fullmoon-protanopia-deuteranopia-theme',
|
||||
'combodo-backoffice-fullmoon-tritanopia-theme',
|
||||
'itop-structure',
|
||||
"itop-config-mgmt",
|
||||
"itop-attachments",
|
||||
"itop-profiles-itil",
|
||||
@@ -243,102 +500,247 @@ class InstallationFileServiceTest extends TestCase {
|
||||
"itop-portal-base",
|
||||
"itop-change-mgmt-itil",
|
||||
"itop-full-itil",
|
||||
'authent-cas',
|
||||
'authent-external',
|
||||
'authent-ldap',
|
||||
'authent-local',
|
||||
'itop-backup',
|
||||
'itop-config',
|
||||
'itop-sla-computation',
|
||||
'itop-bridge-virtualization-storage',
|
||||
];
|
||||
if ($bKnownMgtSelected){
|
||||
$aExpectedInstallationModules []= "itop-knownerror-mgmt";
|
||||
}
|
||||
|
||||
$aExpectedAuthenticationModules = [
|
||||
'authent-cas',
|
||||
'authent-external',
|
||||
'authent-ldap',
|
||||
'authent-local',
|
||||
];
|
||||
sort($aExpectedInstallationModules);
|
||||
sort($aSelectedModules);
|
||||
$this->assertEquals($aExpectedInstallationModules, $aSelectedModules);
|
||||
|
||||
$aUnvisibleModules = [
|
||||
'itop-backup',
|
||||
'itop-config',
|
||||
'itop-sla-computation',
|
||||
];
|
||||
|
||||
$aAutoSelectedModules = [
|
||||
'itop-bridge-cmdb-services',
|
||||
'itop-bridge-virtualization-storage',
|
||||
'itop-bridge-cmdb-ticket',
|
||||
'itop-bridge-datacenter-mgmt-services',
|
||||
'itop-bridge-endusers-devices-services',
|
||||
'itop-bridge-storage-mgmt-services',
|
||||
'itop-bridge-virtualization-mgmt-services',
|
||||
];
|
||||
|
||||
$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");
|
||||
$this->ValidateItilExtensionComputation($oInstallationFileService, $bKnownMgtSelected, $bCoreMgtSelected);
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
private function CreateItopExtension(string $sSource, string $sCode, array $aModules, array $aMissingDependencies, bool $bIsVisible) : iTopExtension{
|
||||
$oExtension = new iTopExtension();
|
||||
$oExtension->sCode = $sCode;
|
||||
$oExtension->sSource = $sSource;
|
||||
$oExtension->aModules = $aModules;
|
||||
$oExtension->aMissingDependencies = $aMissingDependencies;
|
||||
$oExtension->bVisible = $bIsVisible;
|
||||
return $oExtension;
|
||||
}
|
||||
|
||||
public function ProductionModulesProvider() {
|
||||
public function CanChooseUnpackageExtensionProvider() {
|
||||
return [
|
||||
'module autoload as located in production-modules' => [ true ],
|
||||
'module not loaded' => [ false ],
|
||||
'extension in SOURCE_REMOTE' => [
|
||||
'sCode' => "extension-from-designer",
|
||||
'bInstallationOptionalChoicesChecked' => false,
|
||||
'sSource' => 'data',
|
||||
'bExpectedRes' => true
|
||||
],
|
||||
'extension in SOURCE_WIZARD' => [
|
||||
'sCode' => 'extension-from-package',
|
||||
'bInstallationOptionalChoicesChecked' => true,
|
||||
'sSource' => 'datamodels',
|
||||
'bExpectedRes' => false
|
||||
],
|
||||
'extension in SOURCE_MANUAL + optional OK' => [
|
||||
'sCode' => 'extension-from-package',
|
||||
'bInstallationOptionalChoicesChecked' => true,
|
||||
'sSource' => 'extensions',
|
||||
'bExpectedRes' => true
|
||||
],
|
||||
'extension in SOURCE_MANUAL + optional NOT OK' => [
|
||||
'sCode' => 'extension-from-package',
|
||||
'bInstallationOptionalChoicesChecked' => false,
|
||||
'sSource' => 'extensions',
|
||||
'bExpectedRes' => false
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider ProductionModulesProvider
|
||||
* @dataProvider CanChooseUnpackageExtensionProvider
|
||||
*/
|
||||
public function testGetAllSelectedModules_ProductionModules(bool $bModuleInProductionModulesFolder) {
|
||||
$sModuleId = "itop-problem-mgmt";
|
||||
if ($bModuleInProductionModulesFolder){
|
||||
if (! is_dir(APPROOT."data/production-modules")){
|
||||
@mkdir(APPROOT."data/production-modules");
|
||||
}
|
||||
public function testCanChooseUnpackageExtension(string $sCode, bool $bInstallationOptionalChoicesChecked, string $sSource, bool $bExpectedRes) {
|
||||
$sPath = $this->GetInstallationPath();
|
||||
$oInstallationFileService = new InstallationFileService($sPath, 'production', [], $bInstallationOptionalChoicesChecked);
|
||||
|
||||
$this->RecurseMoveDir(APPROOT . "datamodels/2.x/$sModuleId", APPROOT."data/production-modules/$sModuleId");
|
||||
$oItopExtension = $this->CreateItopExtension($sSource, $sCode, [], [], true);
|
||||
$this->assertEquals($bExpectedRes, $oInstallationFileService->CanChooseUnpackageExtension($oItopExtension));
|
||||
}
|
||||
|
||||
public function ProcessExtensionModulesNotSpecifiedInChoicesProvider() {
|
||||
return [
|
||||
'extensions to install OK' => [
|
||||
'aExtensionData' => [
|
||||
'extension1' => [
|
||||
//'itop-request-mgmt-itil', //unselected
|
||||
'combodo-monitoring',
|
||||
'itop-config-mgmt', //already selected
|
||||
],
|
||||
'extension2' => [
|
||||
//'itop-incident-mgmt-itil', //unselected
|
||||
'combodo-monitoring2',
|
||||
'itop-attachments', //already selected
|
||||
]
|
||||
],
|
||||
'bExtensionCanBeChoosen' => true,
|
||||
'aMissingDependencies' => [],
|
||||
'bIsVisible' => true,
|
||||
'bExpectedAdditionalExtensions' => [
|
||||
'extension1', 'extension2'
|
||||
],
|
||||
'bExpectedAdditionalModules' => [
|
||||
'combodo-monitoring', 'combodo-monitoring2'
|
||||
]
|
||||
],
|
||||
'extensions to install cannot be choose,' => [
|
||||
'aExtensionData' => [
|
||||
'extension1' => [
|
||||
'combodo-monitoring',
|
||||
],
|
||||
'extension2' => [
|
||||
'combodo-monitoring2',
|
||||
]
|
||||
],
|
||||
'bExtensionCanBeChoosen' => false,
|
||||
'aMissingDependencies' => [],
|
||||
'bIsVisible' => true,
|
||||
'bExpectedAdditionalExtensions' => [],
|
||||
'bExpectedAdditionalModules' => []
|
||||
],
|
||||
'extensions to install not visible' => [
|
||||
'aExtensionData' => [
|
||||
'extension1' => [
|
||||
'combodo-monitoring',
|
||||
],
|
||||
'extension2' => [
|
||||
'combodo-monitoring2',
|
||||
]
|
||||
],
|
||||
'bExtensionCanBeChoosen' => true,
|
||||
'aMissingDependencies' => [],
|
||||
'bIsVisible' => false,
|
||||
'bExpectedAdditionalExtensions' => [],
|
||||
'bExpectedAdditionalModules' => []
|
||||
],
|
||||
'extensions to install with missing dependencies' => [
|
||||
'aExtensionData' => [
|
||||
'extension1' => [
|
||||
'combodo-monitoring',
|
||||
],
|
||||
'extension2' => [
|
||||
'combodo-monitoring2',
|
||||
]
|
||||
],
|
||||
'bExtensionCanBeChoosen' => true,
|
||||
'aMissingDependencies' => ['missing-module'],
|
||||
'bIsVisible' => true,
|
||||
'bExpectedAdditionalExtensions' => [],
|
||||
'bExpectedAdditionalModules' => []
|
||||
],
|
||||
'extensions to install with unselectable ITIL module' => [
|
||||
'aExtensionData' => [
|
||||
'extension1' => [
|
||||
'itop-request-mgmt-itil', //unselected
|
||||
'combodo-monitoring',
|
||||
],
|
||||
'extension2' => [
|
||||
'itop-incident-mgmt-itil', //unselected
|
||||
'combodo-monitoring2',
|
||||
]
|
||||
],
|
||||
'bExtensionCanBeChoosen' => true,
|
||||
'aMissingDependencies' => [],
|
||||
'bIsVisible' => true,
|
||||
'bExpectedAdditionalExtensions' => [],
|
||||
'bExpectedAdditionalModules' => []
|
||||
],
|
||||
'extensions already processed' => [
|
||||
'aExtensionData' => [
|
||||
'itop-config-mgmt-core' => [
|
||||
'itop-config-mgmt', //already selected
|
||||
],
|
||||
],
|
||||
'bExtensionCanBeChoosen' => true,
|
||||
'aMissingDependencies' => [],
|
||||
'bIsVisible' => true,
|
||||
'bExpectedAdditionalExtensions' => [
|
||||
],
|
||||
'bExpectedAdditionalModules' => [
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider ProcessExtensionModulesNotSpecifiedInChoicesProvider
|
||||
*/
|
||||
public function testProcessExtensionModulesNotSpecifiedInChoices(array $aExtensionData, bool $bExtensionCanBeChoosen,
|
||||
array $aMissingDependencies, bool $bIsVisible, array $bExpectedAdditionalExtensions, array $bExpectedAdditionalModules) {
|
||||
$sPath = $this->GetInstallationPath();
|
||||
$oInstallationFileService = new InstallationFileService($sPath, 'production', [], true);
|
||||
|
||||
$oProductionEnv = $this->createMock(RunTimeEnvironment::class);
|
||||
$oProductionEnv->expects($this->once())
|
||||
->method('AnalyzeInstallation')
|
||||
->willReturn($this->GetMockListOfFoundModules());
|
||||
$oInstallationFileService->SetProductionEnv($oProductionEnv);
|
||||
|
||||
$oItopExtensionsMap = $this->createMock(ItopExtensionsMap::class);
|
||||
$aItopExtensionMap = [];
|
||||
|
||||
$sSource = $bExtensionCanBeChoosen ? iTopExtension::SOURCE_REMOTE : iTopExtension::SOURCE_WIZARD;
|
||||
foreach ($aExtensionData as $sExtensionCode => $aModules){
|
||||
$aItopExtensionMap[]= $this->CreateItopExtension($sSource, $sExtensionCode, $aModules, $aMissingDependencies, $bIsVisible);
|
||||
}
|
||||
$oItopExtensionsMap->expects($this->once())
|
||||
->method('GetAllExtensions')
|
||||
->willReturn($aItopExtensionMap);
|
||||
$oInstallationFileService->SetItopExtensionsMap($oItopExtensionsMap);
|
||||
|
||||
$sPath = realpath($this->GetInstallationPath());
|
||||
$oInstallationFileService = new \InstallationFileService($sPath, 'production', [], false);
|
||||
$oInstallationFileService->Init();
|
||||
|
||||
$aSelectedModules = $oInstallationFileService->GetSelectedModules();
|
||||
$this->assertEquals($bModuleInProductionModulesFolder, array_key_exists($sModuleId, $aSelectedModules));
|
||||
$aSelectedModules = array_keys($oInstallationFileService->GetSelectedModules());
|
||||
sort($aSelectedModules);
|
||||
$aExpectedInstallationModules = array_merge($bExpectedAdditionalModules, [
|
||||
"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",
|
||||
"itop-problem-mgmt",
|
||||
"itop-knownerror-mgmt",
|
||||
'authent-cas',
|
||||
'authent-external',
|
||||
'authent-ldap',
|
||||
'authent-local',
|
||||
'itop-backup',
|
||||
'itop-config',
|
||||
'itop-sla-computation',
|
||||
'itop-bridge-virtualization-storage',
|
||||
]);
|
||||
sort($aExpectedInstallationModules);
|
||||
|
||||
$this->assertEquals($aExpectedInstallationModules, $aSelectedModules);
|
||||
|
||||
$this->ValidateNonItilExtensionComputation($oInstallationFileService, true, $bExpectedAdditionalExtensions);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user