N°2982 - fix delta xml variables not used in themes

This commit is contained in:
odain
2021-04-12 22:14:00 +02:00
parent c0f5906dce
commit 903afff687
10 changed files with 235 additions and 71 deletions

View File

@@ -18,12 +18,21 @@ class MFCompilerTest extends ItopTestCase {
/** @var \MFCompiler */
private $oMFCompiler;
public function setUp()
{
private $sTmpDir;
public function setUp() {
parent::setUp();
require_once(APPROOT.'setup/compiler.class.inc.php');
require_once(APPROOT.'setup/modelfactory.class.inc.php');
require_once(__DIR__.'/SubMFCompiler.php');
$this->oMFCompiler = new MFCompiler($this->createMock(\ModelFactory::class), '');
$this->sTmpDir = $this->CreateTmpdir();
$this->oMFCompiler = new SubMFCompiler($this->createMock(\ModelFactory::class), '');
}
public function tearDown() {
parent::tearDown();
$this->RecurseRmdir($this->sTmpDir);
}
public static function Init(){
@@ -133,5 +142,46 @@ class MFCompilerTest extends ItopTestCase {
];
}
public function testCompileThemes(){
$sXmlDataCustoFilePath = realpath(__DIR__ . '/ressources/datamodels/datamodel-branding.xml');
$oDom = new MFDocument();
$oDom->load($sXmlDataCustoFilePath);
/** @var \MFElement $oBrandingNode */
$oBrandingNode = $oDom->GetNodes('branding')->item(0);
$this->RecurseMkdir($this->sTmpDir.'/branding/themes/fullmoon/');
file_put_contents($this->sTmpDir.'/branding/themes/fullmoon/main.css', "");
$aImportsPaths = array(
APPROOT.'css/',
APPROOT.'css/backoffice/main.scss',
$this->sTmpDir.'//',
);
$aThemeParameters = [
'variables' => [
'ibo-page-banner--background-color' => '$ibo-color-red-600',
'ibo-page-banner--text-color' => '$ibo-color-red-100',
'ibo-page-banner--text-content' => '"THIS IS A TEST INSTANCE"',
],
'imports_variable' => [ 'style2' => 'style2.scss'],
'imports_utility' => [ 'style1' => 'style1.scss', 'style3' => 'style3.scss'],
'stylesheets' => [
"fullmoon" => '../css/backoffice/main.scss',
"environment-banner" => '../css/backoffice/themes/page-banner.scss'
],
];
$oThemeHandlerService = $this->createMock(\ThemeHandlerService::class);
$oThemeHandlerService->expects($this->exactly(1))
->method("CompileTheme")
->with("fullmoon", true, $this->oMFCompiler->GetCompilationTimeStamp(), $aThemeParameters, $aImportsPaths, $this->sTmpDir . '/');
//CompileTheme($sThemeId, $bSetup = false, $sSetupCompilationTimestamp="", $aThemeParameters = null, $aImportsPaths = null, $sWorkingPath = null)
MFCompiler::setThemeHandlerService($oThemeHandlerService);
$this->oMFCompiler->CompileThemes($oBrandingNode, $this->sTmpDir);
}
}

View File

@@ -0,0 +1,14 @@
<?php
/**
* Class SubMFCompiler: used to call a protected method for testing purpose
*/
class SubMFCompiler extends MFCompiler {
public function CompileThemes($oBrandingNode, $sTempTargetDir) {
return parent::CompileThemes($oBrandingNode, $sTempTargetDir);
}
public function GetCompilationTimeStamp(){
return $this->sCompilationTimeStamp;
}
}

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<itop_design xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0">
<branding>
<themes>
<theme id="fullmoon" _delta="define">
<variables>
<variable id="ibo-page-banner--background-color">$ibo-color-red-600</variable>
<variable id="ibo-page-banner--text-color">$ibo-color-red-100</variable>
<variable id="ibo-page-banner--text-content">"THIS IS A TEST INSTANCE"</variable>
</variables>
<imports>
<import id="style1">style1.scss</import>
<import id="style2" xsi:type="variables">style2.scss</import>
<import id="style3" xsi:type="utility">style3.scss</import>
</imports>
<stylesheets>
<stylesheet id="fullmoon">../css/backoffice/main.scss</stylesheet>
<stylesheet id="environment-banner">../css/backoffice/themes/page-banner.scss</stylesheet>
</stylesheets>
<precompiled_stylesheet>itop-structure/precompiled-themes/test-red/main.css</precompiled_stylesheet>
</theme>
</themes>
</branding>
</itop_design>