From ff608a598ef2a5ffaabbcef43899f233f884c8fb Mon Sep 17 00:00:00 2001 From: Thomas Peterson Date: Fri, 25 Jul 2025 14:16:19 +0200 Subject: [PATCH] Fixes --- cobertura.xml | 796 +++++++++--------- .../Parser/EdgeCollectionContainer.php | 17 +- src/Option/Parser/Text.php | 2 +- src/Option/Type/Text.php | 10 +- tests/Json/Type/TextTest.php | 45 + 5 files changed, 469 insertions(+), 401 deletions(-) create mode 100644 tests/Json/Type/TextTest.php diff --git a/cobertura.xml b/cobertura.xml index 5698479..79eced3 100644 --- a/cobertura.xml +++ b/cobertura.xml @@ -1,6 +1,6 @@ - + /home/thomas/projekte/calc/src @@ -323,25 +323,25 @@ - - - - + + + + - + - + - + - + - + - + @@ -507,25 +507,25 @@ - - - - + + + + - + - + - + - + - + - + @@ -689,27 +689,27 @@ - - - - + + + + - + - + - + - + - + - + @@ -1049,27 +1049,27 @@ - - - - + + + + - + - + - + - + - + - + @@ -1732,15 +1732,15 @@ - - + + - - - + + + - + @@ -1881,15 +1881,15 @@ - - + + - - - + + + - + @@ -2234,11 +2234,11 @@ - - - - - + + + + + @@ -2484,15 +2484,15 @@ - - - - - + + + + + - - - + + + @@ -2642,11 +2642,11 @@ - - - - - + + + + + @@ -2736,15 +2736,15 @@ - - - - - + + + + + - - - + + + @@ -3100,7 +3100,7 @@ - + @@ -3110,7 +3110,7 @@ - + @@ -3129,24 +3129,24 @@ - - + + - + - + - + - + - + @@ -3157,28 +3157,28 @@ - - + + - + - + - + - + - + - + @@ -3188,56 +3188,56 @@ - + - - + - - + + + - + - - - - - - - - - - + + + + + + + + + + - + - - - + + - - - - - - - - - - - - + + + + + + + + + + + + + @@ -3690,17 +3690,17 @@ - + - + - + @@ -3710,7 +3710,7 @@ - + @@ -3748,11 +3748,11 @@ - - - + + + - + @@ -4456,7 +4456,7 @@ - + @@ -4542,7 +4542,7 @@ - + @@ -4748,7 +4748,7 @@ - + @@ -4872,7 +4872,7 @@ - + @@ -4914,7 +4914,7 @@ - + @@ -5074,7 +5074,7 @@ - + @@ -5178,10 +5178,10 @@ - - - - + + + + @@ -5196,15 +5196,15 @@ - - + + - + - + - - + + @@ -5253,21 +5253,21 @@ - - - - + + + + - - + + - + - + - - + + @@ -5303,7 +5303,7 @@ - + @@ -5319,7 +5319,7 @@ - + @@ -5517,12 +5517,12 @@ - + - + @@ -5537,45 +5537,45 @@ - - - - - - + + + + + + - + - + - + - - - + + + - + - + - + - + - + - + - + - + - + - + @@ -5588,45 +5588,45 @@ - - + + - - - - - - + + + + + + - + - + - - - - + + + + - + - + - + - + - + - + - + - + - + - + @@ -6242,9 +6242,9 @@ - + - + @@ -6356,30 +6356,30 @@ - + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + @@ -6541,25 +6541,25 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + @@ -6772,62 +6772,62 @@ - + - + - + - + - - - - + + + + - + - - - - + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - + + + + + @@ -6862,8 +6862,8 @@ - - + + @@ -6878,17 +6878,17 @@ - + - + - + @@ -6908,12 +6908,12 @@ - + - + @@ -6928,12 +6928,12 @@ - + - + @@ -6983,12 +6983,12 @@ - + - + @@ -6998,7 +6998,7 @@ - + @@ -7008,12 +7008,12 @@ - + - + @@ -7038,7 +7038,7 @@ - + @@ -7068,64 +7068,64 @@ - - - - + + + + - - + + - + - + - + - - - - - - - + + + + + + + - + - + - + - + - - + + - - - + + + - - + + - - + + @@ -7135,18 +7135,18 @@ - - + + - + - - + + - + @@ -7156,40 +7156,40 @@ - - - - + + + + - - + + - + - + - - - - - - - - + + + + + + + + - + - + - + - + @@ -8466,13 +8466,13 @@ - + - + - + - + @@ -8485,9 +8485,9 @@ - + - + @@ -8495,9 +8495,9 @@ - + - + @@ -8505,9 +8505,9 @@ - + - + @@ -8515,9 +8515,9 @@ - + - + @@ -8525,25 +8525,25 @@ - + - + - + - + - + - + - + - + @@ -8664,7 +8664,7 @@ - + @@ -8674,7 +8674,7 @@ - + @@ -8684,7 +8684,7 @@ - + @@ -8738,11 +8738,11 @@ - + - + - + @@ -8824,22 +8824,36 @@ - + - + - + - - - + + + + + + + + + + + + - - - + + + + + + + + diff --git a/src/General/Parser/EdgeCollectionContainer.php b/src/General/Parser/EdgeCollectionContainer.php index 5fce6d6..aa58bd8 100644 --- a/src/General/Parser/EdgeCollectionContainer.php +++ b/src/General/Parser/EdgeCollectionContainer.php @@ -1,4 +1,5 @@ json = $json; } - public function fromXML(\SimpleXMLElement $node) { + public function fromXML(\SimpleXMLElement $node) + { $this->node = $node; } @@ -30,7 +31,7 @@ class EdgeCollectionContainer { $container = new \PSC\Library\Calc\General\Type\EdgeCollectionContainer(); - foreach($this->json as $row) { + foreach ($this->json as $row) { $collectionParser = new EdgeCollection(); $collectionParser->fromJson($row); $collection = $collectionParser->parseJson(); @@ -45,8 +46,8 @@ class EdgeCollectionContainer { $container = new \PSC\Library\Calc\General\Type\EdgeCollectionContainer(); - foreach($this->node->children() as $key => $row) { - if($key == 'opt') { + foreach ($this->node->children() as $key => $row) { + if ($key == 'data' || $key == 'opt') { continue; } $collectionParser = new EdgeCollection(); diff --git a/src/Option/Parser/Text.php b/src/Option/Parser/Text.php index 9f89777..0b114aa 100644 --- a/src/Option/Parser/Text.php +++ b/src/Option/Parser/Text.php @@ -19,7 +19,7 @@ class Text extends Base parent::parseJson(); if ($this->json['default']) { - $this->element->setDefault((string) $this->json['default']); + $this->element->setValue((string) $this->json['default']); } if (isset($this->json['dependencys']) && count($this->json['dependencys']) > 0) { diff --git a/src/Option/Type/Text.php b/src/Option/Type/Text.php index 3507623..e622ea5 100644 --- a/src/Option/Type/Text.php +++ b/src/Option/Type/Text.php @@ -1,16 +1,24 @@ default = $this->getValue(); $obj->type = 4; return $obj; } + public function generateXML(): array + { + $tmp = ['data' => [ + '_cdata' => $this->getValue(), + ]]; + return array_merge_recursive($tmp, parent::generateXML()); + } } diff --git a/tests/Json/Type/TextTest.php b/tests/Json/Type/TextTest.php new file mode 100644 index 0000000..e579dd2 --- /dev/null +++ b/tests/Json/Type/TextTest.php @@ -0,0 +1,45 @@ +json = json_decode('{ + "id": "2a2e93d0-d1e9-421e-a55e-c4c165964dc7", + "type": 4, + "dependencys": [], + "default": "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.", + "name": "" + }', true); + + $this->xml = ''; + } + + public function testFromJson() + { + $parser = new Text(); + $parser->fromJson($this->json); + $obj = $parser->parseJson(); + + $xml = ArrayToXml::convert($obj->generateXML(), 'option'); + self::assertXmlStringEqualsXmlString($xml, $this->xml); + } + + public function testFromXML() + { + $parser = new Text(); + $parser->fromXML(simplexml_load_string($this->xml)); + $obj = $parser->parseXML(); + + self::assertJsonStringEqualsJsonString(json_encode($obj->generateJson()), json_encode($this->json)); + } +}