Polymorphic type

This commit is contained in:
Eric Espie
2026-01-13 18:00:19 +01:00
parent c075a5c145
commit 90729f84b6
14 changed files with 555 additions and 87 deletions

View File

@@ -0,0 +1,95 @@
<?php
/*
* @copyright Copyright (C) 2010-2026 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
use Combodo\iTop\PropertyType\PropertyTypeDesign;
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
/**
* @copyright Copyright (C) 2010-2026 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
class DashboardSerializerTest extends ItopDataTestCase
{
/**
* @dataProvider XMLSerializerProvider
*
* @param $normalizedValue
* @param string $sPropertyTypeXML
* @param string $sXMLContent
*
* @return void
* @throws \DOMException
*/
public function testSerializeXML($normalizedValue, string $sXMLContent)
{
ServiceLocator::GetInstance()->RegisterService('ModelReflection', new ModelReflectionRuntime());
$oDOMDocument = new PropertyTypeDesign();
$oDOMDocument->preserveWhiteSpace = false;
$oDOMDocument->formatOutput = true;
/** @var \Combodo\iTop\DesignElement $oRootNode */
$oRootNode = $oDOMDocument->createElement('root');
$oDOMDocument->appendChild($oRootNode);
Combodo\iTop\PropertyType\Serializer\XMLSerializer::GetInstance()->Serialize($normalizedValue, $oRootNode, 'DashboardDefinition', 'Dashboard');
$sActualXML = $oDOMDocument->saveXML();
$this->AssertEqualiTopXML($sXMLContent, $sActualXML);
}
public function XMLSerializerProvider()
{
return [
'Basic test should serialize to XML' => [
'normalizedValue' => [
'schema_version' => 2,
'id' => 'WelcomeMenuPage',
'title' => 'Bienvenido al Panel de Control Panel',
'refresh' => '60',
'pos_dashlets' => [
'CUSTOM_WelcomeMenuPage_ID_row0_col0_1' => [
'position_x' => 1,
'position_y' => 2,
'width' => 3,
'height' => 1,
'dashlet' => [
'type' => 'DashletHeaderStatic',
'properties' => [
'title' => 'Menu:ConfigManagementCI',
'icon' => '../images/icons/icons8-database.svg',
],
],
],
],
],
'sXMLContent' => <<<XML
<?xml version="1.0"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-Dashboard-Grid">
<title>Bienvenido al Panel de Control Panel</title>
<refresh>60</refresh>
<pos_dashlets>
<pos_dashlet id="CUSTOM_WelcomeMenuPage_ID_row0_col0_1">
<position_x>1</position_x>
<position_y>2</position_y>
<width>3</width>
<height>1</height>
<dashlet xsi:type="DashletHeaderStatic">
<title>Menu:ConfigManagementCI</title>
<icon>../images/icons/icons8-database.svg</icon>
</dashlet>
</pos_dashlet>
</pos_dashlets>
</root>
XML,
],
];
}
}