From 71011d6ba36fda82fe1f70151858b20a21dc9540 Mon Sep 17 00:00:00 2001 From: "DESKTOP-E17406D\\boonkerz" Date: Wed, 23 Nov 2022 13:59:46 +0100 Subject: [PATCH] Fix Calc --- src/Engine.php | 4 +++ tests/Customer/R/CalcTest.php | 7 ++++ tests/Customer/R/CheckboxTest.php | 56 ++++++++++++++++++++++++++++++ tests/Customer/R/RadioboxTest.php | 56 ++++++++++++++++++++++++++++++ tests/Customer/R/calc.xml | 43 +++++++++++++++++++++-- tests/Customer/R/calc_checkbox.xml | 20 +++++++++++ tests/Customer/R/calc_radiobox.xml | 20 +++++++++++ 7 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 tests/Customer/R/CheckboxTest.php create mode 100644 tests/Customer/R/RadioboxTest.php create mode 100644 tests/Customer/R/calc_checkbox.xml create mode 100644 tests/Customer/R/calc_radiobox.xml diff --git a/src/Engine.php b/src/Engine.php index 259f212..c57109c 100644 --- a/src/Engine.php +++ b/src/Engine.php @@ -238,6 +238,10 @@ class Engine public function calc() { + $this->debugCalcFormel = []; + $this->debugCalcVariables = []; + $this->debugFlatPrice = []; + $this->debugPrice = []; $this->price = 0; $tmp = []; diff --git a/tests/Customer/R/CalcTest.php b/tests/Customer/R/CalcTest.php index b8ae586..f450ee0 100644 --- a/tests/Customer/R/CalcTest.php +++ b/tests/Customer/R/CalcTest.php @@ -72,4 +72,11 @@ class CalcTest extends TestCase self::assertTrue($this->engine->getArticle()->getOptionById('checkboxen1')->getOptions()[1]->isSelected()); } + + public function testOptionCalcCheckbox(): void + { + $this->assertEquals(1048, $this->engine->getPrice()); + $this->engine->setVariable('radio1', 1); + $this->assertEquals(1044, $this->engine->getPrice()); + } } diff --git a/tests/Customer/R/CheckboxTest.php b/tests/Customer/R/CheckboxTest.php new file mode 100644 index 0000000..36d87f7 --- /dev/null +++ b/tests/Customer/R/CheckboxTest.php @@ -0,0 +1,56 @@ +parse(simplexml_load_string(file_get_contents(__DIR__ . '/papierContainer.xml'))); + + $this->engine = new Engine(); + $this->engine->setPaperContainer($paperContainer); + $this->engine->setPaperRepository($repository); + $this->engine->setFormulas(file_get_contents(__DIR__ . '/formels.txt')); + $this->engine->setParameters(file_get_contents(__DIR__ . '/parameters.txt')); + $this->engine->setTemplates(file_get_contents(__DIR__ . '/calcTemplates.xml')); + + $this->engine->loadString(file_get_contents(__DIR__ . '/calc_checkbox.xml')); + + } + + public function tearDown(): void + { + $this->engine = null; + } + + public function testCalcDefault(): void + { + self::assertSame(26.0, $this->engine->getPrice()); + self::assertTrue($this->engine->getArticle()->getOptionById('checkbox')->getOptions()[0]->isSelected()); + self::assertTrue($this->engine->getArticle()->getOptionById('checkbox')->getOptions()[1]->isSelected()); + } + + public function testCalcOnly2(): void + { + $this->engine->setVariable('checkbox', [2]); + self::assertSame(14.0, $this->engine->getPrice()); + self::assertFalse($this->engine->getArticle()->getOptionById('checkbox')->getOptions()[0]->isSelected()); + self::assertTrue($this->engine->getArticle()->getOptionById('checkbox')->getOptions()[1]->isSelected()); + } +} diff --git a/tests/Customer/R/RadioboxTest.php b/tests/Customer/R/RadioboxTest.php new file mode 100644 index 0000000..8d02eb0 --- /dev/null +++ b/tests/Customer/R/RadioboxTest.php @@ -0,0 +1,56 @@ +parse(simplexml_load_string(file_get_contents(__DIR__ . '/papierContainer.xml'))); + + $this->engine = new Engine(); + $this->engine->setPaperContainer($paperContainer); + $this->engine->setPaperRepository($repository); + $this->engine->setFormulas(file_get_contents(__DIR__ . '/formels.txt')); + $this->engine->setParameters(file_get_contents(__DIR__ . '/parameters.txt')); + $this->engine->setTemplates(file_get_contents(__DIR__ . '/calcTemplates.xml')); + + $this->engine->loadString(file_get_contents(__DIR__ . '/calc_radiobox.xml')); + + } + + public function tearDown(): void + { + $this->engine = null; + } + + public function testCalcDefault(): void + { + $this->assertSame(12.0, $this->engine->getPrice()); + self::assertFalse($this->engine->getArticle()->getOptionById('radiobox')->getOptions()[1]->isSelected()); + self::assertTrue($this->engine->getArticle()->getOptionById('radiobox')->getOptions()[0]->isSelected()); + } + + public function testCalcOnly2(): void + { + $this->engine->setVariable('radiobox', 2); + $this->assertSame(14.0, $this->engine->getPrice()); + self::assertFalse($this->engine->getArticle()->getOptionById('radiobox')->getOptions()[0]->isSelected()); + self::assertTrue($this->engine->getArticle()->getOptionById('radiobox')->getOptions()[1]->isSelected()); + } +} diff --git a/tests/Customer/R/calc.xml b/tests/Customer/R/calc.xml index 103fe7c..0b06d6f 100644 --- a/tests/Customer/R/calc.xml +++ b/tests/Customer/R/calc.xml @@ -50,11 +50,32 @@ - - + + + + + + + + + + +