mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
212 lines
6.4 KiB
PHP
212 lines
6.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @copyright Copyright (C) 2010-2025 Combodo SARL
|
|
* @license http://opensource.org/licenses/AGPL-3.0
|
|
*/
|
|
|
|
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
|
|
|
class InstallationChoicesServiceTest extends ItopDataTestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->RequireOnceItopFile('/setup/moduleinstallation/InstallationChoicesService.php');
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
parent::tearDown();
|
|
ModuleDiscovery::ResetCache();
|
|
}
|
|
|
|
public function NonItilExtensionProvider()
|
|
{
|
|
return [
|
|
'all NON ITIL extensions + INCLUDING known-error-mgt' => [
|
|
'aInstallationChoices' => $this->GetSelectedNonItilExtensions(true, true),
|
|
'bKnownMgtSelected' => true,
|
|
'bCoreMgtSelected' => true,
|
|
],
|
|
/*'all NON ITIL extensions WITHOUT known-error-mgt' => [
|
|
'aInstallationChoices' => $this->GetSelectedNonItilExtensions(true, false),
|
|
'bKnownMgtSelected' => false,
|
|
'bCoreMgtSelected' => true,
|
|
],
|
|
'all NON ITIL extensions WITHOUT core mandatory ones + INCLUDING known-error-mgt' => [
|
|
'aInstallationChoices' => $this->GetSelectedNonItilExtensions(false, true),
|
|
'bKnownMgtSelected' => true,
|
|
'bCoreMgtSelected' => false,
|
|
],
|
|
'all NON ITIL extensions WITHOUT core mandatory ones and WITHOUT known-error-mgt' => [
|
|
'aInstallationChoices' => $this->GetSelectedNonItilExtensions(false, false),
|
|
'bKnownMgtSelected' => false,
|
|
'bCoreMgtSelected' => false,
|
|
],*/
|
|
];
|
|
}
|
|
|
|
private function GetSelectedNonItilExtensions(bool $coreExtensionIncluded, bool $bKnownMgtIncluded): array
|
|
{
|
|
$aExtensions = [
|
|
'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',
|
|
'itop-change-mgmt-simple',
|
|
];
|
|
|
|
if ($coreExtensionIncluded) {
|
|
$aExtensions[] = 'itop-config-mgmt-core';
|
|
}
|
|
|
|
if ($bKnownMgtIncluded) {
|
|
$aExtensions[] = 'itop-kown-error-mgmt';
|
|
}
|
|
|
|
return $this->TransformExtensionArrayToDictionnary($aExtensions);
|
|
}
|
|
|
|
private function TransformExtensionArrayToDictionnary(array $aExtensions)
|
|
{
|
|
$aDict = [];
|
|
foreach ($aExtensions as $sExtId) {
|
|
$aDict[$sExtId] = [];
|
|
}
|
|
|
|
return $aDict;
|
|
}
|
|
|
|
/**
|
|
* @dataProvider NonItilExtensionProvider
|
|
*/
|
|
public function testGetInstalledModules(array $aInstallationChoices, bool $bKnownMgtSelected, bool $bCoreMgtSelected)
|
|
{
|
|
$aSearchDirs = $this->GivenModuleDiscoveryInit();
|
|
|
|
$aExpectedModulesIds = $this->GetExpectedNonItilInstalledModules($bKnownMgtSelected, $bCoreMgtSelected);
|
|
|
|
$aInstalledModules = InstallationChoicesService::GetInstance()->GetInstalledModules(
|
|
$aInstallationChoices,
|
|
$aSearchDirs,
|
|
__DIR__.'/ressources/installation.xml'
|
|
);
|
|
|
|
sort($aInstalledModules);
|
|
$this->assertEquals($aExpectedModulesIds, $aInstalledModules);
|
|
}
|
|
|
|
public function testGetInstalledModules_NoInstallationXML()
|
|
{
|
|
$aSearchDirs = $this->GivenModuleDiscoveryInit();
|
|
|
|
$aInstallationChoices = json_decode(file_get_contents(__DIR__."/ressources/installation_choices_when_no_xml_file.json"), true);
|
|
|
|
$aExpectedModulesIds = [
|
|
'authent-cas/3.3.0',
|
|
'authent-external/3.3.0',
|
|
'authent-ldap/3.3.0',
|
|
'authent-local/3.3.0',
|
|
'combodo-backoffice-darkmoon-theme/3.3.0',
|
|
'combodo-backoffice-fullmoon-high-contrast-theme/3.3.0',
|
|
'combodo-backoffice-fullmoon-protanopia-deuteranopia-theme/3.3.0',
|
|
'combodo-backoffice-fullmoon-tritanopia-theme/3.3.0',
|
|
'combodo-db-tools/3.3.0',
|
|
'itop-attachments/3.3.0',
|
|
'itop-backup/3.3.0',
|
|
'itop-bridge-cmdb-services/3.3.0',
|
|
'itop-config-mgmt/3.3.0',
|
|
'itop-config/3.3.0',
|
|
'itop-core-update/3.3.0',
|
|
'itop-faq-light/3.3.0',
|
|
'itop-files-information/3.3.0',
|
|
'itop-portal-base/3.3.0',
|
|
'itop-profiles-itil/3.3.0',
|
|
'itop-request-mgmt/3.3.0',
|
|
'itop-service-mgmt/3.3.0',
|
|
'itop-sla-computation/3.3.0',
|
|
'itop-structure/3.3.0',
|
|
'itop-welcome-itil/3.3.0',
|
|
];
|
|
|
|
$aInstalledModules = InstallationChoicesService::GetInstance()->GetInstalledModules(
|
|
$aInstallationChoices,
|
|
$aSearchDirs,
|
|
null
|
|
);
|
|
|
|
sort($aInstalledModules);
|
|
$this->assertEquals($aExpectedModulesIds, $aInstalledModules);
|
|
}
|
|
|
|
private function GetExpectedNonItilInstalledModules(bool $bKnownMgtSelected, bool $bCoreMgtSelected): array
|
|
{
|
|
$aExpectedInstalledModules = [
|
|
'itop-structure/3.3.0',
|
|
'itop-sla-computation/3.3.0',
|
|
'itop-portal-base/3.3.0',
|
|
'itop-bridge-virtualization-mgmt-services/3.3.0',
|
|
'itop-request-mgmt/3.3.0',
|
|
'itop-welcome-itil/3.3.0',
|
|
'itop-profiles-itil/3.3.0',
|
|
'authent-ldap/3.3.0',
|
|
'authent-local/3.3.0',
|
|
'itop-oauth-client/3.3.0',
|
|
'itop-virtualization-mgmt/3.3.0',
|
|
'itop-core-update/3.3.0',
|
|
'combodo-backoffice-fullmoon-high-contrast-theme/3.3.0',
|
|
'itop-bridge-cmdb-services/3.3.0',
|
|
'itop-files-information/3.3.0',
|
|
'itop-attachments/3.3.0',
|
|
'itop-bridge-endusers-devices-services/3.3.0',
|
|
'itop-endusers-devices/3.3.0',
|
|
'itop-backup/3.3.0',
|
|
'itop-config/3.3.0',
|
|
'itop-bridge-storage-mgmt-services/3.3.0',
|
|
'combodo-backoffice-fullmoon-tritanopia-theme/3.3.0',
|
|
'combodo-backoffice-darkmoon-theme/3.3.0',
|
|
'itop-portal/3.3.0',
|
|
'itop-hub-connector/3.3.0',
|
|
'itop-bridge-datacenter-mgmt-services/3.3.0',
|
|
'itop-themes-compat/3.3.0',
|
|
'itop-tickets/3.3.0',
|
|
'itop-storage-mgmt/3.3.0',
|
|
'combodo-db-tools/3.3.0',
|
|
'combodo-backoffice-fullmoon-protanopia-deuteranopia-theme/3.3.0',
|
|
'authent-cas/3.3.0',
|
|
'itop-datacenter-mgmt/3.3.0',
|
|
'itop-bridge-virtualization-storage/3.3.0',
|
|
'authent-external/3.3.0',
|
|
'itop-bridge-cmdb-ticket/3.3.0',
|
|
|
|
'itop-change-mgmt/3.3.0',
|
|
'itop-service-mgmt/3.3.0',
|
|
];
|
|
if ($bCoreMgtSelected) {
|
|
$aExpectedInstalledModules [] = 'itop-config-mgmt/3.3.0';
|
|
}
|
|
if ($bKnownMgtSelected) {
|
|
$aExpectedInstalledModules [] = 'itop-knownerror-mgmt/3.3.0';
|
|
$aExpectedInstalledModules [] = 'itop-faq-light/3.3.0';
|
|
}
|
|
sort($aExpectedInstalledModules);
|
|
|
|
return $aExpectedInstalledModules;
|
|
}
|
|
|
|
private function GivenModuleDiscoveryInit(): array
|
|
{
|
|
$aSearchDirs = [APPROOT.'datamodels/2.x'];
|
|
$this->SetNonPublicStaticProperty(ModuleDiscovery::class, 'm_aSearchDirs', $aSearchDirs);
|
|
$aAllModules = json_decode(file_get_contents(__DIR__.'/ressources/available_modules.json'), true);
|
|
$this->SetNonPublicStaticProperty(ModuleDiscovery::class, 'm_aModules', $aAllModules);
|
|
return $aSearchDirs;
|
|
}
|
|
}
|