mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-26 12:08:47 +02:00
115 lines
3.7 KiB
PHP
115 lines
3.7 KiB
PHP
<?php
|
|
/**
|
|
* Copyright (C) 2013-2024 Combodo SAS
|
|
* This file is part of iTop.
|
|
* iTop is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
* iTop is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
*/
|
|
|
|
namespace Combodo\iTop\Test\UnitTest\Integration;
|
|
|
|
use ApplicationException;
|
|
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
|
use iTopModulesDependencyValidationService;
|
|
use XmlModule;
|
|
use XmlModuleMetaInfo;
|
|
use utils;
|
|
|
|
|
|
use ModuleInstallerAPI;
|
|
|
|
/**
|
|
* @package Combodo\iTop\Test\UnitTest\Setup
|
|
*/
|
|
class iTopModulesDependencyValidationServiceTest extends ItopDataTestCase {
|
|
private iTopModulesDependencyValidationService $oiTopModulesDependencyValidationService;
|
|
|
|
private array $aFilesToRemove = [];
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->RequireOnceItopFile('setup/modulediscovery.class.inc.php');
|
|
$this->RequireOnceItopFile('setup/module/iTopModulesDependencyValidationService.php');
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
parent::tearDown(); // TODO: Change the autogenerated stub
|
|
foreach ($this->aFilesToRemove as $sTmpFile){
|
|
@unlink($sTmpFile);
|
|
}
|
|
iTopModulesDependencyValidationService::SetInstance(null);
|
|
}
|
|
|
|
/**
|
|
* Module dependency validation: make sure dependencies are correct toward classes/interfaces coming from PHP/Xml datamodel files
|
|
*/
|
|
public function testReadModuleFileData()
|
|
{
|
|
iTopModulesDependencyValidationService::GetInstance()->FetchAllDependenciesViaModulesFiles();
|
|
$this->testModulesBasedOnDMFilesOnly();
|
|
}
|
|
|
|
/**
|
|
* Module dependency validation: make sure dependencies are correct toward classes/interfaces coming from Xml datamodel files
|
|
*/
|
|
public function testModulesBasedOnDMFilesOnly()
|
|
{
|
|
iTopModulesDependencyValidationService::GetInstance()->FetchAllDependenciesViaDM();
|
|
|
|
$aErrors=[];
|
|
/** @var XmlModule $oXmlModule */
|
|
foreach (iTopModulesDependencyValidationService::GetInstance()->aModules as $sModuleName => $oXmlModule) {
|
|
$aCurrentDeps = iTopModulesDependencyValidationService::GetModulesDataByModuleName()[$sModuleName]['dependencies'] ?? [];
|
|
$aModuleErrors=[];
|
|
foreach ($oXmlModule->aDependencyModulesNames as $sDepModuleName => $oXmlModule2){
|
|
$sXmlUIDs = implode('|', $oXmlModule->aXMlMetaInfosByModuleNames[$sDepModuleName]);
|
|
$bResolved=false;
|
|
foreach ($aCurrentDeps as $sDepString){
|
|
$oModuleDependency = new \iTopCoreModuleDependency($sDepString);
|
|
|
|
if (in_array($sDepModuleName, $oModuleDependency->GetPotentialPrerequisiteModuleNames())) {
|
|
$bResolved=true;
|
|
break;
|
|
}
|
|
|
|
foreach ($oModuleDependency->GetPotentialPrerequisiteModuleNames() as $sPotentialDepModuleName){
|
|
/** @var XmlModule $oXmlModule2 */
|
|
$oXmlModule2 = iTopModulesDependencyValidationService::GetInstance()->aModules[$sPotentialDepModuleName]??null;
|
|
|
|
if (! is_null($oXmlModule2) && $oXmlModule2->Depends($sDepModuleName)){
|
|
$bResolved=true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ($bResolved) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (! $bResolved){
|
|
$aModuleErrors []= "$sModuleName depends on $sDepModuleName but missing in module dependencies: " . implode(' & ', $aCurrentDeps) . ". ($sXmlUIDs)";
|
|
}
|
|
}
|
|
|
|
if (count($aModuleErrors)){
|
|
$aErrors[$sModuleName]=$aModuleErrors;
|
|
}
|
|
}
|
|
|
|
$this->assertEquals(0, count($aErrors), var_export($aErrors, true));
|
|
|
|
}
|
|
}
|
|
|
|
|