From eba3da933cdd5d62b7c41bdeefe413ccedda7a7d Mon Sep 17 00:00:00 2001 From: "DESKTOP-E17406D\\boonkerz" Date: Tue, 22 Nov 2022 17:31:02 +0100 Subject: [PATCH] Fix Calc --- src/Calc/Valid.php | 2 +- tests/Customer/R/CalcTest.php | 13 +++- tests/Customer/R/calc.xml | 102 +++++++++++++++++++++++++-- tests/Customer/S/CalcTest.php | 51 ++++++++++++++ tests/Customer/S/calc.xml | 42 +++++++++++ tests/Customer/S/calcTemplates.xml | 2 + tests/Customer/S/formels.txt | 0 tests/Customer/S/papierContainer.xml | 4 ++ tests/Customer/S/parameters.txt | 0 9 files changed, 207 insertions(+), 9 deletions(-) create mode 100644 tests/Customer/S/CalcTest.php create mode 100644 tests/Customer/S/calc.xml create mode 100644 tests/Customer/S/calcTemplates.xml create mode 100644 tests/Customer/S/formels.txt create mode 100644 tests/Customer/S/papierContainer.xml create mode 100644 tests/Customer/S/parameters.txt diff --git a/src/Calc/Valid.php b/src/Calc/Valid.php index 634b4cd..08851f2 100644 --- a/src/Calc/Valid.php +++ b/src/Calc/Valid.php @@ -92,7 +92,7 @@ class Valid } if($option instanceof Checkbox) { - if (in_array($opt->getId(), $this->engine->getVariables()[$option->getId()])) { + if (isset($this->engine->getVariables()[$option->getId()]) && in_array($opt->getId(), $this->engine->getVariables()[$option->getId()])) { $opt->setIsSelected(true); } else { $opt->setIsSelected(false); diff --git a/tests/Customer/R/CalcTest.php b/tests/Customer/R/CalcTest.php index 7d21cdd..9110e8c 100644 --- a/tests/Customer/R/CalcTest.php +++ b/tests/Customer/R/CalcTest.php @@ -48,7 +48,18 @@ class CalcTest extends TestCase { $this->engine->setVariable('auswahl2', 21); $this->engine->calc(); - $this->assertSame('29.24', $this->engine->getArticle()->getOptionById('auswahl3')->getRawValue()); + $this->assertSame('31', $this->engine->getArticle()->getOptionById('auswahl3')->getRawValue()); + } + + public function testOptionCheckbox(): void + { + $this->engine->setVariable('checkboxen1', [1,2]); + $this->engine->calc(); + self::assertTrue($this->engine->getArticle()->getOptionById('checkboxen1')->getOptions()[0]->isSelected()); + self::assertTrue($this->engine->getArticle()->getOptionById('checkboxen1')->getOptions()[1]->isSelected()); + $this->engine->setVariable('checkboxen1', [2]); + self::assertFalse($this->engine->getArticle()->getOptionById('checkboxen1')->getOptions()[0]->isSelected()); + self::assertTrue($this->engine->getArticle()->getOptionById('checkboxen1')->getOptions()[1]->isSelected()); } } diff --git a/tests/Customer/R/calc.xml b/tests/Customer/R/calc.xml index 4da72da..bc0d505 100644 --- a/tests/Customer/R/calc.xml +++ b/tests/Customer/R/calc.xml @@ -5,8 +5,8 @@ - Testprodukt Z Test - XXX-XXXXX9 + Testprodukt Z Test 1 + XXX-XXXXX9-1 @@ -37,16 +37,15 @@ - + + + + + + + + + + + + + + + Testprodukt Z Test 2 + XXX-XXXXX9-2 + + + + + + + + + + + + + + + + + + + + +