mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°9065 - XML Definition for Dashlet properties
This commit is contained in:
@@ -182,7 +182,6 @@ class FormBindingTest extends AbstractFormsTest
|
||||
'Attribute -> Boolean' => [AttributeIOFormat::class, BooleanIOFormat::class],
|
||||
'Attribute -> Class' => [AttributeIOFormat::class, ClassIOFormat::class],
|
||||
'Attribute -> Number' => [AttributeIOFormat::class, NumberIOFormat::class],
|
||||
'Attribute -> String' => [AttributeIOFormat::class, StringIOFormat::class],
|
||||
|
||||
'Boolean => Attribute' => [BooleanIOFormat::class, AttributeIOFormat::class],
|
||||
'Boolean => Class' => [BooleanIOFormat::class, ClassIOFormat::class],
|
||||
@@ -192,7 +191,6 @@ class FormBindingTest extends AbstractFormsTest
|
||||
'Class => Attribute' => [ClassIOFormat::class, AttributeIOFormat::class],
|
||||
'Class => Boolean' => [ClassIOFormat::class, BooleanIOFormat::class],
|
||||
'Class => Number' => [ClassIOFormat::class, NumberIOFormat::class],
|
||||
'Class -> String' => [ClassIOFormat::class, StringIOFormat::class],
|
||||
|
||||
'Number => Attribute' => [NumberIOFormat::class, AttributeIOFormat::class],
|
||||
'Number => Class' => [NumberIOFormat::class, ClassIOFormat::class],
|
||||
@@ -227,8 +225,10 @@ class FormBindingTest extends AbstractFormsTest
|
||||
{
|
||||
return [
|
||||
'Attribute -> Attribute' => [AttributeIOFormat::class, AttributeIOFormat::class],
|
||||
'Attribute -> String' => [AttributeIOFormat::class, StringIOFormat::class],
|
||||
'Boolean => Boolean' => [BooleanIOFormat::class, BooleanIOFormat::class],
|
||||
'Class => Class' => [ClassIOFormat::class, ClassIOFormat::class],
|
||||
'Class -> String' => [ClassIOFormat::class, StringIOFormat::class],
|
||||
'Number => Number' => [NumberIOFormat::class, NumberIOFormat::class],
|
||||
'String => String' => [StringIOFormat::class, StringIOFormat::class],
|
||||
];
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\Forms\Compiler\FormsCompiler;
|
||||
use Combodo\iTop\PropertyType\Compiler\PropertyTypeCompiler;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
|
||||
@@ -18,15 +18,15 @@ class FormsCompilerTest extends ItopDataTestCase
|
||||
* @param string $sExpectedPHP
|
||||
*
|
||||
* @return void
|
||||
* @throws \Combodo\iTop\Forms\Compiler\FormsCompilerException
|
||||
* @throws \Combodo\iTop\PropertyTree\PropertyTreeException
|
||||
* @throws \Combodo\iTop\PropertyType\Compiler\PropertyTypeCompilerException
|
||||
* @throws \Combodo\iTop\PropertyType\PropertyTypeException
|
||||
* @throws \DOMFormatException
|
||||
*/
|
||||
public function testCompileFormFromXML(string $sXMLContent, string $sExpectedPHP)
|
||||
{
|
||||
ServiceLocator::GetInstance()->RegisterService('ModelReflection', new ModelReflectionRuntime());
|
||||
|
||||
$sProducedPHP = FormsCompiler::GetInstance()->CompileFormFromXML($sXMLContent);
|
||||
$sProducedPHP = PropertyTypeCompiler::GetInstance()->CompileFormFromXML($sXMLContent);
|
||||
|
||||
$this->AssertPHPCodeIsValid($sProducedPHP);
|
||||
$sMessage = $this->dataName();
|
||||
@@ -39,21 +39,20 @@ class FormsCompilerTest extends ItopDataTestCase
|
||||
'Basic scalar properties should generate PHP' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<property_tree id="basic_test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<nodes>
|
||||
<node id="title_property">
|
||||
<label>UI:BasicTest:Prop-Title</label>
|
||||
<value-type xsi:type="Combodo-ValueType-Label">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="class_property">
|
||||
<label>UI:BasicTest:Prop-Class</label>
|
||||
<value-type xsi:type="Combodo-ValueType-Class">
|
||||
<categories-csv>test</categories-csv>
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</property_tree>
|
||||
<property_type id="basic_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-PropertyTree">
|
||||
<nodes>
|
||||
<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>
|
||||
</nodes>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedPHP' => <<<PHP
|
||||
class FormFor__basic_test extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
@@ -77,10 +76,13 @@ PHP,
|
||||
'Empty property tree should generate minimal PHP' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<property_tree id="EmptyTest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<nodes>
|
||||
</nodes>
|
||||
</property_tree>
|
||||
<property_type id="EmptyTest" 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-PropertyTree">
|
||||
<nodes>
|
||||
</nodes>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedPHP' => <<<PHP
|
||||
class FormFor__EmptyTest extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
@@ -94,10 +96,13 @@ PHP,
|
||||
'Empty property tree lower case should generate lower case class name' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<property_tree id="empty_test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<nodes>
|
||||
</nodes>
|
||||
</property_tree>
|
||||
<property_type id="empty_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-PropertyTree">
|
||||
<nodes>
|
||||
</nodes>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedPHP' => <<<PHP
|
||||
class FormFor__empty_test extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
@@ -111,82 +116,63 @@ PHP,
|
||||
'Properties with all value-types' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<property_tree id="AllValueTypesTest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<nodes>
|
||||
<node id="aggregate_function_property">
|
||||
<label>UI:AggregateFunction</label>
|
||||
<value-type xsi:type="Combodo-ValueType-AggregateFunction">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="choice_property">
|
||||
<label>UI:Choice</label>
|
||||
<value-type xsi:type="Combodo-ValueType-Choice">
|
||||
<values>
|
||||
<value id="value_a">
|
||||
<label>Label A</label>
|
||||
</value>
|
||||
<value id="value_b">
|
||||
<label>Label B</label>
|
||||
</value>
|
||||
</values>
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="class_property">
|
||||
<label>UI:Class</label>
|
||||
<value-type xsi:type="Combodo-ValueType-Class">
|
||||
<categories-csv>test</categories-csv>
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="class_attribute_property">
|
||||
<label>UI:ClassAttribute</label>
|
||||
<value-type xsi:type="Combodo-ValueType-ClassAttribute">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="class_attribute_group_by_property">
|
||||
<label>UI:ClassAttributeGroupBy</label>
|
||||
<value-type xsi:type="Combodo-ValueType-ClassAttributeGroupBy">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="class_attribute_value_property">
|
||||
<label>UI:ClassAttributeValue</label>
|
||||
<value-type xsi:type="Combodo-ValueType-ClassAttributeValue">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="integer_property">
|
||||
<label>UI:Integer</label>
|
||||
<value-type xsi:type="Combodo-ValueType-Integer">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="label_property">
|
||||
<label>UI:Label</label>
|
||||
<value-type xsi:type="Combodo-ValueType-Label">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="oql_property">
|
||||
<label>UI:OQL</label>
|
||||
<value-type xsi:type="Combodo-ValueType-OQL">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="string_property">
|
||||
<label>UI:String</label>
|
||||
<value-type xsi:type="Combodo-ValueType-String">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="choice_from_input">
|
||||
<label>UI:ChoiceFromInput</label>
|
||||
<value-type xsi:type="Combodo-ValueType-ChoiceFromInput">
|
||||
<values>
|
||||
<value id="value_a">
|
||||
<label>{{class_attribute_property.label}}</label>
|
||||
</value>
|
||||
<value id="value_b">
|
||||
<label>{{class_attribute_group_by_property.label}}</label>
|
||||
</value>
|
||||
</values>
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</property_tree>
|
||||
<property_type id="AllValueTypesTest" 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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="aggregate_function_property" xsi:type="Combodo-ValueType-AggregateFunction">
|
||||
<label>UI:AggregateFunction</label>
|
||||
</node>
|
||||
<node id="choice_property" xsi:type="Combodo-ValueType-Choice">
|
||||
<label>UI:Choice</label>
|
||||
<values>
|
||||
<value id="value_a">
|
||||
<label>Label A</label>
|
||||
</value>
|
||||
<value id="value_b">
|
||||
<label>Label B</label>
|
||||
</value>
|
||||
</values>
|
||||
</node>
|
||||
<node id="class_property" xsi:type="Combodo-ValueType-Class">
|
||||
<label>UI:Class</label>
|
||||
<categories-csv>test</categories-csv>
|
||||
</node>
|
||||
<node id="class_attribute_property" xsi:type="Combodo-ValueType-ClassAttribute">
|
||||
<label>UI:ClassAttribute</label>
|
||||
</node>
|
||||
<node id="class_attribute_group_by_property" xsi:type="Combodo-ValueType-ClassAttributeGroupBy">
|
||||
<label>UI:ClassAttributeGroupBy</label>
|
||||
</node>
|
||||
<node id="class_attribute_value_property" xsi:type="Combodo-ValueType-ClassAttributeValue">
|
||||
<label>UI:ClassAttributeValue</label>
|
||||
</node>
|
||||
<node id="integer_property" xsi:type="Combodo-ValueType-Integer">
|
||||
<label>UI:Integer</label>
|
||||
</node>
|
||||
<node id="label_property" xsi:type="Combodo-ValueType-Label">
|
||||
<label>UI:Label</label>
|
||||
</node>
|
||||
<node id="oql_property" xsi:type="Combodo-ValueType-OQL">
|
||||
<label>UI:OQL</label>
|
||||
</node>
|
||||
<node id="string_property" xsi:type="Combodo-ValueType-String">
|
||||
<label>UI:String</label>
|
||||
</node>
|
||||
<node id="choice_from_input" xsi:type="Combodo-ValueType-ChoiceFromInput">
|
||||
<label>UI:ChoiceFromInput</label>
|
||||
<values>
|
||||
<value id="value_a">
|
||||
<label>{{class_attribute_property.label}}</label>
|
||||
</value>
|
||||
<value id="value_b">
|
||||
<label>{{class_attribute_group_by_property.label}}</label>
|
||||
</value>
|
||||
</values>
|
||||
</node>
|
||||
</nodes>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedPHP' => <<<PHP
|
||||
class FormFor__AllValueTypesTest extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
@@ -252,28 +238,25 @@ PHP,
|
||||
'Collection of trees' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<property_tree id="collection_of_trees_test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<property_type id="collection_of_trees_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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="sub_tree_collection">
|
||||
<node id="sub_tree_collection" xsi:type="Combodo-ValueType-Collection">
|
||||
<label>UI:SubTree</label>
|
||||
<value-type xsi:type="Combodo-ValueType-Collection">
|
||||
<prototype>
|
||||
<node id="string_property">
|
||||
<label>UI:String</label>
|
||||
<value-type xsi:type="Combodo-ValueType-String">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="integer_property">
|
||||
<label>UI:Integer</label>
|
||||
<relevance-condition>{{string_property.text != 'no-display'}}</relevance-condition>
|
||||
<value-type xsi:type="Combodo-ValueType-Integer">
|
||||
</value-type>
|
||||
</node>
|
||||
</prototype>
|
||||
</value-type>
|
||||
<prototype>
|
||||
<node id="string_property" xsi:type="Combodo-ValueType-String">
|
||||
<label>UI:String</label>
|
||||
</node>
|
||||
<node id="integer_property" xsi:type="Combodo-ValueType-Integer">
|
||||
<label>UI:Integer</label>
|
||||
<relevance-condition>{{string_property.text != 'no-display'}}</relevance-condition>
|
||||
</node>
|
||||
</prototype>
|
||||
</node>
|
||||
</nodes>
|
||||
</property_tree>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedPHP' => <<<PHP
|
||||
class SubFormFor__collection_of_trees_test__sub_tree_collection extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
@@ -313,17 +296,18 @@ PHP,
|
||||
'Static inputs should be bound and invalid input should be ignored' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<node id="input_static_test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<nodes>
|
||||
<node id="class_attribute_property">
|
||||
<label>UI:ClassAttribute</label>
|
||||
<value-type xsi:type="Combodo-ValueType-ClassAttribute">
|
||||
<property_type id="input_static_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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="class_attribute_property" xsi:type="Combodo-ValueType-ClassAttribute">
|
||||
<label>UI:ClassAttribute</label>
|
||||
<class>Contact</class>
|
||||
<invalid-input>Test</invalid-input>
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
</node>
|
||||
</nodes>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedPHP' => <<<PHP
|
||||
class FormFor__input_static_test extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
@@ -342,17 +326,18 @@ PHP,
|
||||
'Quotes should be handled gracefully' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<node id="input_quotes_test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<nodes>
|
||||
<node id="class_attribute_property">
|
||||
<label>'Class' and "Attribute"</label>
|
||||
<value-type xsi:type="Combodo-ValueType-ClassAttribute">
|
||||
<property_type id="input_quotes_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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="class_attribute_property" xsi:type="Combodo-ValueType-ClassAttribute">
|
||||
<label>'Class' and "Attribute"</label>
|
||||
<class>{{CONCAT("'", '"')}}</class>
|
||||
<category>'Class' and "Attribute"</category>
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
</node>
|
||||
</nodes>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedPHP' => <<<PHP
|
||||
class FormFor__input_quotes_test extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
@@ -376,22 +361,21 @@ PHP,
|
||||
'Dynamic input should be bound' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<node id="input_binding_test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<nodes>
|
||||
<node id="class_property">
|
||||
<label>UI:Class</label>
|
||||
<value-type xsi:type="Combodo-ValueType-Class">
|
||||
<categories-csv>test</categories-csv>
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="class_attribute_property">
|
||||
<label>UI:ClassAttribute</label>
|
||||
<value-type xsi:type="Combodo-ValueType-ClassAttribute">
|
||||
<property_type id="input_binding_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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="class_property" xsi:type="Combodo-ValueType-Class">
|
||||
<label>UI:Class</label>
|
||||
<categories-csv>test</categories-csv>
|
||||
</node>
|
||||
<node id="class_attribute_property" xsi:type="Combodo-ValueType-ClassAttribute">
|
||||
<label>UI:ClassAttribute</label>
|
||||
<class>{{class_property.text}}</class>
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
</node>
|
||||
</nodes>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedPHP' => <<<PHP
|
||||
class FormFor__input_binding_test extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
@@ -416,22 +400,21 @@ PHP,
|
||||
'Dynamic input can be an expression' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<node id="input_binding_expression" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<property_type id="input_binding_expression" 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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="class_property">
|
||||
<node id="class_property" xsi:type="Combodo-ValueType-Class">
|
||||
<label>UI:Class</label>
|
||||
<value-type xsi:type="Combodo-ValueType-Class">
|
||||
<categories-csv>test</categories-csv>
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="class_attribute_property">
|
||||
<node id="class_attribute_property" xsi:type="Combodo-ValueType-ClassAttribute">
|
||||
<label>UI:ClassAttribute</label>
|
||||
<value-type xsi:type="Combodo-ValueType-ClassAttribute">
|
||||
<class>{{IF(class_property.value = '', 'Person', class_property.value)}}</class>
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedPHP' => <<<PHP
|
||||
class FormFor__input_binding_expression extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
@@ -461,21 +444,20 @@ PHP,
|
||||
'Relevance condition should generate a boolean block expression' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<node id="RelevanceCondition" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<property_type id="RelevanceCondition" 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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="source_property">
|
||||
<node id="source_property" xsi:type="Combodo-ValueType-String">
|
||||
<label>UI:Source</label>
|
||||
<value-type xsi:type="Combodo-ValueType-String">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="dependant_property">
|
||||
<node id="dependant_property" xsi:type="Combodo-ValueType-String">
|
||||
<label>UI:Dependant</label>
|
||||
<relevance-condition>{{source_property.text != 'count'}}</relevance-condition>
|
||||
<value-type xsi:type="Combodo-ValueType-String">
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedPHP' => <<<PHP
|
||||
class FormFor__RelevanceCondition extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
@@ -503,26 +485,23 @@ PHP,
|
||||
'Complex Relevance condition should generate a boolean block expression' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<node id="ComplexRelevanceCondition" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<property_type id="ComplexRelevanceCondition" 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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="source_a_property">
|
||||
<node id="source_a_property" xsi:type="Combodo-ValueType-String">
|
||||
<label>UI:Source</label>
|
||||
<value-type xsi:type="Combodo-ValueType-String">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="source_b_property">
|
||||
<node id="source_b_property" xsi:type="Combodo-ValueType-String">
|
||||
<label>UI:Source</label>
|
||||
<value-type xsi:type="Combodo-ValueType-String">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="dependant_property">
|
||||
<node id="dependant_property" xsi:type="Combodo-ValueType-String">
|
||||
<label>UI:Dependant</label>
|
||||
<relevance-condition>{{IF(source_a_property.text != '', source_a_property.text, source_b_property.text)}}</relevance-condition>
|
||||
<value-type xsi:type="Combodo-ValueType-String">
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedPHP' => <<<PHP
|
||||
class FormFor__ComplexRelevanceCondition extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
@@ -551,60 +530,73 @@ class FormFor__ComplexRelevanceCondition extends Combodo\iTop\Forms\Block\Base\F
|
||||
}
|
||||
PHP,
|
||||
],
|
||||
'Class category for value type class' => [
|
||||
'Sub form generate a sub-form' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<node id="ClassCategory" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<nodes>
|
||||
<node id="class_property">
|
||||
<label>UI:Class</label>
|
||||
<value-type xsi:type="Combodo-ValueType-Class">
|
||||
<categories-csv>addon/authentication,grant_by_profile,silo</categories-csv>
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
<property_typeproperty_type id="SubFormTest" 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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="sub_form_property" xsi:type="Combodo-ValueType-PropertyTree">
|
||||
<label>UI:SubForm:Title</label>
|
||||
<nodes>
|
||||
<node id="string_property" xsi:type="Combodo-ValueType-String">
|
||||
<label>UI:String</label>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
</nodes>
|
||||
</definition>
|
||||
</property_typeproperty_type>
|
||||
XML,
|
||||
'sExpectedPHP' => <<<PHP
|
||||
class FormFor__ClassCategory extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
class SubFormFor__SubFormTest__sub_form_property extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
{
|
||||
protected function BuildForm(): void
|
||||
{
|
||||
\$this->Add('class_property', 'Combodo\iTop\Forms\Block\Base\ChoiceFormBlock', [
|
||||
'label' => 'UI:Class',
|
||||
'choices' => [
|
||||
\Dict::S('Class:ActionEmail') => 'ActionEmail',
|
||||
\Dict::S('Class:ActionNewsroom') => 'ActionNewsroom',
|
||||
\Dict::S('Class:AuditCategory') => 'AuditCategory',
|
||||
\Dict::S('Class:AuditDomain') => 'AuditDomain',
|
||||
\Dict::S('Class:AuditRule') => 'AuditRule',
|
||||
\Dict::S('Class:OAuthClientAzure') => 'OAuthClientAzure',
|
||||
\Dict::S('Class:OAuthClientGoogle') => 'OAuthClientGoogle',
|
||||
\Dict::S('Class:QueryOQL') => 'QueryOQL',
|
||||
\Dict::S('Class:SynchroAttExtKey') => 'SynchroAttExtKey',
|
||||
\Dict::S('Class:SynchroAttLinkSet') => 'SynchroAttLinkSet',
|
||||
\Dict::S('Class:SynchroAttribute') => 'SynchroAttribute',
|
||||
\Dict::S('Class:SynchroDataSource') => 'SynchroDataSource',
|
||||
\Dict::S('Class:SynchroLog') => 'SynchroLog',
|
||||
\Dict::S('Class:SynchroReplica') => 'SynchroReplica',
|
||||
\Dict::S('Class:TriggerOnAttachmentCreate') => 'TriggerOnAttachmentCreate',
|
||||
\Dict::S('Class:TriggerOnAttachmentDelete') => 'TriggerOnAttachmentDelete',
|
||||
\Dict::S('Class:TriggerOnAttachmentDownload') => 'TriggerOnAttachmentDownload',
|
||||
\Dict::S('Class:TriggerOnAttributeBlobDownload') => 'TriggerOnAttributeBlobDownload',
|
||||
\Dict::S('Class:TriggerOnObjectCreate') => 'TriggerOnObjectCreate',
|
||||
\Dict::S('Class:TriggerOnObjectDelete') => 'TriggerOnObjectDelete',
|
||||
\Dict::S('Class:TriggerOnObjectMention') => 'TriggerOnObjectMention',
|
||||
\Dict::S('Class:TriggerOnObjectUpdate') => 'TriggerOnObjectUpdate',
|
||||
\Dict::S('Class:TriggerOnPortalUpdate') => 'TriggerOnPortalUpdate',
|
||||
\Dict::S('Class:TriggerOnStateEnter') => 'TriggerOnStateEnter',
|
||||
\Dict::S('Class:TriggerOnStateLeave') => 'TriggerOnStateLeave',
|
||||
\Dict::S('Class:TriggerOnThresholdReached') => 'TriggerOnThresholdReached',
|
||||
\Dict::S('Class:URP_Profiles') => 'URP_Profiles',
|
||||
\Dict::S('Class:URP_UserOrg') => 'URP_UserOrg',
|
||||
\Dict::S('Class:UserExternal') => 'UserExternal',
|
||||
\Dict::S('Class:UserLDAP') => 'UserLDAP',
|
||||
\Dict::S('Class:UserLocal') => 'UserLocal',
|
||||
\$this->Add('string_property', 'Combodo\iTop\Forms\Block\Base\TextFormBlock', [
|
||||
'label' => 'UI:String',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
class FormFor__SubFormTest extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
{
|
||||
protected function BuildForm(): void
|
||||
{
|
||||
\$this->Add('sub_form_property', 'SubFormFor__SubFormTest__sub_form_property', [
|
||||
'label' => 'UI:SubForm:Title',
|
||||
]);
|
||||
}
|
||||
}
|
||||
PHP,
|
||||
],
|
||||
'Collection of values' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<property_typeproperty_type id="CollectionOfValuesTest" 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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="coll" xsi:type="Combodo-ValueType-CollectionOfValues">
|
||||
<label>UI:ClassAttributeValue</label>
|
||||
<value-type xsi:type="Combodo-ValueType-ClassAttributeValue">
|
||||
<class>Contact</class>
|
||||
<attribute>status</attribute>
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</definition>
|
||||
</property_typeproperty_type>
|
||||
XML,
|
||||
'sExpectedPHP' => <<<PHP
|
||||
class FormFor__CollectionOfValuesTest extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
{
|
||||
protected function BuildForm(): void
|
||||
{
|
||||
\$this->Add('coll', 'Combodo\iTop\Forms\Block\DataModel\AttributeValueChoiceFormBlock', [
|
||||
'label' => 'UI:ClassAttributeValue',
|
||||
'multiple' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -613,10 +605,13 @@ PHP,
|
||||
'test' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<node id="Test" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<nodes>
|
||||
</nodes>
|
||||
</node>
|
||||
<property_typeproperty_type id="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-PropertyTree">
|
||||
<nodes>
|
||||
</nodes>
|
||||
</definition>
|
||||
</property_typeproperty_type>
|
||||
XML,
|
||||
'sExpectedPHP' => <<<PHP
|
||||
class FormFor__Test extends Combodo\iTop\Forms\Block\Base\FormBlock
|
||||
@@ -631,121 +626,143 @@ PHP,
|
||||
|
||||
/**
|
||||
* @dataProvider CompileFormFromInvalidXMLProvider
|
||||
*
|
||||
* @param string $sXMLContent
|
||||
* @param string $sExpectedClass
|
||||
* @param string $sExpectedMessage
|
||||
*
|
||||
* @return void
|
||||
* @throws \Combodo\iTop\Forms\Compiler\FormsCompilerException
|
||||
* @throws \Combodo\iTop\PropertyTree\PropertyTreeException
|
||||
* @throws \Combodo\iTop\PropertyType\Compiler\PropertyTypeCompilerException
|
||||
* @throws \Combodo\iTop\PropertyType\PropertyTypeException
|
||||
* @throws \DOMFormatException
|
||||
*/
|
||||
public function testCompileFormFromInvalidXML(string $sXMLContent, string $sExpectedClass, string $sExpectedMessage)
|
||||
{
|
||||
$this->expectException($sExpectedClass);
|
||||
$this->expectExceptionMessage($sExpectedMessage);
|
||||
FormsCompiler::GetInstance()->CompileFormFromXML($sXMLContent);
|
||||
PropertyTypeCompiler::GetInstance()->CompileFormFromXML($sXMLContent);
|
||||
}
|
||||
|
||||
public function CompileFormFromInvalidXMLProvider()
|
||||
{
|
||||
return [
|
||||
'Invalid OQL expression in condition' => [
|
||||
'sXMLContent' => <<<XML
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<node id="RelevanceCondition" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<property_type id="RelevanceCondition" 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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="dependant_property">
|
||||
<node id="dependant_property" xsi:type="Combodo-ValueType-String">
|
||||
<label>UI:Dependant</label>
|
||||
<relevance-condition>{{source_property.text == 'count'}}</relevance-condition>
|
||||
<value-type xsi:type="Combodo-ValueType-String">
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedClass' => 'Combodo\iTop\PropertyTree\PropertyTreeException',
|
||||
'sExpectedClass' => 'Combodo\iTop\PropertyType\PropertyTypeException',
|
||||
'sExpectedMessage' => 'Node: dependant_property, invalid syntax in condition: Unexpected token EQ - found \'=\' at 22 in \'source_property.text == \'count\'\'',
|
||||
],
|
||||
|
||||
'Unknown source in relevance condition' => [
|
||||
'sXMLContent' => <<<XML
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<node id="RelevanceCondition" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<property_type id="RelevanceCondition" 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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="dependant_property">
|
||||
<node id="dependant_property" xsi:type="Combodo-ValueType-String">
|
||||
<label>UI:Dependant</label>
|
||||
<relevance-condition>{{source_property.text = 'count'}}</relevance-condition>
|
||||
<value-type xsi:type="Combodo-ValueType-String">
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedClass' => 'Combodo\iTop\PropertyTree\PropertyTreeException',
|
||||
'sExpectedClass' => 'Combodo\iTop\PropertyType\PropertyTypeException',
|
||||
'sExpectedMessage' => 'Node: dependant_property, invalid source in condition: source_property',
|
||||
],
|
||||
|
||||
'Unknown output in relevance condition' => [
|
||||
'sXMLContent' => <<<XML
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<node id="RelevanceCondition" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<property_type id="RelevanceCondition" 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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="source_property">
|
||||
<node id="source_property" xsi:type="Combodo-ValueType-String">
|
||||
<label>UI:Source</label>
|
||||
<value-type xsi:type="Combodo-ValueType-String">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="dependant_property">
|
||||
<node id="dependant_property" xsi:type="Combodo-ValueType-String">
|
||||
<label>UI:Dependant</label>
|
||||
<relevance-condition>{{source_property.text_output != 'count'}}</relevance-condition>
|
||||
<value-type xsi:type="Combodo-ValueType-String">
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedClass' => 'Combodo\iTop\PropertyTree\PropertyTreeException',
|
||||
'sExpectedClass' => 'Combodo\iTop\PropertyType\PropertyTypeException',
|
||||
'sExpectedMessage' => 'Node: dependant_property, invalid output in condition: source_property.text_output',
|
||||
],
|
||||
|
||||
'Missing output or source in relevance condition' => [
|
||||
'sXMLContent' => <<<XML
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<node id="RelevanceCondition" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<property_type id="RelevanceCondition" 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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="source_property">
|
||||
<node id="source_property" xsi:type="Combodo-ValueType-String">
|
||||
<label>UI:Source</label>
|
||||
<value-type xsi:type="Combodo-ValueType-String">
|
||||
</value-type>
|
||||
</node>
|
||||
<node id="dependant_property">
|
||||
<node id="dependant_property" xsi:type="Combodo-ValueType-String">
|
||||
<label>UI:Dependant</label>
|
||||
<relevance-condition>{{source_property != 'count'}}</relevance-condition>
|
||||
<value-type xsi:type="Combodo-ValueType-String">
|
||||
</value-type>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedClass' => 'Combodo\iTop\PropertyTree\PropertyTreeException',
|
||||
'sExpectedClass' => 'Combodo\iTop\PropertyType\PropertyTypeException',
|
||||
'sExpectedMessage' => 'Node: dependant_property, missing output or source in condition: source_property',
|
||||
],
|
||||
|
||||
'Missing value-type in node specification' => [
|
||||
'sXMLContent' => <<<XML
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<node id="RelevanceCondition" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Combodo-PropertyTree" xsi:noNamespaceSchemaLocation = "https://www.combodo.com/itop-schema/3.3">
|
||||
<property_type id="RelevanceCondition" 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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="source_property">
|
||||
<label>UI:Source</label>
|
||||
</node>
|
||||
</nodes>
|
||||
</node>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedClass' => 'Combodo\iTop\PropertyTree\PropertyTreeException',
|
||||
'sExpectedClass' => 'Combodo\iTop\PropertyType\PropertyTypeException',
|
||||
'sExpectedMessage' => 'Node: source_property, missing value-type in node specification',
|
||||
],
|
||||
|
||||
'Wrong class for value-type in node specification' => [
|
||||
'sXMLContent' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<property_type id="RelevanceCondition" 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-PropertyTree">
|
||||
<nodes>
|
||||
<node id="source_property" xsi:type="Test-Combodo">
|
||||
<label>UI:Source</label>
|
||||
</node>
|
||||
</nodes>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedClass' => 'Combodo\iTop\PropertyType\PropertyTypeException',
|
||||
'sExpectedMessage' => 'Node: source_property, unknown type node class: "Test-Combodo"',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2026 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
use Combodo\iTop\PropertyType\Compiler\PropertyTypeCompiler;
|
||||
use Combodo\iTop\PropertyType\PropertyTypeDesign;
|
||||
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
|
||||
class XMLSerializerTest extends ItopDataTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider XMLSerializerProvider
|
||||
*
|
||||
* @param $inputContent
|
||||
* @param string $sPropertyTypeXML
|
||||
* @param string $sExpectedXMLContent
|
||||
*
|
||||
* @return void
|
||||
* @throws \DOMException
|
||||
*/
|
||||
public function testSerializeXML($inputContent, string $sPropertyTypeXML, string $sExpectedXMLContent)
|
||||
{
|
||||
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()->SerializeForPropertyType($inputContent, $oRootNode, $sPropertyTypeXML);
|
||||
|
||||
$sActualXML = $oDOMDocument->saveXML();
|
||||
|
||||
$this->AssertEqualiTopXML($sExpectedXMLContent, $sActualXML);
|
||||
}
|
||||
|
||||
public function XMLSerializerProvider()
|
||||
{
|
||||
return [
|
||||
'Basic test should serialize to XML' => [
|
||||
'inputContent' => 'text',
|
||||
'sPropertyTypeXML' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<property_type id="basic_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-Label">
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root>text</root>
|
||||
XML,
|
||||
],
|
||||
'Collection of values as CSV' => [
|
||||
'inputContent' => ['Contact', 'Organization'],
|
||||
'sPropertyTypeXML' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<property_type id="basic_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-CollectionOfValues">
|
||||
<xml-format xsi:type="Combodo-XMLFormat-CSV"/>
|
||||
<value-type xsi:type="Combodo-ValueType-Class">
|
||||
</value-type>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root>Contact,Organization</root>
|
||||
XML,
|
||||
],
|
||||
'Collection of values as id attribute' => [
|
||||
'inputContent' => ['Contact', 'Organization'],
|
||||
'sPropertyTypeXML' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<property_type id="class_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-CollectionOfValues">
|
||||
<xml-format xsi:type="Combodo-XMLFormat-ValueAsId">
|
||||
<tag-name>item</tag-name>
|
||||
</xml-format>
|
||||
<value-type xsi:type="Combodo-ValueType-Class">
|
||||
</value-type>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root>
|
||||
<item id="Contact"/>
|
||||
<item id="Organization"/>
|
||||
</root>
|
||||
XML,
|
||||
],
|
||||
'Collection of tree as flat array' => [
|
||||
'inputContent' => [
|
||||
[
|
||||
'title_property' => 'title_a',
|
||||
'class_property' => 'class_a',
|
||||
],
|
||||
[
|
||||
'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-FlatArray">
|
||||
<count-tag>item_count</count-tag>
|
||||
<tag-format>item_\$rank\$_\$id\$</tag-format>
|
||||
</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,
|
||||
'sExpectedXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root>
|
||||
<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>
|
||||
<item_1_title_property>title_b</item_1_title_property>
|
||||
<item_1_class_property>class_b</item_1_class_property>
|
||||
</root>
|
||||
XML,
|
||||
],
|
||||
'Property tree' => [
|
||||
'inputContent' => ['title_property' => 'title', 'class_property' => 'class'],
|
||||
'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-PropertyTree">
|
||||
<nodes>
|
||||
<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>
|
||||
</nodes>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'sExpectedXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root>
|
||||
<title_property>title</title_property>
|
||||
<class_property>class</class_property>
|
||||
</root>
|
||||
XML,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider XMLUnserializerProvider
|
||||
*
|
||||
* @param $sInputXMLContent
|
||||
* @param string $sPropertyTypeXML
|
||||
* @param $expectedValue
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testUnserializeXML($sInputXMLContent, string $sPropertyTypeXML, $expectedValue)
|
||||
{
|
||||
ServiceLocator::GetInstance()->RegisterService('ModelReflection', new ModelReflectionRuntime());
|
||||
|
||||
$oDoc = new PropertyTypeDesign();
|
||||
$oDoc->loadXML($sInputXMLContent);
|
||||
/** @var \Combodo\iTop\DesignElement $oRoot */
|
||||
$oRoot = $oDoc->firstChild;
|
||||
|
||||
$aActualValue = Combodo\iTop\PropertyType\Serializer\XMLSerializer::GetInstance()->UnserializeForPropertyType($oRoot, $sPropertyTypeXML);
|
||||
|
||||
$this->assertEquals($expectedValue, $aActualValue);
|
||||
}
|
||||
|
||||
public function XMLUnserializerProvider()
|
||||
{
|
||||
return [
|
||||
'Basic test should unserialize from XML' => [
|
||||
'sInputXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root>text</root>
|
||||
XML,
|
||||
'sPropertyTypeXML' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<property_type id="basic_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-Label">
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'expectedValue' => 'text',
|
||||
],
|
||||
'Collection of values as CSV' => [
|
||||
'sInputXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root>Contact,Organization</root>
|
||||
XML,
|
||||
'sPropertyTypeXML' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<property_type id="basic_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-CollectionOfValues">
|
||||
<xml-format xsi:type="Combodo-XMLFormat-CSV"/>
|
||||
<value-type xsi:type="Combodo-ValueType-Class">
|
||||
</value-type>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'expectedValue' => ['Contact', 'Organization'],
|
||||
],
|
||||
'Collection of values as id attribute' => [
|
||||
'sInputXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root>
|
||||
<item id="Contact"/>
|
||||
<item id="Organization"/>
|
||||
</root>
|
||||
XML,
|
||||
'sPropertyTypeXML' => <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<property_type id="class_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-CollectionOfValues">
|
||||
<xml-format xsi:type="Combodo-XMLFormat-ValueAsId">
|
||||
<tag-name>item</tag-name>
|
||||
</xml-format>
|
||||
<value-type xsi:type="Combodo-ValueType-Class">
|
||||
</value-type>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'expectedValue' => ['Contact', 'Organization'],
|
||||
],
|
||||
'Collection of tree as flat array' => [
|
||||
'sInputXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root>
|
||||
<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>
|
||||
<item_1_title_property>title_b</item_1_title_property>
|
||||
<item_1_class_property>class_b</item_1_class_property>
|
||||
</root>
|
||||
XML,
|
||||
'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-FlatArray">
|
||||
<count-tag>item_count</count-tag>
|
||||
<tag-format>item_\$rank\$_\$id\$</tag-format>
|
||||
</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,
|
||||
'expectedValue' => [
|
||||
[
|
||||
'title_property' => 'title_a',
|
||||
'class_property' => 'class_a',
|
||||
],
|
||||
[
|
||||
'title_property' => 'title_b',
|
||||
'class_property' => 'class_b',
|
||||
],
|
||||
],
|
||||
],
|
||||
'Property tree' => [
|
||||
'sInputXMLContent' => <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<root>
|
||||
<title_property>title</title_property>
|
||||
<class_property>class</class_property>
|
||||
</root>
|
||||
XML,
|
||||
'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-PropertyTree">
|
||||
<nodes>
|
||||
<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>
|
||||
</nodes>
|
||||
</definition>
|
||||
</property_type>
|
||||
XML,
|
||||
'expectedValue' => ['title_property' => 'title', 'class_property' => 'class'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user