N°4789 - fix broken setup + tests

This commit is contained in:
odain
2025-08-20 16:26:03 +02:00
parent 1bc14f97e1
commit 07d7995a51
8 changed files with 1132 additions and 1032 deletions

View File

@@ -0,0 +1,55 @@
<?php
namespace Combodo\iTop\Test\UnitTest\Setup\ModuleDiscovery;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
use ModuleDiscoveryService;
class ModuleDiscoveryServiceTest extends ItopDataTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->RequireOnceItopFile('setup/modulediscovery/ModuleDiscoveryService.php');
}
public function test()
{
$sModuleFilePath = __DIR__.'/resources/module.itop-full-itil.php';
$aRes = ModuleDiscoveryService::GetInstance()->ReadModuleFileConfiguration($sModuleFilePath);
var_dump($aRes);
$this->assertCount(3, $aRes);
$this->assertEquals($sModuleFilePath, $aRes[0]);
$this->assertEquals('itop-full-itil/3.3.0', $aRes[1]);
$this->assertIsArray($aRes[2]);
$this->assertArrayHasKey('label', $aRes[2]);
$this->assertEquals('Bridge - Request management ITIL + Incident management ITIL', $aRes[2]['label'] ?? null);
}
public static function ComputeBooleanExpressionProvider()
{
return [
"true" => [ "expr" => "true", "expected" => true],
"(true)" => [ "expr" => "(true)", "expected" => true],
"(false||true)" => [ "expr" => "(false||true)", "expected" => true],
"false" => [ "expr" => "false", "expected" => false],
"(false)" => [ "expr" => "(false)", "expected" => false],
"(false&&true)" => [ "expr" => "(false&&true)", "expected" => false],
];
}
/**
* @dataProvider ComputeBooleanExpressionProvider
*/
public function testComputeBooleanExpression(string $sBooleanExpression, bool $expected){
$this->assertEquals($expected, ModuleDiscoveryService::GetInstance()->ComputeBooleanExpression($sBooleanExpression), $sBooleanExpression);
}
public function testComputeBooleanExpression_BrokenBooleanExpression(){
$this->expectException(\ModuleDiscoveryServiceException::class);
$this->expectExceptionMessage('Eval of \'(a || true)\' caused an error: Undefined constant "a"');
$this->assertTrue(ModuleDiscoveryService::GetInstance()->ComputeBooleanExpression("(a || true)"));
}
}

View File

@@ -0,0 +1,41 @@
<?php
//
// iTop module definition file
//
SetupWebPage::AddModule(
__FILE__, // Path to the current file, all other file names are relative to the directory containing this file
'itop-full-itil/3.3.0',
array(
// Identification
//
'label' => 'Bridge - Request management ITIL + Incident management ITIL',
'category' => 'business',
// Setup
//
'dependencies' => array(
'itop-request-mgmt-itil/2.3.0',
'itop-incident-mgmt-itil/2.3.0',
),
'mandatory' => false,
'visible' => false,
'auto_select' => 'SetupInfo::ModuleIsSelected("itop-request-mgmt-itil") && SetupInfo::ModuleIsSelected("itop-incident-mgmt-itil")',
// Components
//
'datamodel' => array(),
'webservice' => array(),
'data.struct' => array(// add your 'structure' definition XML files here,
),
'data.sample' => array(// add your sample data XML files here,
),
// Documentation
//
'doc.manual_setup' => '', // hyperlink to manual setup documentation, if any
'doc.more_information' => '', // hyperlink to more information, if any
// Default settings
//
'settings' => array(// Module specific settings go here, if any
),
)
);