From a9b3a17518bcfcd245965c244e3e902a6245cac2 Mon Sep 17 00:00:00 2001 From: Thomas Peterson Date: Thu, 31 Jan 2019 10:42:30 +0100 Subject: [PATCH] Fix Edges --- src/Article.php | 17 ++++- src/Calc/Valid.php | 7 ++ src/Option/Parser/Select.php | 6 ++ tests/Legacy/selectWithGrenzenTest.php | 55 ++++++++++++++++ .../Legacy/testSelectWithGrenzen.xml | 66 +++++++++++++++++++ 5 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 tests/Legacy/selectWithGrenzenTest.php create mode 100644 tests/TestFiles/Legacy/testSelectWithGrenzen.xml diff --git a/src/Article.php b/src/Article.php index 7cdcf51..d9512ea 100644 --- a/src/Article.php +++ b/src/Article.php @@ -78,12 +78,27 @@ class Article return $this->options; } + /** + * @return array + */ + public function getValidOptions() + { + $temp = array(); + + foreach ($this->options as $option) { + if($option->isValid()) { + $temp[] = $option; + } + } + return $temp; + } + public function getOptionsAsArray() { $temp = array(); /** @var Option\Type\Base $option */ foreach ($this->options as $option) { - if($option->getValue() == '' && $option->getRawValue() == '') { + if(($option->getValue() == '' && $option->getRawValue() == '') || !$option->isValid()) { continue; } $temp[$option->getId()] = array( diff --git a/src/Calc/Valid.php b/src/Calc/Valid.php index 6c6c9cc..9facb93 100644 --- a/src/Calc/Valid.php +++ b/src/Calc/Valid.php @@ -48,6 +48,8 @@ class Valid if($option instanceof Select) { + $valid = false; + /** @var Select\Opt $opt */ foreach ($option->getOptions() as $opt) { if(count($opt->getEdgesCollectionContainer()) > 0) { @@ -66,8 +68,13 @@ class Valid if($this->engine->getVariables()[$option->getId()] == $opt->getId()) { $opt->setIsSelected(true); } + + if($opt->isValid() && !$valid) { + $valid = true; + } } + $option->setIsValid($valid); } } diff --git a/src/Option/Parser/Select.php b/src/Option/Parser/Select.php index 4a98314..e1274c8 100644 --- a/src/Option/Parser/Select.php +++ b/src/Option/Parser/Select.php @@ -2,6 +2,7 @@ namespace PSC\Library\Calc\Option\Parser; use Doctrine\Common\Persistence\ObjectRepository; +use PSC\Library\Calc\General\Parser\EdgeCollectionContainer; use PSC\Library\Calc\Option\Parser\Select\Opt; use PSC\Library\Calc\PaperContainer; use PSC\Library\Calc\Tests\Mock\Paper; @@ -35,6 +36,11 @@ class Select extends Base { parent::parse(); + if(isset($this->node->grenzen) && $this->node->grenzen->children()) { + $edgeCollectionContainerParser = new EdgeCollectionContainer($this->node->grenzen); + $this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parse()); + } + if(isset($this->node['mode']) && (string)$this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb) { $this->parseModePapierDb(); }else{ diff --git a/tests/Legacy/selectWithGrenzenTest.php b/tests/Legacy/selectWithGrenzenTest.php new file mode 100644 index 0000000..63e9423 --- /dev/null +++ b/tests/Legacy/selectWithGrenzenTest.php @@ -0,0 +1,55 @@ +parse(simplexml_load_string(file_get_contents(__DIR__ . '/../TestFiles/Option/Select/papierContainer.xml'))); + + $this->engine = new Engine(); + $this->engine->setPaperContainer($paperContainer); + $this->engine->setPaperRepository($repository); + + $this->engine->loadString(file_get_contents(__DIR__ . '/../TestFiles/Legacy/testSelectWithGrenzen.xml')); + + } + + public function testSelectWithGrenzen() + { + $this->engine->calc("Test25"); + /** @var Article $article */ + $article = $this->engine->getArticle(); + + $this->assertCount(3, $article->getValidOptions()); + + $this->assertCount(3, $article->getOptionsAsArray()); + } + + public function testSelectWithGrenzenParams() + { + $this->engine->setVariable('umschlag', 4); + $this->engine->calc("Test25"); + /** @var Article $article */ + $article = $this->engine->getArticle(); + + $this->assertCount(6, $article->getValidOptions()); + + $this->assertCount(6, $article->getOptionsAsArray()); + } + +} \ No newline at end of file diff --git a/tests/TestFiles/Legacy/testSelectWithGrenzen.xml b/tests/TestFiles/Legacy/testSelectWithGrenzen.xml new file mode 100644 index 0000000..ae7f19f --- /dev/null +++ b/tests/TestFiles/Legacy/testSelectWithGrenzen.xml @@ -0,0 +1,66 @@ + + + + Test25 + kein + + + + + + + + + + + + + +