Fixes
This commit is contained in:
parent
8138652387
commit
ff608a598e
796
cobertura.xml
796
cobertura.xml
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by PhpStorm.
|
* Created by PhpStorm.
|
||||||
* User: thomas
|
* User: thomas
|
||||||
@ -14,15 +15,15 @@ class EdgeCollectionContainer
|
|||||||
|
|
||||||
protected array $json;
|
protected array $json;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fromJson(array $json) {
|
public function fromJson(array $json)
|
||||||
|
{
|
||||||
$this->json = $json;
|
$this->json = $json;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fromXML(\SimpleXMLElement $node) {
|
public function fromXML(\SimpleXMLElement $node)
|
||||||
|
{
|
||||||
$this->node = $node;
|
$this->node = $node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ class EdgeCollectionContainer
|
|||||||
$container = new \PSC\Library\Calc\General\Type\EdgeCollectionContainer();
|
$container = new \PSC\Library\Calc\General\Type\EdgeCollectionContainer();
|
||||||
|
|
||||||
foreach ($this->node->children() as $key => $row) {
|
foreach ($this->node->children() as $key => $row) {
|
||||||
if($key == 'opt') {
|
if ($key == 'data' || $key == 'opt') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$collectionParser = new EdgeCollection();
|
$collectionParser = new EdgeCollection();
|
||||||
|
|||||||
@ -19,7 +19,7 @@ class Text extends Base
|
|||||||
parent::parseJson();
|
parent::parseJson();
|
||||||
|
|
||||||
if ($this->json['default']) {
|
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) {
|
if (isset($this->json['dependencys']) && count($this->json['dependencys']) > 0) {
|
||||||
|
|||||||
@ -1,16 +1,24 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace PSC\Library\Calc\Option\Type;
|
namespace PSC\Library\Calc\Option\Type;
|
||||||
|
|
||||||
class Text extends Base
|
class Text extends Base
|
||||||
{
|
{
|
||||||
|
|
||||||
public $type = 'text';
|
public $type = 'text';
|
||||||
|
|
||||||
public function generateJson(): \stdClass
|
public function generateJson(): \stdClass
|
||||||
{
|
{
|
||||||
$obj = parent::generateJson();
|
$obj = parent::generateJson();
|
||||||
|
$obj->default = $this->getValue();
|
||||||
$obj->type = 4;
|
$obj->type = 4;
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function generateXML(): array
|
||||||
|
{
|
||||||
|
$tmp = ['data' => [
|
||||||
|
'_cdata' => $this->getValue(),
|
||||||
|
]];
|
||||||
|
return array_merge_recursive($tmp, parent::generateXML());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
45
tests/Json/Type/TextTest.php
Normal file
45
tests/Json/Type/TextTest.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PSC\Library\Calc\Tests\Json\Type;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use PSC\Library\Calc\Option\Parser\Text;
|
||||||
|
use Spatie\ArrayToXml\ArrayToXml;
|
||||||
|
|
||||||
|
class TextTest extends TestCase
|
||||||
|
{
|
||||||
|
private array $json;
|
||||||
|
private string $xml;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
$this->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 = '<option id="2a2e93d0-d1e9-421e-a55e-c4c165964dc7" type="Text"><data><![CDATA[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.]]></data></option>';
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user