N°4762 - menu compilation: fix broken menus scenario via AVA6 delta XML

N°4762-enhance test
This commit is contained in:
odain
2023-03-02 08:51:42 +01:00
parent 9c0b906ded
commit 7176bc8686
5 changed files with 380 additions and 89 deletions

View File

@@ -7,6 +7,7 @@ use Combodo\iTop\Test\UnitTest\ItopTestCase;
use Config;
use MetaModel;
use MFCompiler;
use ParentMenuNodeCompiler;
use RunTimeEnvironment;
/**
@@ -14,8 +15,8 @@ use RunTimeEnvironment;
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
* @backupGlobals disabled
* @since 3.0.x N°4762
* @covers \MFCompiler::UseLatestPrecompiledFile
* @since 3.1 N°4762
* @covers \MFCompiler::DoCompile
*/
class MFCompilerMenuTest extends ItopTestCase {
private static $aPreviousEnvMenus;
@@ -23,22 +24,26 @@ class MFCompilerMenuTest extends ItopTestCase {
public function setUp(): void {
parent::setUp();
require_once(APPROOT.'setup/compiler.class.inc.php');
require_once(APPROOT.'setup/modelfactory.class.inc.php');
require_once(APPROOT.'application/utils.inc.php');
$this->RequireOnceItopFile('setup/compiler.class.inc.php');
$this->RequireOnceItopFile('setup/modelfactory.class.inc.php');
$this->RequireOnceItopFile('application/utils.inc.php');
}
public function tearDown(): void {
parent::tearDown();
}
private function GetCurrentEnvDeltaXmlPath(string $sEnv) : string {
return APPROOT."data/$sEnv.delta.xml";
}
public function CompileMenusProvider(){
return [
'legacy_algo' => [ 'sEnv' => 'legacy_algo', 'bLegacyMenuCompilation' => true ],
'menu_compilation_fix' => [ 'sEnv' => 'menu_compilation_fix', 'bLegacyMenuCompilation' => false ],
];
}
/**
* @dataProvider CompileMenusProvider
*/
@@ -55,7 +60,7 @@ class MFCompilerMenuTest extends ItopTestCase {
$oConfig = new Config($sConfigFilePath);
if ($bLegacyMenuCompilation){
MFCompiler::UseLegacyMenuCompilation();
ParentMenuNodeCompiler::UseLegacyMenuCompilation();
}
$oConfig->WriteToFile();
$oRunTimeEnvironment = new RunTimeEnvironment($sEnv);
@@ -82,4 +87,53 @@ class MFCompilerMenuTest extends ItopTestCase {
}
static::$aPreviousEnvMenuCount = $aMenuCount;
}
public function CompileMenusWithDeltaProvider(){
return [
'Menus are broken with specific delta XML using LEGACY algo' => [ 'sDeltaFile' => 'delta_broken_menus.xml', 'sEnv' => 'broken_menus', 'bLegacyMenuCompilation' => true ],
'Menus repaired using same delta XML with NEW algo' => [ 'sDeltaFile' => 'delta_broken_menus.xml', 'sEnv' => 'fixed_menus', 'bLegacyMenuCompilation' => false ],
];
}
/**
* @dataProvider CompileMenusWithDeltaProvider
*/
public function testCompileMenusWithDelta($sDeltaFile, $sEnv, $bLegacyMenuCompilation){
$sProvidedDeltaPath = __DIR__.'/ressources/datamodels/'.$sDeltaFile;
if (is_file($sProvidedDeltaPath)){
$sDeltaXmlPath = $this->GetCurrentEnvDeltaXmlPath($sEnv);
copy($sProvidedDeltaPath, $sDeltaXmlPath);
}
$sConfigFilePath = \utils::GetConfigFilePath($sEnv);
//copy conf from production to phpunit context
$sDirPath = dirname($sConfigFilePath);
if (! is_dir($sDirPath)){
mkdir($sDirPath);
}
$oConfig = new Config(\utils::GetConfigFilePath());
$oConfig->WriteToFile($sConfigFilePath);
$oConfig = new Config($sConfigFilePath);
if ($bLegacyMenuCompilation){
ParentMenuNodeCompiler::UseLegacyMenuCompilation();
}
$oConfig->WriteToFile();
$oRunTimeEnvironment = new RunTimeEnvironment($sEnv);
$oRunTimeEnvironment->CompileFrom(\utils::GetCurrentEnvironment());
$oConfig->WriteToFile();
if ($bLegacyMenuCompilation){
/**
* PHP Notice: Undefined index: ConfigManagement in /var/www/html/iTop/env-broken_menus/itop-structure/model.itop-structure.php on line 925
*/
error_reporting(E_ALL & ~E_NOTICE);
$this->expectErrorMessage("Call to a member function GetIndex() on null");
}
$sConfigFile = APPCONF.\utils::GetCurrentEnvironment().'/'.ITOP_CONFIG_FILE;
MetaModel::Startup($sConfigFile, false /* $bModelOnly */, true /* $bAllowCache */, false /* $bTraceSourceFiles */, $sEnv);
$this->assertNotEquals([], ApplicationMenu::GetMenuGroups());
$this->assertNotEquals([], ApplicationMenu::GetMenusCount());
}
}