mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-27 12:38:44 +02:00
module dependency validation moved in a core folder + cleanup dedicated unit/integration tests
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
<?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::GetInstance()::$aModulesDataByModuleName[$sModuleName][2]['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));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user