diff --git a/cobertura.xml b/cobertura.xml index 76d1409..6d0538c 100644 --- a/cobertura.xml +++ b/cobertura.xml @@ -1,6 +1,6 @@ - + /home/thomas/projekte/calc/src @@ -267,9 +267,9 @@ - + - + @@ -283,7 +283,7 @@ - + @@ -296,175 +296,187 @@ - - + + + + - - - - - - - - - + + + + + + + - - - + + + + + + + + + - + - - - - - - + - - + + + - - - - - - - - + + + + + + + - - - - + + + - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + - - - + + + - + - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - + + + + + + - + + + - - + - + + + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - + + + @@ -484,170 +496,182 @@ - - + + + + - - - - - - - - - + + + + + + + - - - + + + + + + + - - - - + - - + + + - - - - - - - - + + + + + + + - - - - + + + - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + - - - + + + - + - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - + + + + + + - + + + - - + - - - + + + + + + + + + - - - - - - + + + + + + + + + + - + - + @@ -679,7 +703,7 @@ - + @@ -695,10 +719,10 @@ - - + + - + @@ -712,25 +736,25 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + @@ -1055,10 +1079,10 @@ - - + + - + @@ -1072,25 +1096,25 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + @@ -1437,9 +1461,9 @@ - + - + @@ -1465,7 +1489,7 @@ - + @@ -1480,26 +1504,26 @@ - + - + - + - - + + - - - - - + + + + + - + @@ -1520,26 +1544,26 @@ - + - - - - - - + + + + + + - + - - - - - - + + + + + + @@ -1574,22 +1598,22 @@ - + - + - - + + - - - - - + + + + + - + @@ -1607,29 +1631,29 @@ - - - - - - + + + + + + - + - - - - - - + + + + + + - + - + @@ -1643,7 +1667,7 @@ - + @@ -1653,7 +1677,7 @@ - + @@ -1662,27 +1686,27 @@ - + - + - - - - - - - - - - + + + + + + + + + + - + @@ -1704,7 +1728,7 @@ - + @@ -1716,8 +1740,8 @@ - - + + @@ -1743,26 +1767,26 @@ - - + + - + - + - + - + @@ -1773,24 +1797,24 @@ - + - - - - - + + + + + - + - + - + - - + + @@ -1808,7 +1832,7 @@ - + @@ -1817,27 +1841,27 @@ - + - + - - - - - - - - - - + + + + + + + + + + - + @@ -1859,7 +1883,7 @@ - + @@ -1871,8 +1895,8 @@ - - + + @@ -1898,22 +1922,22 @@ - - + + - + - + - + @@ -1924,20 +1948,20 @@ - + - - - - - + + + + + - + - + - - + + @@ -2077,9 +2101,9 @@ - + - + @@ -2292,9 +2316,9 @@ - + - + @@ -2355,10 +2379,10 @@ - + - - + + @@ -2438,9 +2462,9 @@ - + - + @@ -2458,9 +2482,9 @@ - + - + @@ -2482,21 +2506,21 @@ - + - - - - + + + + - - - + + + @@ -2670,7 +2694,7 @@ - + @@ -2689,8 +2713,8 @@ - - + + @@ -2716,11 +2740,11 @@ - + - + @@ -2733,14 +2757,14 @@ - - - - + + + + - - - + + + @@ -2808,19 +2832,19 @@ - + - + - + - - + + @@ -2831,16 +2855,16 @@ - - + + - + - + @@ -2852,17 +2876,17 @@ - + - - - - + + + + - + - + @@ -2876,11 +2900,11 @@ - - - - - + + + + + @@ -2888,9 +2912,9 @@ - + - + @@ -2941,13 +2965,13 @@ - + - + @@ -2973,29 +2997,29 @@ - - - - - + + + + + - + - + - - - + + + - - - + + + @@ -3041,7 +3065,7 @@ - + @@ -3067,32 +3091,32 @@ - - - - - + + + + + - + - - - + + + - - - + + + - + - + @@ -3123,11 +3147,11 @@ - + - + @@ -3155,7 +3179,7 @@ - + @@ -3168,9 +3192,9 @@ - + - + @@ -3198,12 +3222,12 @@ - + - + @@ -3227,7 +3251,7 @@ - + @@ -3238,9 +3262,9 @@ - + - + @@ -3282,9 +3306,9 @@ - + - + @@ -3402,19 +3426,19 @@ - + - + - + - + - + - + @@ -3427,28 +3451,28 @@ - + - + - - - - - - - - + + + + + + + + - + - + @@ -3456,9 +3480,9 @@ - + - + @@ -3554,7 +3578,7 @@ - + @@ -3578,33 +3602,33 @@ - - - + + + - + - - - - - - - - + + + + + + + + - + - + - + @@ -3680,9 +3704,9 @@ - + - + @@ -3699,9 +3723,9 @@ - + - + @@ -3747,7 +3771,7 @@ - + @@ -3798,9 +3822,9 @@ - + - + @@ -3808,31 +3832,31 @@ - + - - - - - - - - - + + + + + + + + + - + - - - - + + + + - + - - + + @@ -3841,97 +3865,97 @@ - + - - - - - - - - + + + + + + + + - + - - - - - - - - - - + + + + + + + + + + - + - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + @@ -4440,9 +4464,9 @@ - + - + @@ -4466,14 +4490,14 @@ - + - - - - - - + + + + + + @@ -4481,13 +4505,13 @@ - + - - - - - + + + + + @@ -4546,18 +4570,18 @@ - - - - - - + + + + + + - - - - - + + + + + @@ -4602,26 +4626,26 @@ - + - + - + - - - - - - - - - + + + + + + + + + @@ -4634,48 +4658,48 @@ - - - + + + - - - - - - - - - - - + + + + + + + + + + + - - - + + + - + - - - - + + + + - + - - + + @@ -4691,16 +4715,16 @@ - + - - - - - - - - + + + + + + + + @@ -4710,42 +4734,42 @@ - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -4761,15 +4785,15 @@ - - - - - - - - - + + + + + + + + + @@ -4782,40 +4806,40 @@ - - - + + + - - - - - - - - - - - + + + + + + + + + + + - - - + + + - - - - - - + + + + + + @@ -4829,14 +4853,14 @@ - - - - - - - - + + + + + + + + @@ -4844,36 +4868,36 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -4905,13 +4929,13 @@ - + - + - + - + @@ -4930,23 +4954,23 @@ - + - - - - - + + + + + - + - - - - - - + + + + + + @@ -4955,14 +4979,14 @@ - + - + - + - + @@ -4975,9 +4999,9 @@ - + - + @@ -5068,40 +5092,40 @@ - + - + - + - - - - - - - - - - - + + + + + + + + + + + - - + + - + @@ -5142,31 +5166,31 @@ - + - + - + - + - - - - - + + + + + - - - - - + + + + + @@ -5174,9 +5198,9 @@ - + - + @@ -5196,13 +5220,13 @@ - + - + @@ -5210,47 +5234,47 @@ - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - + + + + + + + + + + + + + + @@ -5265,42 +5289,42 @@ - + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - + - + - + - + @@ -5308,9 +5332,9 @@ - + - + @@ -5320,9 +5344,9 @@ - + - + @@ -5336,9 +5360,9 @@ - + - + @@ -5387,7 +5411,7 @@ - + @@ -5407,8 +5431,8 @@ - - + + @@ -5492,8 +5516,8 @@ - - + + @@ -5520,9 +5544,9 @@ - + - + @@ -5565,7 +5589,7 @@ - + @@ -5582,7 +5606,7 @@ - + @@ -5633,7 +5657,7 @@ - + @@ -6370,20 +6394,20 @@ - + - + - + - + - + - + @@ -6406,23 +6430,23 @@ - + - - - + + + - - + + - - + + - + @@ -6442,144 +6466,148 @@ - + - + + - - + + - + + - + - - - + - - - + + + + - - - + + + + + + - - - - - - + + - + + - - - + + + - - + + + + + - - - - - - + + - + + - - - + + + - - + + + + + - + - - - - + + + + - - - - + + + + - + - + - + - + @@ -6587,11 +6615,11 @@ - + - + - + @@ -6610,19 +6638,19 @@ - - - + + + - - + + - - + + - + @@ -6636,102 +6664,106 @@ - + + - - + + - - - - + + + - - - + + + + - - - + + - - - - - - + + + + + + - + + - - - + + + - - + + + + - - - - - + + - + + - - - + + + - - + - - - - + + + + + + + - - - - - - - + + + + + + + + @@ -6808,13 +6840,13 @@ - + - + - + - + @@ -6822,9 +6854,9 @@ - + - + @@ -6838,22 +6870,22 @@ - + - - - - - - - + + + + + + + - + - + @@ -6861,13 +6893,13 @@ - - - - - - - + + + + + + + @@ -6900,13 +6932,13 @@ - + - + - + - + @@ -6921,23 +6953,23 @@ - + - - + + - - - - - - - + + + + + + + - + @@ -6946,16 +6978,16 @@ - - + + - - - - - - - + + + + + + + @@ -6994,9 +7026,9 @@ - + - + @@ -7144,9 +7176,9 @@ - + - + @@ -7240,7 +7272,7 @@ - + @@ -7270,7 +7302,7 @@ - + @@ -7898,22 +7930,19 @@ - + - + - - - - + + - + - @@ -7923,28 +7952,28 @@ + - - - + + + + + - + - - - - - + + + - @@ -7957,9 +7986,9 @@ + - @@ -7973,28 +8002,28 @@ + - - - - + + + + - - + + - - + + - @@ -8006,10 +8035,10 @@ + - @@ -8022,51 +8051,91 @@ + - + + + + + - + - - - - + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + - + - @@ -8076,24 +8145,24 @@ + - - - + + + + - - - - - + + + + - @@ -8106,9 +8175,9 @@ + - @@ -8122,28 +8191,28 @@ + - - - - + + + + - - + + - - + + - @@ -8155,10 +8224,10 @@ + - @@ -8171,25 +8240,48 @@ + - + + - - - - - + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -8468,9 +8560,9 @@ - + - + @@ -8502,11 +8594,11 @@ - + - + @@ -8555,9 +8647,9 @@ - + - + @@ -8635,7 +8727,7 @@ - + @@ -8646,7 +8738,7 @@ - + diff --git a/src/Calc/Calc.php b/src/Calc/Calc.php index a12751b..18288a6 100644 --- a/src/Calc/Calc.php +++ b/src/Calc/Calc.php @@ -65,6 +65,14 @@ class Calc } } if ($option instanceof Select || $option instanceof Checkbox || $option instanceof Radio) { + if ($option instanceof PaperDbSelect) { + if ($option->getStaffelCalc() !== null) { + $formel = $this->formelCalc->parse($option->getStaffelCalc()); + eval('$staffelCalcResult = ' . $formel . ';'); + var_dump($staffelCalcResult); + $option->setStaffelCalcResult($staffelCalcResult); + } + } foreach ($option->getSelectedOptions() as $opt) { if ($opt->isValid()) { $gesamt = $this->parseEdgeCollection( @@ -167,16 +175,20 @@ class Calc $edge->getCalcValue(), $orgCv . ' = ' . $cv, ); - $this->engine->getCalcGraph()->addPart(new Part( - type: PartType::CalcValue, - name: $option->getId() . '_' . $collection->getName(), - unParsed: $edge->getCalcValue(), - )); - $this->engine->getCalcGraph()->addPart(new Part( - type: PartType::CalcValue, - name: $calcValueId, - unParsed: $edge->getCalcValue(), - )); + $this->engine + ->getCalcGraph() + ->addPart(new Part( + type: PartType::CalcValue, + name: $option->getId() . '_' . $collection->getName(), + unParsed: $edge->getCalcValue(), + )); + $this->engine + ->getCalcGraph() + ->addPart(new Part( + type: PartType::CalcValue, + name: $calcValueId, + unParsed: $edge->getCalcValue(), + )); } catch (\Throwable $e) { $cv = 0; } @@ -187,11 +199,11 @@ class Calc if ($edge->getFormel() != '') { $formel = $this->formelCalc->parse($edge->getFormel()); if ( - $formel != '' && - !in_array($option->getId(), ['weight', 'weight_single']) && - !$option->isAjaxExport() && - !$option->isDisplayOnly() && - $option->isAmount() + $formel != '' + && !in_array($option->getId(), ['weight', 'weight_single']) + && !$option->isAjaxExport() + && !$option->isDisplayOnly() + && $option->isAmount() ) { $p = 0; $formel = str_replace('tonumber', '$this->toNumber', $formel); @@ -199,11 +211,13 @@ class Calc try { eval('@$p = ' . $this->eval_func($gesamt, $formel) . ';'); $this->engine->addDebugCalcFormel($edge->getFormel(), $formel . ' = ' . $p); - $this->engine->getCalcGraph()->addCalcFormel(new Part( - type: PartType::Formel, - name: sprintf('%s-%s', $option->getId(), $collection->getName()), - unParsed: $edge->getFormel(), - )); + $this->engine + ->getCalcGraph() + ->addCalcFormel(new Part( + type: PartType::Formel, + name: sprintf('%s-%s', $option->getId(), $collection->getName()), + unParsed: $edge->getFormel(), + )); } catch (\Throwable $e) { $this->engine->addDebugCalcFormel($edge->getFormel(), $formel . ' = error'); $p = 0; @@ -215,11 +229,11 @@ class Calc $this->engine->setVariable('price', $gesamt); } if ( - $formel != '' && - !in_array($option->getId(), ['weight', 'weight_single']) && - $option->isAjaxExport() && - !$option->isDisplayOnly() && - $option->isAmount() + $formel != '' + && !in_array($option->getId(), ['weight', 'weight_single']) + && $option->isAjaxExport() + && !$option->isDisplayOnly() + && $option->isAmount() ) { $p = 0; $formel = str_replace('tonumber', '$this->toNumber', $formel); @@ -233,11 +247,11 @@ class Calc } } if ( - $formel != '' && - !in_array($option->getId(), ['weight', 'weight_single']) && - !$option->isAjaxExport() && - $option->isDisplayOnly() && - $option->isAmount() + $formel != '' + && !in_array($option->getId(), ['weight', 'weight_single']) + && !$option->isAjaxExport() + && $option->isDisplayOnly() + && $option->isAmount() ) { $p = 0; $formel = str_replace('tonumber', '$this->toNumber', $formel); diff --git a/src/Option/Parser/Select.php b/src/Option/Parser/Select.php index f3f99d5..cb8578b 100644 --- a/src/Option/Parser/Select.php +++ b/src/Option/Parser/Select.php @@ -23,7 +23,7 @@ class Select extends Base /** @var ObjectRepository */ protected $paperRepository; - public function __construct(null|string $mode = null) + public function __construct(?string $mode = null) { parent::__construct(); @@ -49,18 +49,18 @@ class Select extends Base } if ( - isset($this->json['mode']) && - ((string) $this->json['mode']) == \PSC\Library\Calc\Option\Type\Select::$modePaperDb + isset($this->json['mode']) + && (string) $this->json['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb ) { $this->parseModePapierDbJson(); } elseif ( - isset($this->json['mode']) && - ((string) $this->json['mode']) == \PSC\Library\Calc\Option\Type\Select::$modeDelivery + isset($this->json['mode']) + && (string) $this->json['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeDelivery ) { $this->parseModeDeliveryJson(); } elseif ( - isset($this->json['mode']) && - ((string) $this->json['mode']) == \PSC\Library\Calc\Option\Type\Select::$modeColorDb + isset($this->json['mode']) + && (string) $this->json['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeColorDb ) { $this->parseModeColorDbJson(); } else { @@ -81,18 +81,18 @@ class Select extends Base } if ( - isset($this->node['mode']) && - ((string) $this->node['mode']) == \PSC\Library\Calc\Option\Type\Select::$modePaperDb + isset($this->node['mode']) + && (string) $this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb ) { $this->parseModePapierDbXML(); } elseif ( - isset($this->node['mode']) && - ((string) $this->node['mode']) == \PSC\Library\Calc\Option\Type\Select::$modeDelivery + isset($this->node['mode']) + && (string) $this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeDelivery ) { $this->parseModeDeliveryXML(); } elseif ( - isset($this->node['mode']) && - ((string) $this->node['mode']) == \PSC\Library\Calc\Option\Type\Select::$modeColorDb + isset($this->node['mode']) + && (string) $this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modeColorDb ) { $this->parseModeColorDbXML(); } else { @@ -123,6 +123,9 @@ class Select extends Base private function parseModePapierDbXML() { $this->element->setContainer((string) $this->node['container']); + if (isset($this->node['staffelCalc'])) { + $this->element->setStaffelCalc((string) $this->node['staffelCalc']); + } if ($this->getPaperRepository()) { $this->element->setNewPaperObject($this->getPaperRepository()->getNewObject()); /** @var PaperContainer\Container $container */ @@ -154,6 +157,9 @@ class Select extends Base private function parseModePapierDbJson() { $this->element->setContainer((string) $this->json['container']); + if (isset($this->json['staffelCalc'])) { + $this->element->setStaffelCalc((string) $this->json['staffelCalc']); + } if ($this->getPaperRepository()) { $this->element->setNewPaperObject($this->getPaperRepository()->getNewObject()); /** @var PaperContainer\Container $container */ diff --git a/src/Option/Type/PaperDbSelect.php b/src/Option/Type/PaperDbSelect.php index 4c270ce..9514892 100644 --- a/src/Option/Type/PaperDbSelect.php +++ b/src/Option/Type/PaperDbSelect.php @@ -10,15 +10,18 @@ class PaperDbSelect extends Select { protected $newPaperObject = null; - public function getSelectedOption(): null|Opt + private ?string $staffelCalc = null; + private ?float $staffelCalcResult = null; + + public function getSelectedOption(): ?Opt { if (count($this->selectedOptions) > 0) { return $this->selectedOptions[0]; } if ( - isset($this->savedCalcValues[$this->getId()]) && - $this->savedCalcValues[$this->getId()]['art_nr'] == $this->getRawValue() + isset($this->savedCalcValues[$this->getId()]) + && $this->savedCalcValues[$this->getId()]['art_nr'] == $this->getRawValue() ) { $opt = new PaperOpt(); $opt->setId($this->savedCalcValues[$this->getId()]['art_nr']); @@ -104,6 +107,7 @@ class PaperDbSelect extends Select $variables[$this->getId() . '_glam'] = 0; $variables[$this->getId() . '_post'] = 0; $variables[$this->getId() . '_sammelform'] = 0; + $variables[$this->getId() . '_staffel_value'] = 0; } else { /** @var Paper $paper */ $paper = $option->getPaper(); @@ -160,6 +164,7 @@ class PaperDbSelect extends Select $variables[$this->getId() . '_glam'] = $paper->getGlam(); $variables[$this->getId() . '_post'] = $paper->getPost(); $variables[$this->getId() . '_sammelform'] = $paper->getSammelform(); + $variables[$this->getId() . '_staffel_value'] = $this->getStaffelValue($paper); } return $variables; @@ -177,6 +182,7 @@ class PaperDbSelect extends Select { return array_merge_recursive(parent::generateXML(), ['_attributes' => [ 'mode' => 'papierdb', + 'staffelCalc' => $this->staffelCalc, 'container' => $this->container, ]]); } @@ -186,8 +192,51 @@ class PaperDbSelect extends Select $obj = parent::generateJson(); $obj->mode = 'papierdb'; $obj->container = $this->container; + $obj->staffelCalc = $this->staffelCalc; $obj->options = []; $obj->options[] = $this->getSelectedOption()->generateJson(); return $obj; } + + public function setStaffelCalc(?string $staffelCalc): void + { + $this->staffelCalc = $staffelCalc; + } + + public function getStaffelCalc(): ?string + { + return $this->staffelCalc; + } + + public function setStaffelCalcResult(?float $staffelCalcResult): void + { + $this->staffelCalcResult = $staffelCalcResult; + } + + public function getStaffelCalcResult(): ?float + { + return $this->staffelCalcResult; + } + + private function getStaffelValue($paper): ?float + { + var_dump(1); + if ($this->getStaffelCalcResult() < $paper->getStaffelMenge1()) { + return (float) $paper->getStaffelPreis1(); + } + if ($this->getStaffelCalcResult() < $paper->getStaffelMenge2()) { + return (float) $paper->getStaffelPreis2(); + } + if ($this->getStaffelCalcResult() < $paper->getStaffelMenge3()) { + return (float) $paper->getStaffelPreis3(); + } + if ($this->getStaffelCalcResult() < $paper->getStaffelMenge4()) { + return (float) $paper->getStaffelPreis4(); + } + if ($this->getStaffelCalcResult() < $paper->getStaffelMenge5()) { + return (float) $paper->getStaffelPreis5(); + } + + return 0; + } } diff --git a/tests/Article/SimpleXmlTest.php b/tests/Article/SimpleXmlTest.php index 787bd18..39d903d 100644 --- a/tests/Article/SimpleXmlTest.php +++ b/tests/Article/SimpleXmlTest.php @@ -1,4 +1,5 @@ assertTrue($parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/simple.xml'))); + $this->assertTrue($parser->loadString(file_get_contents(__DIR__ . '/../TestFiles/General/simple.xml'))); $this->assertEquals(1, $parser->getArticles()->Count()); } @@ -18,7 +19,8 @@ class SimpleXmlTest extends TestCase public function testIfArticleCountInXmlCorrectWith2Article() { $parser = new Engine(new Container()); - $this->assertTrue($parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/simple2articles.xml'))); + $this->assertTrue($parser->loadString(file_get_contents(__DIR__ + . '/../TestFiles/General/simple2articles.xml'))); $this->assertEquals(2, $parser->getArticles()->Count()); } @@ -26,12 +28,11 @@ class SimpleXmlTest extends TestCase public function testGetArticleByName() { $parser = new Engine(new Container()); - $parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/simple2articles.xml')); + $parser->loadString(file_get_contents(__DIR__ . '/../TestFiles/General/simple2articles.xml')); - $parser->setActiveArticle("Blocks A5 25blatt geleimt"); + $parser->setActiveArticle('Blocks A5 25blatt geleimt'); $article = $parser->getArticle(); $this->assertInstanceOf('PSC\Library\Calc\Article', $article); $this->assertEquals('Blocks A5 25blatt geleimt', $article->getName()); } - } diff --git a/tests/Customer/PP/CalcTest.php b/tests/Customer/PP/CalcTest.php new file mode 100644 index 0000000..12941af --- /dev/null +++ b/tests/Customer/PP/CalcTest.php @@ -0,0 +1,44 @@ +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.txt')); + } + + public function tearDown(): void + { + $this->engine = null; + } + + public function testNormalPrice(): void + { + $this->engine->calc(); + $this->assertSame(5.00, $this->engine->getPrice()); + $this->engine->getCalcGraph()->generateJsonGraph(); + } +} diff --git a/tests/Customer/PP/calc.txt b/tests/Customer/PP/calc.txt new file mode 100644 index 0000000..8c330e4 --- /dev/null +++ b/tests/Customer/PP/calc.txt @@ -0,0 +1,39 @@ + + + + + + + Broschüren Offsetdruck + + + + + BRO Prototyp + + + + + + + + + + diff --git a/tests/Customer/PP/calcTemplates.xml b/tests/Customer/PP/calcTemplates.xml new file mode 100644 index 0000000..093d936 --- /dev/null +++ b/tests/Customer/PP/calcTemplates.xml @@ -0,0 +1,2 @@ + + diff --git a/tests/Customer/PP/formels.txt b/tests/Customer/PP/formels.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/Customer/PP/formels.txt @@ -0,0 +1 @@ + diff --git a/tests/Customer/PP/papierContainer.xml b/tests/Customer/PP/papierContainer.xml new file mode 100644 index 0000000..8925215 --- /dev/null +++ b/tests/Customer/PP/papierContainer.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/Customer/PP/parameters.txt b/tests/Customer/PP/parameters.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/Customer/PP/parameters.txt @@ -0,0 +1 @@ + diff --git a/tests/Mock/PaperRepostory.php b/tests/Mock/PaperRepostory.php index 068d1e3..5b27d8c 100644 --- a/tests/Mock/PaperRepostory.php +++ b/tests/Mock/PaperRepostory.php @@ -447,6 +447,40 @@ class PaperRepostory implements ObjectRepository $papier['ct200']->setUmschlagen(true); $papier['ct200']->setStaerke(0.191); + $papier['staffel1'] = new Paper(); + $papier['staffel1']->setArtNr('staffel1'); + $papier['staffel1']->setGrammatur('1'); + $papier['staffel1']->setPreis(5); + $papier['staffel1']->setUmschlagen(true); + $papier['staffel1']->setStaerke(0.191); + $papier['staffel1']->setStaffelmenge1(10); + $papier['staffel1']->setStaffelmenge2(20); + $papier['staffel1']->setStaffelmenge3(30); + $papier['staffel1']->setStaffelmenge4(40); + $papier['staffel1']->setStaffelmenge5(50); + $papier['staffel1']->setStaffelpreis1(10); + $papier['staffel1']->setStaffelpreis2(20); + $papier['staffel1']->setStaffelpreis3(30); + $papier['staffel1']->setStaffelpreis4(40); + $papier['staffel1']->setStaffelpreis5(50); + + $papier['staffel2'] = new Paper(); + $papier['staffel2']->setArtNr('staffel2'); + $papier['staffel2']->setGrammatur('1'); + $papier['staffel2']->setPreis(6); + $papier['staffel2']->setUmschlagen(true); + $papier['staffel2']->setStaerke(0.191); + $papier['staffel2']->setStaffelmenge1(10); + $papier['staffel2']->setStaffelmenge2(20); + $papier['staffel2']->setStaffelmenge3(30); + $papier['staffel2']->setStaffelmenge4(40); + $papier['staffel2']->setStaffelmenge5(50); + $papier['staffel2']->setStaffelpreis1(101); + $papier['staffel2']->setStaffelpreis2(201); + $papier['staffel2']->setStaffelpreis3(301); + $papier['staffel2']->setStaffelpreis4(401); + $papier['staffel2']->setStaffelpreis5(501); + return $papier[$criteria['artNr']]; }