diff --git a/src/Calc/Formel.php b/src/Calc/Formel.php index 6fef875..485eb4f 100644 --- a/src/Calc/Formel.php +++ b/src/Calc/Formel.php @@ -145,7 +145,11 @@ class Formel if ($variables [$foundvalue] == '') { $formel = str_replace($found, 0, $formel); } else { - $formel = str_replace($found, $variables [$foundvalue], $formel); + if(is_array($variables [$foundvalue])) { + $formel = str_replace($found, 0, $formel); + }else{ + $formel = str_replace($found, $variables [$foundvalue], $formel); + } } } } diff --git a/tests/Customer/U/CalcTest.php b/tests/Customer/U/CalcTest.php new file mode 100644 index 0000000..3bda9f5 --- /dev/null +++ b/tests/Customer/U/CalcTest.php @@ -0,0 +1,46 @@ +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.xml')); + + } + + public function tearDown(): void + { + $this->engine = null; + } + + public function testIfDefaultPriceIsOk(): void + { + $this->engine->calc(); + $this->assertEquals(202 , $this->engine->getPrice()); + $this->assertEquals('135 g/m² Bilderdruck matt gestrichen', $this->engine->getArticle()->getOptionById('papier')->getValue()); + + } +} diff --git a/tests/Customer/U/calc.xml b/tests/Customer/U/calc.xml new file mode 100644 index 0000000..830bec9 --- /dev/null +++ b/tests/Customer/U/calc.xml @@ -0,0 +1,19 @@ + + + + + Banderolen + + + + + + + \ No newline at end of file diff --git a/tests/Customer/U/calcTemplates.xml b/tests/Customer/U/calcTemplates.xml new file mode 100644 index 0000000..b3f7d62 --- /dev/null +++ b/tests/Customer/U/calcTemplates.xml @@ -0,0 +1,4 @@ + + + + diff --git a/tests/Customer/U/formels.txt b/tests/Customer/U/formels.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/Customer/U/papierContainer.xml b/tests/Customer/U/papierContainer.xml new file mode 100644 index 0000000..2697401 --- /dev/null +++ b/tests/Customer/U/papierContainer.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/tests/Customer/U/parameters.txt b/tests/Customer/U/parameters.txt new file mode 100644 index 0000000..e69de29