mirror of
https://github.com/Combodo/iTop.git
synced 2026-03-09 19:14:19 +01:00
N°4739 - Remove precompiled themes unit test as they are no longer used since the introduction of DM classes style SCSS
This commit is contained in:
@@ -53,180 +53,6 @@ class ThemeHandlerTest extends ItopTestCase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test used to be notified by CI when precompiled styles are not up to date anymore in code repository.
|
||||
*
|
||||
* @param $xmlDataCusto
|
||||
* @param $sPrecompiledStylesheet
|
||||
* @param $oTheme
|
||||
*
|
||||
* @group beforeSetup
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testValidatePrecompiledStyles()
|
||||
{
|
||||
$aErrors = [];
|
||||
$aDataModelFiles=glob(APPROOT . utils::GetConfig()->Get('source_dir'). "/**/datamodel*.xml");
|
||||
$aImportsPaths = [
|
||||
APPROOT.'datamodels', // Simulate env-xxx when looking for files outside env-xxx
|
||||
APPROOT.'datamodels/2.x', // Simulate env-xxx when looking for files within env-xxx
|
||||
$this->sTmpDir, // For DM rules
|
||||
];
|
||||
|
||||
// First we have to compile the styles defined in the DM in order to feed it to the themes
|
||||
$oMFCompiler = new SubMFCompiler($this->createMock(\ModelFactory::class), '');
|
||||
$sDmCssContent = "";
|
||||
foreach ($aDataModelFiles as $sXmlDataCustoFilePath) {
|
||||
if (is_file($sXmlDataCustoFilePath)) {
|
||||
$oDom = new MFDocument();
|
||||
$oDom->load($sXmlDataCustoFilePath);
|
||||
|
||||
$oClassNodes = $oDom->GetNodes("/itop_design//class");
|
||||
foreach ($oClassNodes as $oClassNode) {
|
||||
$sClass = $oClassNode->getAttribute("id");
|
||||
$oFieldNodes = $oClassNode->GetNodes("fields/field[@xsi:type='AttributeEnum' or @xsi:type='AttributeMetaEnum']");
|
||||
foreach ($oFieldNodes as $oFieldNode) {
|
||||
$sAttCode = $oFieldNode->getAttribute("id");
|
||||
|
||||
// Values styles
|
||||
$oValueNodes = $oFieldNode->GetNodes("value");
|
||||
foreach ($oValueNodes as $oValueNode) {
|
||||
$sValueCode = $oValueNode->getAttribute("id");
|
||||
$sDmCssContent .= $oMFCompiler->GenerateStyleDataFromNode($oValueNode, $oMFCompiler::ENUM_STYLE_HOST_ELEMENT_TYPE_ENUM, $sClass, $sAttCode, $sValueCode)['scss'];
|
||||
}
|
||||
|
||||
// Default style
|
||||
$oDefaultStyleNode = $oFieldNode->GetOptionalElement('default_style');
|
||||
if ($oDefaultStyleNode) {
|
||||
$sDmCssContent .= $oMFCompiler->GenerateStyleDataFromNode($oDefaultStyleNode, $oMFCompiler::ENUM_STYLE_HOST_ELEMENT_TYPE_ENUM, $sClass, $sAttCode)['scss'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// - Write file
|
||||
$sDmStylesheetId = 'datamodel-compiled-scss-rules';
|
||||
file_put_contents($this->sDmCssAbsPath, $sDmCssContent);
|
||||
|
||||
foreach ($aDataModelFiles as $sXmlDataCustoFilePath)
|
||||
{
|
||||
if (is_file($sXmlDataCustoFilePath))
|
||||
{
|
||||
$sXmlDataCustoFilePath = realpath($sXmlDataCustoFilePath);
|
||||
$sContent = file_get_contents($sXmlDataCustoFilePath);
|
||||
if (strpos($sContent, "precompiled_stylesheet") !== false)
|
||||
{
|
||||
$oDom = new MFDocument();
|
||||
$oDom->load($sXmlDataCustoFilePath);
|
||||
$oThemeNodes = $oDom->GetNodes("/itop_design/branding/themes/theme");
|
||||
|
||||
// Parsing themes from DM
|
||||
foreach ($oThemeNodes as $oTheme)
|
||||
{
|
||||
/** @var \MFElement $oTheme */
|
||||
$sPrecompiledStylesheetUri = $oTheme->GetChildText('precompiled_stylesheet', '');
|
||||
if (empty($sPrecompiledStylesheetUri))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$sThemeId = $oTheme->getAttribute('id');
|
||||
|
||||
//echo "=== theme: $sThemeId ===\n";
|
||||
$sPrecompiledFilePath = $sSourceDir = APPROOT . utils::GetConfig()->Get('source_dir') . $sPrecompiledStylesheetUri;
|
||||
$sPreCompiledSig = ThemeHandler::GetSignature($sPrecompiledFilePath);
|
||||
if (empty(trim($sPreCompiledSig))){
|
||||
var_dump("$sThemeId: $sPrecompiledFilePath => " . realpath($sPrecompiledFilePath));
|
||||
}
|
||||
//echo " precompiled signature: $sPreCompiledSig\n";
|
||||
|
||||
if (empty($sPreCompiledSig))
|
||||
{
|
||||
$aErrors[] = "Signature in precompiled theme '".$sThemeId."' is not retrievable (cf precompiledsheet $sPrecompiledStylesheetUri / datamodel $sXmlDataCustoFilePath)";
|
||||
continue;
|
||||
}
|
||||
|
||||
$aThemeParameters = array(
|
||||
'variables' => array(),
|
||||
'variable_imports' => array(),
|
||||
'utility_imports' => array(),
|
||||
'stylesheets' => array(),
|
||||
);
|
||||
|
||||
/** @var \DOMNodeList $oVariables */
|
||||
$oVariables = $oTheme->GetNodes('variables/variable');
|
||||
foreach ($oVariables as $oVariable)
|
||||
{
|
||||
$sVariableId = $oVariable->getAttribute('id');
|
||||
$aThemeParameters['variables'][$sVariableId] = $oVariable->GetText();
|
||||
}
|
||||
|
||||
/** @var \DOMNodeList $oImports */
|
||||
$oImports = $oTheme->GetNodes('imports/import');
|
||||
$oFindStylesheetObject = new FindStylesheetObject();
|
||||
|
||||
foreach ($oImports as $oImport)
|
||||
{
|
||||
$sImportId = $oImport->getAttribute('id');
|
||||
|
||||
if($oImport->getAttribute('xsi:type') === 'variables'){
|
||||
$aThemeParameters['variable_imports'][$sImportId] = $oImport->GetText();
|
||||
} else {
|
||||
$aThemeParameters['utility_imports'][$sImportId] = $oImport->GetText();
|
||||
ThemeHandler::FindStylesheetFile($oImport->GetText(), $aImportsPaths, $oFindStylesheetObject);
|
||||
}
|
||||
}
|
||||
|
||||
/** @var \DOMNodeList $oStylesheets */
|
||||
$oStylesheets = $oTheme->GetNodes('stylesheets/stylesheet');
|
||||
foreach ($oStylesheets as $oStylesheet)
|
||||
{
|
||||
$sStylesheetId = $oStylesheet->getAttribute('id');
|
||||
$aThemeParameters['stylesheets'][$sStylesheetId] = $oStylesheet->GetText();
|
||||
ThemeHandler::FindStylesheetFile($oStylesheet->GetText(), $aImportsPaths, $oFindStylesheetObject);
|
||||
}
|
||||
|
||||
$sDmCssRelPath = str_ireplace($this->sTmpDir, '', $this->sDmCssAbsPath);
|
||||
$aThemeParameters['stylesheets'][$sDmStylesheetId] = $sDmCssRelPath;
|
||||
ThemeHandler::FindStylesheetFile($sDmCssRelPath, $aImportsPaths, $oFindStylesheetObject);
|
||||
|
||||
$aIncludedImages = ThemeHandler::GetIncludedImages($aThemeParameters['variables'], $oFindStylesheetObject->GetAllStylesheetPaths(), $sThemeId);
|
||||
$compiled_json_sig = ThemeHandler::ComputeSignature($aThemeParameters, $aImportsPaths, $aIncludedImages);
|
||||
//echo " current signature: $compiled_json_sig\n";
|
||||
|
||||
if ($sPreCompiledSig !== $compiled_json_sig)
|
||||
{
|
||||
$sSignatureDiffToPrint = $this->KeepSignatureDiff($sPreCompiledSig, $compiled_json_sig);
|
||||
|
||||
// Temporary bypass of the test if it concerns only the DM CSS rules
|
||||
$aSignatureDiff = json_decode($sSignatureDiffToPrint, true);
|
||||
if (isset($aSignatureDiff['stylesheets']['datamodel-compiled-scss-rules']) && (count($aSignatureDiff['stylesheets']) === 1) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var_dump($sSignatureDiffToPrint);
|
||||
$iLine = $oTheme->GetLineNo();
|
||||
$aErrors[] = " $sPrecompiledStylesheetUri declared in $sXmlDataCustoFilePath:$iLine.\n$sSignatureDiffToPrint";
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($aErrors)!=0)
|
||||
{
|
||||
$sMsg = "Below precompiled files are not up to date. Please run a new setup and save your precompiled files again:\n";
|
||||
$sMsg .= implode("\n", $aErrors);
|
||||
$this->fail($sMsg);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
function KeepSignatureDiff($sSignature1, $sSignature2) : string {
|
||||
$aSignature1 = json_decode($sSignature1, true);
|
||||
$aSignature2 = json_decode($sSignature2, true);
|
||||
|
||||
Reference in New Issue
Block a user