mirror of
https://github.com/Combodo/iTop.git
synced 2026-10-14 04:18:57 +02:00
* N°10151 - Missing extension.xml in extension disturb setup * N°10151 - Missing extension.xml in extension disturb setup * N°10151 - add weird usecase with multi xml files in same extension * N°10151 - fix module not installed after MTP * N°10151 - fix broken extension with further extension.xml * N°10151 - code style
550 lines
19 KiB
PHP
550 lines
19 KiB
PHP
<?php
|
|
|
|
namespace Combodo\iTop\Test\UnitTest\Integration;
|
|
|
|
use Combodo\iTop\Test\UnitTest\ItopTestCase;
|
|
use CoreException;
|
|
use iTopExtension;
|
|
use ItopExtensionsMap;
|
|
use iTopExtensionsMapFake;
|
|
use ModuleDiscovery;
|
|
|
|
class ExtensionsMapTest extends ItopTestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp(); // TODO: Change the autogenerated stub
|
|
$this->RequireOnceItopFile('/setup/unattended-install/InstallationFileService.php');
|
|
ModuleDiscovery::ResetCache();
|
|
|
|
}
|
|
|
|
public function testGetAllExtensionsWithPreviouslyInstalledDoesNotCrash()
|
|
{
|
|
$oExtensionsMap = iTopExtensionsMap::GetExtensionsMap();
|
|
$aExtensions = $oExtensionsMap->GetAllExtensionsWithPreviouslyInstalled();
|
|
$this->assertGreaterThan(0, count($aExtensions));
|
|
}
|
|
|
|
public function testGetAllExtensionsToDisplayInSetup()
|
|
{
|
|
$oExtensionsMap = $this->GiveExtensionMapWithAllTypeOfExtensions();
|
|
|
|
$aExtensions = $oExtensionsMap->GetAllExtensionsToDisplayInSetup();
|
|
$expected = [
|
|
'installed_ext1',
|
|
'ext1',
|
|
];
|
|
$this->assertEquals($expected, array_keys($aExtensions));
|
|
}
|
|
|
|
public function testDeclareExtensionAsRemoved_WithDictPassed()
|
|
{
|
|
try {
|
|
$oExtensionsMap = $this->GiveExtensionMapWithAllTypeOfExtensions();
|
|
//non existing extension
|
|
$aExtensionCodes = ['unexisting_extension_code' => 'label_unexisting_extension_code'];
|
|
//extension ok
|
|
$aExtensionCodes ['installed_ext1'] = $oExtensionsMap->GetFromExtensionCode('installed_ext1')->sLabel;
|
|
//search extension by label ko
|
|
$sLabel = $oExtensionsMap->GetFromExtensionCode('installed_ext_in_package')->sLabel;
|
|
$aExtensionCodes [$sLabel] = $sLabel;
|
|
|
|
$oExtensionsMap->DeclareExtensionAsRemoved($aExtensionCodes);
|
|
|
|
$this->assertEquals(["installed_ext1"], ModuleDiscovery::GetRemovedExtensionCodes());
|
|
} finally {
|
|
ModuleDiscovery::DeclareRemovedExtensions([]);
|
|
}
|
|
}
|
|
|
|
public function testDeclareExtensionAsRemoved_WithListPassed()
|
|
{
|
|
try {
|
|
$oExtensionsMap = $this->GiveExtensionMapWithAllTypeOfExtensions();
|
|
$aExtensionCodes = ['unexisting_extension_code', 'installed_ext1'];
|
|
$aExtensionCodes [] = $oExtensionsMap->GetFromExtensionCode('installed_ext_in_package')->sLabel;
|
|
$oExtensionsMap->DeclareExtensionAsRemoved($aExtensionCodes);
|
|
|
|
$this->assertEquals(["installed_ext1"], ModuleDiscovery::GetRemovedExtensionCodes());
|
|
} finally {
|
|
ModuleDiscovery::DeclareRemovedExtensions([]);
|
|
}
|
|
}
|
|
|
|
public function testGetAllExtensionsToDisplayInSetup_WithExtensionsHavingDependencyIssues()
|
|
{
|
|
$oExtensionsMap = $this->GiveExtensionMapWithAllTypeOfExtensions();
|
|
|
|
$aExtensions = $oExtensionsMap->GetAllExtensionsToDisplayInSetup(true);
|
|
$expected = [
|
|
'installed_ext1',
|
|
'installed_ext_with_deps_issues',
|
|
'ext1',
|
|
'ext_with_deps_issues',
|
|
];
|
|
$this->assertEquals($expected, array_keys($aExtensions));
|
|
}
|
|
|
|
public function testGetAllExtensionsToDisplayInSetup_LegacyPackage()
|
|
{
|
|
$oExtensionsMap = $this->GiveExtensionMapWithAllTypeOfExtensions();
|
|
|
|
$this->SetNonPublicProperty($oExtensionsMap, 'bHasXmlInstallationFile', false);
|
|
$aExtensions = $oExtensionsMap->GetAllExtensionsToDisplayInSetup();
|
|
$expected = [
|
|
'installed_ext1',
|
|
'installed_ext_in_package',
|
|
'ext1',
|
|
'ext_in_package',
|
|
];
|
|
$this->assertEquals($expected, array_keys($aExtensions));
|
|
}
|
|
|
|
public function testGetAllExtensionsToDisplayInSetup_LegacyPackage_WithExtensionsHavingDependencyIssues()
|
|
{
|
|
$oExtensionsMap = $this->GiveExtensionMapWithAllTypeOfExtensions();
|
|
|
|
$this->SetNonPublicProperty($oExtensionsMap, 'bHasXmlInstallationFile', false);
|
|
$aExtensions = $oExtensionsMap->GetAllExtensionsToDisplayInSetup(true);
|
|
$expected = [
|
|
'installed_ext1',
|
|
'installed_ext_in_package',
|
|
'installed_ext_with_deps_issues',
|
|
'ext1',
|
|
'ext_in_package',
|
|
'ext_with_deps_issues',
|
|
];
|
|
$this->assertEquals($expected, array_keys($aExtensions));
|
|
}
|
|
|
|
public function testAddExtensionAlwaysKeepsNewestVersion(): void
|
|
{
|
|
$oExtensionsMap = iTopExtensionsMapFake::createFromArray([]);
|
|
|
|
$oExtensionV1 = $this->GivenExtension('my-ext', '1.0.0');
|
|
$oExtensionsMap->AddExtension($oExtensionV1);
|
|
$this->assertSame($oExtensionV1, $oExtensionsMap->GetFromExtensionCode('my-ext'));
|
|
$this->assertEquals(['my-ext/1.0.0'], array_keys($oExtensionsMap->GetAllExtensions()));
|
|
|
|
$oExtensionV3 = $this->GivenExtension('my-ext', '3.0.0');
|
|
$oExtensionsMap->AddExtension($oExtensionV3);
|
|
$this->assertSame($oExtensionV3, $oExtensionsMap->GetFromExtensionCode('my-ext'));
|
|
$this->assertEquals(['my-ext/3.0.0'], array_keys($oExtensionsMap->GetAllExtensions()));
|
|
|
|
$oExtensionV2 = $this->GivenExtension('my-ext', '2.0.0');
|
|
$oExtensionsMap->AddExtension($oExtensionV2);
|
|
$this->assertSame($oExtensionV3, $oExtensionsMap->GetFromExtensionCode('my-ext'));
|
|
$this->assertEquals(['my-ext/3.0.0'], array_keys($oExtensionsMap->GetAllExtensions()));
|
|
}
|
|
|
|
public function testAddExtensionReplaceRemovedExtensions(): void
|
|
{
|
|
$oExtensionsMap = iTopExtensionsMapFake::createFromArray([]);
|
|
|
|
$oExtensionV3Removed = $this->GivenExtension('my-ext', '3.0.0');
|
|
$oExtensionV3Removed->bRemovedFromDisk = true;
|
|
$oExtensionsMap->AddExtension($oExtensionV3Removed);
|
|
$this->assertSame($oExtensionV3Removed, $oExtensionsMap->GetFromExtensionCode('my-ext'));
|
|
$this->assertEquals(['my-ext/3.0.0'], array_keys($oExtensionsMap->GetAllExtensions()));
|
|
|
|
$oExtensionV2 = $this->GivenExtension('my-ext', '2.0.0');
|
|
$oExtensionsMap->AddExtension($oExtensionV2);
|
|
$this->assertSame($oExtensionV2, $oExtensionsMap->GetFromExtensionCode('my-ext'));
|
|
$this->assertEquals(['my-ext/2.0.0'], array_keys($oExtensionsMap->GetAllExtensions()));
|
|
}
|
|
|
|
private function GiveExtensionMapWithAllTypeOfExtensions(): iTopExtensionsMap
|
|
{
|
|
$oExtensionsMap = iTopExtensionsMap::GetExtensionsMap();
|
|
$this->SetNonPublicProperty($oExtensionsMap, 'aInstalledExtensions', []);
|
|
$this->SetNonPublicProperty($oExtensionsMap, 'aExtensions', []);
|
|
|
|
$this->AddExtension(
|
|
$oExtensionsMap,
|
|
$this->GivenExtension("installed_ext1", "123", true, iTopExtension::SOURCE_REMOTE, true, []),
|
|
'aInstalledExtensions'
|
|
);
|
|
$this->AddExtension(
|
|
$oExtensionsMap,
|
|
$this->GivenExtension("installed_notvisible", "123", false, iTopExtension::SOURCE_REMOTE, true, []),
|
|
'aInstalledExtensions'
|
|
);
|
|
$this->AddExtension(
|
|
$oExtensionsMap,
|
|
$this->GivenExtension("installed_ext_in_package", "123", true, iTopExtension::SOURCE_WIZARD, true, []),
|
|
'aInstalledExtensions'
|
|
);
|
|
$this->AddExtension(
|
|
$oExtensionsMap,
|
|
$this->GivenExtension("installed_ext_with_deps_issues", "123", true, iTopExtension::SOURCE_REMOTE, true, ["aa"]),
|
|
'aInstalledExtensions'
|
|
);
|
|
$this->AddExtension(
|
|
$oExtensionsMap,
|
|
$this->GivenExtension("ext1", "123", true, iTopExtension::SOURCE_REMOTE, true, []),
|
|
'aExtensions'
|
|
);
|
|
$this->AddExtension(
|
|
$oExtensionsMap,
|
|
$this->GivenExtension("notvisible", "123", false, iTopExtension::SOURCE_REMOTE, true, []),
|
|
'aExtensions'
|
|
);
|
|
$this->AddExtension(
|
|
$oExtensionsMap,
|
|
$this->GivenExtension("ext_in_package", "123", true, iTopExtension::SOURCE_WIZARD, true, []),
|
|
'aExtensions'
|
|
);
|
|
$this->AddExtension(
|
|
$oExtensionsMap,
|
|
$this->GivenExtension("ext_with_deps_issues", "123", true, iTopExtension::SOURCE_REMOTE, true, ["aa"]),
|
|
'aExtensions'
|
|
);
|
|
|
|
return $oExtensionsMap;
|
|
}
|
|
|
|
private function GivenExtension(string $sCode, string $sVersion, bool $bVisible = true, string $sSource = iTopExtension::SOURCE_REMOTE, bool $bMandatory = false, array $aMissingDependencies = []): iTopExtension
|
|
{
|
|
$oExt = new iTopExtension();
|
|
$oExt->sCode = $sCode;
|
|
$oExt->sLabel = "LABEL_".$sCode;
|
|
$oExt->sVersion = $sVersion;
|
|
$oExt->bVisible = $bVisible;
|
|
$oExt->sSource = $sSource;
|
|
$oExt->aMissingDependencies = $aMissingDependencies;
|
|
$oExt->bMandatory = $bMandatory;
|
|
return $oExt;
|
|
}
|
|
|
|
private function AddExtension(iTopExtensionsMap $oExtensionsMap, iTopExtension $oExt, string $mapKeyInItopExtensionMap)
|
|
{
|
|
$this->InvokeNonPublicMethod(iTopExtensionsMap::class, 'AddExtension', $oExtensionsMap, [$oExt]);
|
|
$aMap = $this->GetNonPublicProperty($oExtensionsMap, $mapKeyInItopExtensionMap);
|
|
$aMap[$oExt->sCode.'/'.$oExt->sVersion] = $oExt;
|
|
$this->SetNonPublicProperty($oExtensionsMap, $mapKeyInItopExtensionMap, $aMap);
|
|
}
|
|
|
|
public function testiTopExtensionsMapInit()
|
|
{
|
|
$oiTopExtensionsMap = iTopExtensionsMap::GetExtensionsMap(sAppRootForTests: __DIR__."/ressources/");
|
|
|
|
$sExpected = file_get_contents(__DIR__.'/ressources/all_extensions_from_datamodels.json');
|
|
$sExpected = str_replace('"sVersion": "ITOP_VERSION"', '"sVersion": "'.ITOP_VERSION.'"', $sExpected);
|
|
$sExpected = preg_replace('/"module_file_path": .*/', '"module_file_path": ANYPATH', $sExpected);
|
|
|
|
$actual = json_encode($this->SerializeExtensionMap($oiTopExtensionsMap), JSON_PRETTY_PRINT);
|
|
$actual = preg_replace('/"module_file_path": .*/', '"module_file_path": ANYPATH', $actual);
|
|
$this->assertEquals($sExpected, $actual);
|
|
}
|
|
|
|
public function testGetScannedModulesRootDirs()
|
|
{
|
|
$sAppRootForTest = __DIR__."/resources2/";
|
|
$oiTopExtensionsMap = iTopExtensionsMap::GetExtensionsMap(sAppRootForTests: $sAppRootForTest);
|
|
|
|
$aExpectedDirs = [
|
|
"{$sAppRootForTest}datamodels/2.x",
|
|
"{$sAppRootForTest}extensions",
|
|
"{$sAppRootForTest}data/production-modules",
|
|
];
|
|
self::assertEquals($aExpectedDirs, $oiTopExtensionsMap->GetScannedModulesRootDirs());
|
|
}
|
|
|
|
public function testCheckExtensionsValidityReturnsFalseWhenSelectedExtensionCodeAndLabelAreMissing(): void
|
|
{
|
|
[$sEnvironment, $sExtensionsDirRelative] = $this->CreateFixtureContext('env-missing-label-');
|
|
|
|
$sInvalidExtensionXml = <<<XML
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<extension format="1.0">
|
|
<description>Test extension without code and label</description>
|
|
<version>1.0.0</version>
|
|
<mandatory>false</mandatory>
|
|
<more_info_url/>
|
|
</extension>
|
|
XML;
|
|
$sExtensionsDirAbsolute = APPROOT.$sExtensionsDirRelative;
|
|
file_put_contents($sExtensionsDirAbsolute.'/extension.xml', $sInvalidExtensionXml);
|
|
|
|
$oExtensionMap = ItopExtensionsMap::GetExtensionsMap($sEnvironment);
|
|
|
|
//echo json_encode(array_keys($oExtensionMap->GetAllExtensions()), JSON_PRETTY_PRINT);
|
|
|
|
// $this->expectException(CoreException::class);
|
|
// $this->expectExceptionMessage("Selected extension(s) cannot be installed: Missing extension code ($sExtensionsDirAbsolute)");
|
|
|
|
self::assertFalse($oExtensionMap->CheckExtensionsValidity(), 'Check extensions validity should have detected an extension without code.');
|
|
}
|
|
|
|
public function testCheckExtensionsValidityReturnsFalseWhenSelectedExtensionCodeIsMissing(): void
|
|
{
|
|
[$sEnvironment, $sExtensionsDirRelative] = $this->CreateFixtureContext('env-missing-label-');
|
|
|
|
$sInvalidExtensionXml = <<<XML
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<extension format="1.0">
|
|
<label>Broken extension</label>
|
|
<description>Test extension without code and label</description>
|
|
<version>1.0.0</version>
|
|
<mandatory>false</mandatory>
|
|
<more_info_url/>
|
|
</extension>
|
|
XML;
|
|
$sExtensionsDirAbsolute = APPROOT.$sExtensionsDirRelative;
|
|
file_put_contents($sExtensionsDirAbsolute.'/extension.xml', $sInvalidExtensionXml);
|
|
|
|
$oExtensionMap = ItopExtensionsMap::GetExtensionsMap($sEnvironment);
|
|
|
|
//echo json_encode(array_keys($oExtensionMap->GetAllExtensions()), JSON_PRETTY_PRINT);
|
|
|
|
// $this->expectException(CoreException::class);
|
|
// $this->expectExceptionMessage("Selected extension(s) cannot be installed: Missing extension code ($sExtensionsDirAbsolute)");
|
|
|
|
self::assertFalse($oExtensionMap->CheckExtensionsValidity(), 'Check extensions validity should have detected an extension without code.');
|
|
}
|
|
|
|
public function testCheckExtensionsValidityThrowExceptionWhenSelectedExtensionCodeAndLabelAreMissingAndExtensionIsChosen(): void
|
|
{
|
|
[$sEnvironment, $sExtensionsDirRelative] = $this->CreateFixtureContext('env-missing-label-');
|
|
|
|
$sInvalidExtensionXml = <<<XML
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<extension format="1.0">
|
|
<description>Test extension without code and label</description>
|
|
<version>1.0.0</version>
|
|
<mandatory>false</mandatory>
|
|
<more_info_url/>
|
|
</extension>
|
|
XML;
|
|
$sExtensionsDirAbsolute = APPROOT.$sExtensionsDirRelative;
|
|
file_put_contents($sExtensionsDirAbsolute.'/extension.xml', $sInvalidExtensionXml);
|
|
|
|
$oExtensionMap = ItopExtensionsMap::GetExtensionsMap($sEnvironment);
|
|
$oExtensionMap->MarkAsChosen('');
|
|
|
|
//echo json_encode(array_keys($oExtensionMap->GetAllExtensions()), JSON_PRETTY_PRINT);
|
|
|
|
$this->expectException(CoreException::class);
|
|
$this->expectExceptionMessage("Selected extension(s) cannot be installed: Missing extension code ($sExtensionsDirAbsolute)");
|
|
|
|
$oExtensionMap->CheckExtensionsValidity();
|
|
}
|
|
|
|
public function testCheckExtensionsValidityThrowExceptionWhenSelectedExtensionCodeIsMissingAndExtensionIsChosen(): void
|
|
{
|
|
[$sEnvironment, $sExtensionsDirRelative] = $this->CreateFixtureContext('env-missing-label-');
|
|
|
|
$sInvalidExtensionXml = <<<XML
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<extension format="1.0">
|
|
<label>Broken extension</label>
|
|
<description>Test extension without code and label</description>
|
|
<version>1.0.0</version>
|
|
<mandatory>false</mandatory>
|
|
<more_info_url/>
|
|
</extension>
|
|
XML;
|
|
$sExtensionsDirAbsolute = APPROOT.$sExtensionsDirRelative;
|
|
file_put_contents($sExtensionsDirAbsolute.'/extension.xml', $sInvalidExtensionXml);
|
|
|
|
$oExtensionMap = ItopExtensionsMap::GetExtensionsMap($sEnvironment);
|
|
$oExtensionMap->MarkAsChosen('');
|
|
|
|
//echo json_encode(array_keys($oExtensionMap->GetAllExtensions()), JSON_PRETTY_PRINT);
|
|
|
|
$this->expectException(CoreException::class);
|
|
$this->expectExceptionMessage("Selected extension(s) cannot be installed: Missing extension code (Broken extension)");
|
|
|
|
$oExtensionMap->CheckExtensionsValidity();
|
|
}
|
|
|
|
public function testExtensionsFoundInDBShouldBeMarkedAsInstalled()
|
|
{
|
|
$oExtensionsMap = iTopExtensionsMapFake::createFromArray([
|
|
'itop-installed' => [
|
|
'installed' => false,
|
|
],
|
|
'itop-not-installed' => [
|
|
'installed' => false,
|
|
],
|
|
]);
|
|
$oExtensionsMap->AddInstalledExtensionInfo('itop-installed');
|
|
$oExtensionsMap->LoadInstalledExtensionsFromDatabase(new \Config());
|
|
|
|
$this->assertTrue($oExtensionsMap->GetFromExtensionCode('itop-installed')->bInstalled);
|
|
$this->assertFalse($oExtensionsMap->GetFromExtensionCode('itop-not-installed')->bInstalled);
|
|
}
|
|
|
|
public function testExtensionSourceMismatchShouldBeFlaggedAsRemoved()
|
|
{
|
|
$sExtensionCode = 'itop-problem-mgmt';
|
|
$oExtensionsMap = iTopExtensionsMapFake::createFromArray([
|
|
$sExtensionCode => [
|
|
'installed' => false,
|
|
'source' => iTopExtension::SOURCE_WIZARD,
|
|
],
|
|
]);
|
|
$oExtensionsMap->AddInstalledExtensionInfo($sExtensionCode, '6.4.0', iTopExtension::SOURCE_MANUAL);
|
|
|
|
$oExtensionsMap->LoadInstalledExtensionsFromDatabase(new \Config());
|
|
|
|
$oInstalledExtension = $oExtensionsMap->aInstalledExtensions[$sExtensionCode.'/6.4.0'];
|
|
$this->assertTrue($oInstalledExtension->bRemovedFromDisk);
|
|
}
|
|
|
|
private function CreateFixtureContext(string $sEnvPrefix): array
|
|
{
|
|
$sEnvironment = str_replace('.', '-', uniqid($sEnvPrefix, true));
|
|
$sExtensionsDirRelative = 'data/'.$sEnvironment.'-modules';
|
|
|
|
mkdir(APPROOT.$sExtensionsDirRelative, 0777, true);
|
|
$this->aFileToClean[] = APPROOT.$sExtensionsDirRelative;
|
|
|
|
return [$sEnvironment, $sExtensionsDirRelative];
|
|
}
|
|
|
|
public function SerializeExtensionMap(iTopExtensionsMap $oiTopExtensionsMap): array
|
|
{
|
|
$aRes = [];
|
|
foreach ($oiTopExtensionsMap->GetAllExtensions() as $oExtension) {
|
|
$aRes[] = [
|
|
'sCode' => $oExtension->sCode,
|
|
'sSource' => $oExtension->sSource,
|
|
'sVersion' => $oExtension->sVersion,
|
|
'aModules' => $oExtension->aModules,
|
|
'aModuleVersion' => $oExtension->aModuleVersion,
|
|
'aModuleInfo' => $oExtension->aModuleInfo,
|
|
];
|
|
}
|
|
|
|
return $aRes;
|
|
}
|
|
|
|
public function testGetExtensionsFromDir_MonoModuleExtensionWithXmlDefinition()
|
|
{
|
|
$oiTopExtensionsMap = iTopExtensionsMap::GetExtensionsMap();
|
|
$sTestDir = $this->PrepareTestDir();
|
|
|
|
$this->CreateExtensionFolder($sTestDir, "ext1", "ext_code1", "1.5.9");
|
|
$this->CreateModule($sTestDir, "module1", "module_code1", "9.5.1");
|
|
self::assertEquals(['ext_code1' => 'ext1'], $oiTopExtensionsMap->GetExtensionsFromDir($sTestDir));
|
|
}
|
|
|
|
public function testGetExtensionsFromDir_MultiModuleExtension()
|
|
{
|
|
$oiTopExtensionsMap = iTopExtensionsMap::GetExtensionsMap();
|
|
$sTestDir = $this->PrepareTestDir();
|
|
|
|
$this->CreateExtensionFolder($sTestDir, "ext1", "ext_code1", "1.5.9");
|
|
|
|
foreach ([1, 2, 3] as $i) {
|
|
$this->CreateModule($sTestDir, "module{$i}", "module_code{$i}", "9.5.{$i}");
|
|
}
|
|
self::assertEquals(['ext_code1' => 'ext1'], $oiTopExtensionsMap->GetExtensionsFromDir($sTestDir));
|
|
}
|
|
|
|
public function testGetExtensionsFromDir_MultiModuleExtensionWithOneXMLDefPerModule()
|
|
{
|
|
$oiTopExtensionsMap = iTopExtensionsMap::GetExtensionsMap();
|
|
$sTestDir = $this->PrepareTestDir();
|
|
|
|
$this->CreateExtensionFolder($sTestDir, "ext1", "ext_code1", "1.5.9");
|
|
|
|
foreach ([1, 2, 3] as $i) {
|
|
if (! is_dir("$sTestDir/module_code{$i}")) {
|
|
mkdir("$sTestDir/module_code{$i}");
|
|
}
|
|
$this->CreateExtensionFolder("$sTestDir/module_code{$i}", "ext{$i}", "ext_code{$i}", "9.5.{$i}");
|
|
$this->CreateModule($sTestDir, "module{$i}", "module_code{$i}", "9.5.{$i}");
|
|
}
|
|
self::assertEquals(['ext_code1' => 'ext1'], $oiTopExtensionsMap->GetExtensionsFromDir($sTestDir));
|
|
}
|
|
|
|
public function testGetExtensionsFromDir_FurtherMonoModuleExtensionsWithoutXmlDefinition()
|
|
{
|
|
$oiTopExtensionsMap = iTopExtensionsMap::GetExtensionsMap();
|
|
$sTestDir = $this->PrepareTestDir();
|
|
|
|
foreach ([1, 2, 3] as $i) {
|
|
$this->CreateModule($sTestDir, "module{$i}", "module_code{$i}", "9.5.{$i}");
|
|
}
|
|
|
|
$expected = [
|
|
'module_code1' => 'module1',
|
|
'module_code2' => 'module2',
|
|
'module_code3' => 'module3',
|
|
];
|
|
self::assertEquals($expected, $oiTopExtensionsMap->GetExtensionsFromDir($sTestDir));
|
|
}
|
|
|
|
public function testGetExtensionsFromDir_MonoModuleExtensionWithoutXmlDefinition()
|
|
{
|
|
$oiTopExtensionsMap = iTopExtensionsMap::GetExtensionsMap();
|
|
$sTestDir = $this->PrepareTestDir();
|
|
|
|
$this->CreateModule($sTestDir, "module1", "module_code1", "9.5.1");
|
|
self::assertEquals(['module_code1' => 'module1'], $oiTopExtensionsMap->GetExtensionsFromDir($sTestDir));
|
|
}
|
|
|
|
private function PrepareTestDir(): string
|
|
{
|
|
$sTestDir = tempnam(sys_get_temp_dir(), "ext_map");
|
|
unlink($sTestDir);
|
|
mkdir($sTestDir, 0777, true);
|
|
$this->aFileToClean[] = $sTestDir;
|
|
return $sTestDir;
|
|
}
|
|
|
|
private function CreateExtensionFolder(string $sDir, string $sExtensionLabel, string $sExtensionCode, string $sExtensionVersion)
|
|
{
|
|
$sXmlDef = <<<XML
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<extension format="1.0">
|
|
<extension_code>$sExtensionCode</extension_code>
|
|
<label><![CDATA[$sExtensionLabel]]></label>
|
|
<description><![CDATA[BLABLA]]></description>
|
|
<version>$sExtensionVersion</version>
|
|
<modules type="array">
|
|
<module>
|
|
<id>aaa</id>
|
|
<version>tags/6.6.6</version>
|
|
</module>
|
|
</modules>
|
|
<release_date>2023-07-19</release_date>
|
|
<itop_version_min>3.2.0</itop_version_min>
|
|
<status></status>
|
|
<mandatory>false</mandatory>
|
|
<more_info_url></more_info_url>
|
|
</extension>
|
|
XML;
|
|
|
|
file_put_contents($sDir.'/extension.xml', $sXmlDef);
|
|
}
|
|
|
|
private function CreateModule(string $sDir, string $sModuleLabel, string $sModuleCode, string $sVersion)
|
|
{
|
|
$sModuleDir = $sDir."/$sModuleCode";
|
|
if (! is_dir($sModuleDir)) {
|
|
mkdir($sModuleDir, 0777, true);
|
|
}
|
|
$sModuleContent = <<<PHP
|
|
<?php
|
|
SetupWebPage::AddModule(
|
|
__FILE__, // Path to the current file, all other file names are relative to the directory containing this file
|
|
'$sModuleCode/$sVersion',
|
|
[
|
|
'label' => '$sModuleLabel',
|
|
'category' => 'authentication',
|
|
'dependencies' => [],
|
|
'mandatory' => true,
|
|
'visible' => true,
|
|
'datamodel' => [],
|
|
]
|
|
);
|
|
PHP;
|
|
|
|
file_put_contents($sModuleDir."/module.{$sModuleCode}.php", $sModuleContent);
|
|
}
|
|
}
|