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 + + + + + + + + + + + + + + + + + + + + +