mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
Polymorphic type
This commit is contained in:
@@ -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,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,8 @@ class XMLSerializerTest extends ItopDataTestCase
|
||||
|
||||
/** @var \Combodo\iTop\DesignElement $oRootNode */
|
||||
$oRootNode = $oDOMDocument->createElement('root');
|
||||
$oRootNode->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
|
||||
|
||||
$oDOMDocument->appendChild($oRootNode);
|
||||
|
||||
Combodo\iTop\PropertyType\Serializer\XMLSerializer::GetInstance()->SerializeForPropertyType($normalizedValue, $oRootNode, $sPropertyTypeXML);
|
||||
@@ -56,7 +58,7 @@ class XMLSerializerTest extends ItopDataTestCase
|
||||
XML,
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root>text</root>
|
||||
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">text</root>
|
||||
XML,
|
||||
],
|
||||
'Collection of values as CSV' => [
|
||||
@@ -74,7 +76,7 @@ XML,
|
||||
XML,
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root>Contact,Organization</root>
|
||||
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Contact,Organization</root>
|
||||
XML,
|
||||
],
|
||||
'Collection of values as id attribute' => [
|
||||
@@ -94,7 +96,7 @@ XML,
|
||||
XML,
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root>
|
||||
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<item id="Contact"/>
|
||||
<item id="Organization"/>
|
||||
</root>
|
||||
@@ -134,7 +136,7 @@ XML,
|
||||
XML,
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root>
|
||||
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<item_count>2</item_count>
|
||||
<item_0_title_property>title_a</item_0_title_property>
|
||||
<item_0_class_property>class_a</item_0_class_property>
|
||||
@@ -164,10 +166,83 @@ XML,
|
||||
XML,
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root>
|
||||
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<title_property>title</title_property>
|
||||
<class_property>class</class_property>
|
||||
</root>
|
||||
XML,
|
||||
],
|
||||
'Polymorphic tree' => [
|
||||
'normalizedValue' => [
|
||||
'type' => 'DashletHeaderStatic',
|
||||
'properties' => [
|
||||
'title' => 'Menu:ConfigManagementCI',
|
||||
'icon' => '../images/icons/icons8-database.svg',
|
||||
],
|
||||
],
|
||||
'sPropertyTypeXML' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<property_type id="property_tree_test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyType" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<extends>Dashlet</extends>
|
||||
<definition xsi:type="Combodo-ValueType-Polymorphic">
|
||||
<label>Dashlet</label>
|
||||
<allowed-types>
|
||||
<allowed-type>Dashlet</allowed-type>
|
||||
</allowed-types>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="DashletHeaderStatic">
|
||||
<title>Menu:ConfigManagementCI</title>
|
||||
<icon>../images/icons/icons8-database.svg</icon>
|
||||
</root>
|
||||
XML,
|
||||
],
|
||||
'Collection of tree with id' => [
|
||||
'normalizedValue' => [
|
||||
'a' => [
|
||||
'title_property' => 'title_a',
|
||||
'class_property' => 'class_a',
|
||||
],
|
||||
'b' => [
|
||||
'title_property' => 'title_b',
|
||||
'class_property' => 'class_b',
|
||||
],
|
||||
],
|
||||
'sPropertyTypeXML' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<property_type id="collection_test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyType" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<extends>Dashlet</extends>
|
||||
<definition xsi:type="Combodo-ValueType-Collection">
|
||||
<xml-format xsi:type="Combodo-XMLFormat-CollectionWithId">
|
||||
<tag-name>item</tag-name>
|
||||
</xml-format>
|
||||
<prototype>
|
||||
<node id="title_property" xsi:type="Combodo-ValueType-Label">
|
||||
<label>UI:BasicTest:Prop-Title</label>
|
||||
</node>
|
||||
<node id="class_property" xsi:type="Combodo-ValueType-Class">
|
||||
<label>UI:BasicTest:Prop-Class</label>
|
||||
<categories-csv>test</categories-csv>
|
||||
</node>
|
||||
</prototype>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<item id="a">
|
||||
<title_property>title_a</title_property>
|
||||
<class_property>class_a</class_property>
|
||||
</item>
|
||||
<item id="b">
|
||||
<title_property>title_b</title_property>
|
||||
<class_property>class_b</class_property>
|
||||
</item>
|
||||
</root>
|
||||
XML,
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user