From e2c41ecaa9f8e14bc848647639a87f79ea479e0f Mon Sep 17 00:00:00 2001 From: Thomas Peterson Date: Tue, 15 Jul 2025 10:48:35 +0200 Subject: [PATCH] Fixes --- .gitignore | 1 + cobertura.xml | 3790 +++++++++++++------------ src/Calc/Calc.php | 13 + src/Option/Parser/Input.php | 53 +- src/Option/Parser/Select.php | 1 - src/Option/Type/Input.php | 84 +- tests/Customer/MM/CalcTest.php | 79 + tests/Customer/MM/calc.xml | 261 ++ tests/Customer/MM/calcTemplates.xml | 2 + tests/Customer/MM/formels.txt | 0 tests/Customer/MM/papierContainer.xml | 45 + tests/Customer/MM/parameters.txt | 27 + tests/Mock/PaperRepostory.php | 52 +- 13 files changed, 2504 insertions(+), 1904 deletions(-) create mode 100644 tests/Customer/MM/CalcTest.php create mode 100644 tests/Customer/MM/calc.xml create mode 100644 tests/Customer/MM/calcTemplates.xml create mode 100644 tests/Customer/MM/formels.txt create mode 100644 tests/Customer/MM/papierContainer.xml create mode 100644 tests/Customer/MM/parameters.txt diff --git a/.gitignore b/.gitignore index b6c6a21..f187325 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ composer.phar vendor/ .php-cs-fixer.cache .phpunit.result.cache +cobertura.xml ## Directory-based project format: .idea/ .phpunit.cache/ diff --git a/cobertura.xml b/cobertura.xml index f449c6d..c593e50 100644 --- a/cobertura.xml +++ b/cobertura.xml @@ -1,6 +1,6 @@ - + /home/thomas/projekte/calc/src @@ -11,11 +11,11 @@ - - - - - + + + + + @@ -30,7 +30,7 @@ - + @@ -53,7 +53,7 @@ - + @@ -63,12 +63,12 @@ - + - + @@ -78,33 +78,33 @@ - + - + - + - - + + - + - - + + - + @@ -114,7 +114,7 @@ - + @@ -162,42 +162,42 @@ - - - - - + + + + + - + - + - - + + - - + + - - - + + + - + - - + + - + - + @@ -267,352 +267,370 @@ - + - + - - - + + + - + - + - - - + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - + + + - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -623,82 +641,82 @@ - - - + + + - + - - + + - - - - - - - - - - + + + + + + + + + + - - - - - - + + + + + + - - - - - + + + + + - - - + + + - - - - + + + + - - - - + + + + - - - - - - - + + + + + + + - - - - - - - - + + + + + + + + @@ -721,7 +739,7 @@ - + @@ -744,7 +762,7 @@ - + @@ -767,7 +785,7 @@ - + @@ -790,7 +808,7 @@ - + @@ -813,7 +831,7 @@ - + @@ -836,7 +854,7 @@ - + @@ -859,7 +877,7 @@ - + @@ -882,7 +900,7 @@ - + @@ -905,7 +923,7 @@ - + @@ -928,82 +946,82 @@ - + - + - - - - - - + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - + + + + + - - - + + + - - - - + + + + - - - - + + + + - - - - - - - + + + + + + + - - - - - - - - + + + + + + + + @@ -1026,7 +1044,7 @@ - + @@ -1049,7 +1067,7 @@ - + @@ -1072,7 +1090,7 @@ - + @@ -1095,7 +1113,7 @@ - + @@ -1118,7 +1136,7 @@ - + @@ -1141,7 +1159,7 @@ - + @@ -1164,7 +1182,7 @@ - + @@ -1187,7 +1205,7 @@ - + @@ -1210,7 +1228,7 @@ - + @@ -1233,14 +1251,14 @@ - + - + @@ -1305,70 +1323,70 @@ - - + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - + + + + + + + - - - + + + - + - + - - - - + + + + - - - - + + + + - + - - + + @@ -1379,82 +1397,82 @@ - + - - - - - - - + + + + + + + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - + - - - - - + + + + + - - - - + + + + - - - + + + @@ -1465,26 +1483,26 @@ - - - - - - - - + + + + + + + + - + - + - + - + - + @@ -1495,83 +1513,83 @@ - - - + + + - + - - + + - - + + - + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - + + + + + + - + - + - + - - + + - - + + - - - + + + - - - + + + @@ -1585,44 +1603,44 @@ - - - - - - - + + + + + + + - + - - + + - - - + + + - - - - - - - - - - - + + + + + + + + + + + - + @@ -1642,75 +1660,75 @@ - - - - - - + + + + + + - - + + - + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - + + + + + + - + - + - + - - + + - - + + - - - + + + - - - + + + @@ -1724,40 +1742,40 @@ - - - - - - - + + + + + + + - + - - - - - + + + + + - - - - - - - - - - - + + + + + + + + + + + - + @@ -1923,30 +1941,30 @@ - - - - - - + + + + + + - - - - - - - - - + + + + + + + + + - - + + @@ -1956,9 +1974,9 @@ - - - + + + @@ -1974,8 +1992,8 @@ - - + + @@ -1985,66 +2003,66 @@ - - + + - + - - + + - + - - + + - + - - + + - - - - - - - - - - - + + + + + + + + + + + - - - + + + - - - - + + + + @@ -2054,60 +2072,60 @@ - - + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - - + + - - - - - + + + + + - - - - + + + + - + - + @@ -2131,7 +2149,7 @@ - + @@ -2141,12 +2159,12 @@ - + - + @@ -2184,7 +2202,7 @@ - + @@ -2194,8 +2212,8 @@ - - + + @@ -2203,13 +2221,13 @@ - + - - + + @@ -2229,9 +2247,9 @@ - + - + @@ -2252,7 +2270,7 @@ - + @@ -2321,11 +2339,11 @@ - - - - - + + + + + @@ -2335,28 +2353,28 @@ - - + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -2386,30 +2404,30 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - + + - - - + + + @@ -2417,41 +2435,41 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - - + + + + @@ -2461,52 +2479,52 @@ - - + + - - - - - - - - + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - + + + + + - - - - - + + + + + - + @@ -2514,10 +2532,10 @@ - + - - + + @@ -2531,22 +2549,22 @@ - + - - + + - - - + + + - + - + @@ -2555,7 +2573,7 @@ - + @@ -2572,11 +2590,11 @@ - - - - - + + + + + @@ -2586,24 +2604,24 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + @@ -2738,7 +2756,7 @@ - + @@ -2787,56 +2805,56 @@ - - - - - - + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - - - - - - - - - + + + + + + + + + @@ -2844,7 +2862,7 @@ - + @@ -2881,52 +2899,52 @@ - - - - - - + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - + + + + + + + + + + + @@ -2940,7 +2958,7 @@ - + @@ -2950,7 +2968,7 @@ - + @@ -2969,24 +2987,24 @@ - - - - + + + + - - - - - - + + + + + + - + - + @@ -2997,17 +3015,17 @@ - - - - + + + + - - - - - - + + + + + + @@ -3018,7 +3036,7 @@ - + @@ -3028,7 +3046,7 @@ - + @@ -3044,23 +3062,23 @@ - - - + + + - - - - - - + + + + + + - + - + @@ -3068,16 +3086,16 @@ - - - + + + - - - - - - + + + + + + @@ -3088,22 +3106,22 @@ - + - + - + - + @@ -3113,7 +3131,7 @@ - + @@ -3123,17 +3141,17 @@ - + - + - + @@ -3143,7 +3161,7 @@ - + @@ -3153,7 +3171,7 @@ - + @@ -3163,7 +3181,7 @@ - + @@ -3173,7 +3191,7 @@ - + @@ -3183,7 +3201,7 @@ - + @@ -3193,7 +3211,7 @@ - + @@ -3203,7 +3221,7 @@ - + @@ -3213,7 +3231,7 @@ - + @@ -3223,7 +3241,7 @@ - + @@ -3233,71 +3251,71 @@ - + - + - + - + - + - + - + - + - - - - - - - - - + + + + + + + + + - - - + + + - + - + @@ -3390,64 +3408,64 @@ - - - - + + + + - + - - - + + + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - + + + - - + + @@ -3530,27 +3548,27 @@ - + - + - + - + - + @@ -3588,11 +3606,11 @@ - - - - - + + + + + @@ -3648,8 +3666,8 @@ - - + + @@ -3723,8 +3741,8 @@ - - + + @@ -3780,8 +3798,8 @@ - - + + @@ -4026,8 +4044,8 @@ - - + + @@ -4284,19 +4302,19 @@ - - - + + + - + - + @@ -4373,11 +4391,11 @@ - - - - - + + + + + @@ -4440,7 +4458,7 @@ - + @@ -4582,12 +4600,12 @@ - + - + @@ -4701,7 +4719,7 @@ - + @@ -4742,7 +4760,7 @@ - + @@ -4902,7 +4920,7 @@ - + @@ -5006,10 +5024,10 @@ - - - - + + + + @@ -5024,15 +5042,15 @@ - - - - + + + + - - - - + + + + @@ -5081,21 +5099,21 @@ - - - - + + + + - - - - + + + + - - - - + + + + @@ -5131,7 +5149,7 @@ - + @@ -5142,7 +5160,7 @@ - + @@ -5162,7 +5180,7 @@ - + @@ -5200,44 +5218,44 @@ - - - - - - - - - + + + + + + + + + - + - + - + - + - - - + + + - + - + @@ -5267,39 +5285,39 @@ - - - - - - - - - + + + + + + + + + - + - + - + - + - - - + + + - + @@ -5310,12 +5328,12 @@ - + - + @@ -5350,29 +5368,29 @@ - - - - - + + + + + - + - + - + - + - + - + - + - + - + @@ -5384,8 +5402,8 @@ - - + + @@ -5400,29 +5418,29 @@ - - - - - + + + + + - + - + - + - + - + - + - + - + - + @@ -5614,7 +5632,7 @@ - + @@ -5629,43 +5647,43 @@ - - - - - - + + + + + + - + - - - - - - + + + + + + - + - + - + - + @@ -5675,33 +5693,41 @@ - - - - + + + + + + + + - + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + @@ -5710,24 +5736,32 @@ - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -5942,15 +5976,15 @@ - + - + - - - + + + @@ -5980,14 +6014,14 @@ - - + + - - - + + + @@ -5995,7 +6029,7 @@ - + @@ -6016,103 +6050,103 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - + - + + - + - - + - + - + - + - - - + + + @@ -6134,14 +6168,14 @@ - - + + - - - + + + @@ -6149,7 +6183,7 @@ - + @@ -6158,60 +6192,60 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - + + + + @@ -6466,8 +6500,8 @@ - - + + @@ -6487,7 +6521,7 @@ - + @@ -6512,12 +6546,12 @@ - + - + @@ -6532,12 +6566,12 @@ - + - + @@ -6572,17 +6606,17 @@ - + - + - + @@ -6592,32 +6626,32 @@ - + - + - + - + - + - + @@ -6627,7 +6661,7 @@ - + @@ -6637,12 +6671,12 @@ - + - + @@ -6652,7 +6686,7 @@ - + @@ -6714,45 +6748,45 @@ - - + + - + - - + + - - + + - - - + + + - - - - - - + + + + + + - + - - + + - + @@ -7038,128 +7072,176 @@ - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -7190,8 +7272,8 @@ - - + + @@ -7217,8 +7299,8 @@ - - + + @@ -7265,61 +7347,61 @@ - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -7339,8 +7421,8 @@ - - + + @@ -7362,8 +7444,8 @@ - - + + @@ -7410,57 +7492,57 @@ - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -7656,14 +7738,14 @@ - - - + + + - + @@ -7673,10 +7755,10 @@ - - - - + + + + @@ -7707,17 +7789,17 @@ - + - + - + @@ -7727,9 +7809,9 @@ - - - + + + @@ -7738,10 +7820,10 @@ - - - - + + + + @@ -7780,36 +7862,36 @@ - - - - + + + + - - - - + + + + - - - + + + - - - + + + - - - - + + + + @@ -7840,13 +7922,13 @@ - + - + - + - + @@ -7859,9 +7941,9 @@ - + - + @@ -7869,9 +7951,9 @@ - + - + @@ -7879,9 +7961,9 @@ - + - + @@ -7889,9 +7971,9 @@ - + - + @@ -7899,25 +7981,25 @@ - + - + - + - + - + - + - + - + @@ -8038,47 +8120,47 @@ - + - + - + - + - + - + - + - + - + @@ -8112,15 +8194,15 @@ - - - - - - - - - + + + + + + + + + @@ -8148,30 +8230,30 @@ - + - + - + - + - - - - + + + + @@ -8244,25 +8326,25 @@ - + - - - - - - - + + + + + + + - - - - - - + + + + + + @@ -8272,32 +8354,32 @@ - - - + + + - - - - - - - - + + + + + + + + - - - - - - + + + + + + - - - + + + @@ -8308,36 +8390,36 @@ - + - + - + - + - + - - - - - + + + + + @@ -8348,32 +8430,32 @@ - + - + - + - + - + - + @@ -8383,12 +8465,12 @@ - - - - - - + + + + + + @@ -8400,7 +8482,7 @@ - + @@ -8429,11 +8511,11 @@ - - - - - + + + + + @@ -8441,18 +8523,18 @@ - + - - - - - - - - - + + + + + + + + + @@ -8461,44 +8543,44 @@ - - - + + + - + - + - + - + - + - + - + @@ -8519,11 +8601,11 @@ - - - - - + + + + + @@ -8531,18 +8613,18 @@ - + - - - - - - - - - + + + + + + + + + @@ -8551,19 +8633,19 @@ - - - + + + - - - - - - + + + + + + @@ -8748,7 +8830,7 @@ - + @@ -8763,7 +8845,7 @@ - + diff --git a/src/Calc/Calc.php b/src/Calc/Calc.php index 75dee30..0f85a5f 100644 --- a/src/Calc/Calc.php +++ b/src/Calc/Calc.php @@ -18,6 +18,7 @@ use PSC\Library\Calc\Model\Part; use PSC\Library\Calc\Model\PartType; use PSC\Library\Calc\Option\Type\Base; use PSC\Library\Calc\Option\Type\Checkbox; +use PSC\Library\Calc\Option\Type\Input; use PSC\Library\Calc\Option\Type\PaperDbSelect; use PSC\Library\Calc\Option\Type\Radio; use PSC\Library\Calc\Option\Type\Row; @@ -76,6 +77,18 @@ class Calc } } + if ($option instanceof Input) { + if ($option->getMaxCalc() != null) { + $formel = $this->formelCalc->parse($option->getMaxCalc()); + eval('$maxValue = ' . $formel . ';'); + $option->setMaxValue($maxValue); + } + if ($option->getMinCalc() != null) { + $formel = $this->formelCalc->parse($option->getMinCalc()); + eval('$minValue = ' . $formel . ';'); + $option->setMinValue($minValue); + } + } $gesamt = $this->parseEdgeCollection( $gesamt, $option, diff --git a/src/Option/Parser/Input.php b/src/Option/Parser/Input.php index ce34188..4b1a58f 100644 --- a/src/Option/Parser/Input.php +++ b/src/Option/Parser/Input.php @@ -1,4 +1,5 @@ element = new \PSC\Library\Calc\Option\Type\Input(); @@ -16,18 +16,26 @@ class Input extends Base { parent::parseJson(); - if(isset($this->json['placeHolder'])) { - $this->element->setPlaceHolder((string)$this->json['placeHolder']); + if (isset($this->json['placeHolder'])) { + $this->element->setPlaceHolder((string) $this->json['placeHolder']); } - if(isset($this->json['minValue'])) { - $this->element->setMinValue((int)$this->json['minValue']); + if (isset($this->json['minValue'])) { + $this->element->setMinValue((int) $this->json['minValue']); } - if(isset($this->json['maxValue'])) { - $this->element->setMaxValue((int)$this->json['maxValue']); + if (isset($this->json['minCalc'])) { + $this->element->setMinCalc((string) $this->json['minCalc']); } - if(isset($this->json['dependencys']) && count($this->json['dependencys']) > 0) { + if (isset($this->json['maxValue'])) { + $this->element->setMaxValue((int) $this->json['maxValue']); + } + + if (isset($this->json['maxCalc'])) { + $this->element->setMaxCalc((string) $this->json['maxCalc']); + } + + if (isset($this->json['dependencys']) && count($this->json['dependencys']) > 0) { $edgeCollectionContainerParser = new EdgeCollectionContainer(); $edgeCollectionContainerParser->fromJson($this->json['dependencys']); $this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseJson()); @@ -40,22 +48,30 @@ class Input extends Base { parent::parseXML(); - if(isset($this->node['min'])) { - $this->element->setMinValue((int)$this->node['min']); + if (isset($this->node['min'])) { + $this->element->setMinValue((int) $this->node['min']); } - if(isset($this->node['max'])) { - $this->element->setMaxValue((int)$this->node['max']); + if (isset($this->node['min_calc'])) { + $this->element->setMinCalc((string) $this->node['min_calc']); } - if(isset($this->node['pattern'])) { - $this->element->setPattern((string)$this->node['pattern']); - } - if(isset($this->node['placeholder'])) { - $this->element->setPlaceHolder((string)$this->node['placeholder']); + if (isset($this->node['max'])) { + $this->element->setMaxValue((int) $this->node['max']); } - if($this->node->children()) { + if (isset($this->node['max_calc'])) { + $this->element->setMaxCalc((string) $this->node['max_calc']); + } + + if (isset($this->node['pattern'])) { + $this->element->setPattern((string) $this->node['pattern']); + } + if (isset($this->node['placeholder'])) { + $this->element->setPlaceHolder((string) $this->node['placeholder']); + } + + if ($this->node->children()) { $edgeCollectionContainerParser = new EdgeCollectionContainer(); $edgeCollectionContainerParser->fromXML($this->node); $this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseXML()); @@ -63,5 +79,4 @@ class Input extends Base return $this->element; } - } diff --git a/src/Option/Parser/Select.php b/src/Option/Parser/Select.php index 8962d5e..accdb31 100644 --- a/src/Option/Parser/Select.php +++ b/src/Option/Parser/Select.php @@ -133,7 +133,6 @@ class Select extends Base foreach ($container->getItems() as $papier) { /** @var Paper $paper */ $paper = $this->getPaperRepository()->findOneBy(['artNr' => $papier->getId()]); - if ($paper) { $optPapier = new \PSC\Library\Calc\Option\Type\Select\PaperOpt(); $optPapier->setId($paper->getArtNr()); diff --git a/src/Option/Type/Input.php b/src/Option/Type/Input.php index 36a034e..3b69349 100644 --- a/src/Option/Type/Input.php +++ b/src/Option/Type/Input.php @@ -1,34 +1,59 @@ minValue = $min; } - public function getMinValue(): ?int + public function getMinValue(): null|int { return $this->minValue; } - public function setMaxValue(?int $max): void + public function setMaxCalc(null|string $max): void + { + $this->maxCalc = $max; + } + + public function getMaxCalc(): null|string + { + return $this->maxCalc; + } + + public function setMinCalc(null|string $min): void + { + $this->minCalc = $min; + } + + public function getMinCalc(): null|string + { + return $this->minCalc; + } + + public function setMaxValue(null|int $max): void { $this->maxValue = $max; } - - public function getMaxValue(): ?int + + public function getMaxValue(): null|int { return $this->maxValue; } @@ -57,28 +82,39 @@ class Input extends Base { $tmp = []; - if($this->getPlaceHolder() != "") { + if ($this->getPlaceHolder() != '') { $tmp['_attributes'] = [ - 'placeholder' => $this->getPlaceHolder() + 'placeholder' => $this->getPlaceHolder(), ]; } - if($this->getMinValue() !== null) { + if ($this->getMinValue() !== null) { $tmp = array_merge_recursive($tmp, ['_attributes' => [ - 'min' => $this->getMinValue() + 'min' => $this->getMinValue(), ]]); } - if($this->getMaxValue() !== null) { + if ($this->getMaxValue() !== null) { $tmp = array_merge_recursive($tmp, ['_attributes' => [ - 'max' => $this->getMaxValue() + 'max' => $this->getMaxValue(), + ]]); + } + + if ($this->getMinCalc() !== null) { + $tmp = array_merge_recursive($tmp, ['_attributes' => [ + 'min_calc' => $this->getMinCalc(), + ]]); + } + if ($this->getMaxCalc() !== null) { + $tmp = array_merge_recursive($tmp, ['_attributes' => [ + 'max_calc' => $this->getMaxCalc(), ]]); } $tmp = array_merge_recursive($tmp, ['_attributes' => [ - 'default' => $this->getDefault() + 'default' => $this->getDefault(), ]]); - if($this->isRequire()) { + if ($this->isRequire()) { $tmp = array_merge_recursive($tmp, ['_attributes' => [ - 'require' => 'true' + 'require' => 'true', ]]); } return array_merge_recursive($tmp, parent::generateXML()); @@ -89,12 +125,18 @@ class Input extends Base $obj = parent::generateJson(); $obj->placeHolder = $this->placeHolder; $obj->required = $this->isRequire(); - if($this->getMinValue() !== NULL) { + if ($this->getMinValue() !== null) { $obj->minValue = $this->getMinValue(); } - if($this->getMaxValue() !== null) { + if ($this->getMaxValue() !== null) { $obj->maxValue = $this->getMaxValue(); } + if ($this->getMinCalc() !== null) { + $obj->minCalc = $this->getMinCalc(); + } + if ($this->getMaxCalc() !== null) { + $obj->maxCalc = $this->getMaxCalc(); + } $obj->type = 2; return $obj; } diff --git a/tests/Customer/MM/CalcTest.php b/tests/Customer/MM/CalcTest.php new file mode 100644 index 0000000..5becc9f --- /dev/null +++ b/tests/Customer/MM/CalcTest.php @@ -0,0 +1,79 @@ +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 testPrice(): void + { + $this->engine->calc(); + $this->assertSame(1272.34, $this->engine->getPrice()); + self::assertCount( + 3, + $this->engine + ->getArticle() + ->getOptionById('papier_umschlag') + ->getValidOptions(), + ); + self::assertSame( + 60, + $this->engine + ->getArticle() + ->getOptionById('seiten_inhalt') + ->getMaxValue(), + ); + } + + public function testPapierDbPrice(): void + { + $this->engine->setVariable('papier_inhalt', 'ct90'); + $this->engine->calc(); + $this->assertSame(1185.42, $this->engine->getPrice()); + self::assertCount( + 5, + $this->engine + ->getArticle() + ->getOptionById('papier_umschlag') + ->getValidOptions(), + ); + self::assertSame( + 80, + $this->engine + ->getArticle() + ->getOptionById('seiten_inhalt') + ->getMaxValue(), + ); + } +} diff --git a/tests/Customer/MM/calc.xml b/tests/Customer/MM/calc.xml new file mode 100644 index 0000000..0c1d3c4 --- /dev/null +++ b/tests/Customer/MM/calc.xml @@ -0,0 +1,261 @@ + + + + SD-Satz + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/Customer/MM/calcTemplates.xml b/tests/Customer/MM/calcTemplates.xml new file mode 100644 index 0000000..093d936 --- /dev/null +++ b/tests/Customer/MM/calcTemplates.xml @@ -0,0 +1,2 @@ + + diff --git a/tests/Customer/MM/formels.txt b/tests/Customer/MM/formels.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/Customer/MM/papierContainer.xml b/tests/Customer/MM/papierContainer.xml new file mode 100644 index 0000000..29c4015 --- /dev/null +++ b/tests/Customer/MM/papierContainer.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + ct90 + + + + + + + ct90 + ct100 + + + + + + + ct90 + ct100 + ct120 + + + + + + + ct90 + ct100 + ct120 + ct160 + + + + + + diff --git a/tests/Customer/MM/parameters.txt b/tests/Customer/MM/parameters.txt new file mode 100644 index 0000000..8b87a74 --- /dev/null +++ b/tests/Customer/MM/parameters.txt @@ -0,0 +1,27 @@ +$dm_zuschuss_je_auftrag = 3; +$dm_zuschuss_je_papiersorte = 2; +$dm_zuschuss_fortdruck = 0.02; + +$dm_drucke_pro_minute_100 = 30; +$dm_minuten_pro_1000_100 = 34; + +$dm_drucke_pro_minute_150 = 19; +$dm_minuten_pro_1000_150 = 53; + +$dm_drucke_pro_minute_300 = 12; +$dm_minuten_pro_1000_300 = 84; + + +$dm_druckzeit_zuschlag_finisher = 0.20; + +$dm_stundensatz = 78; +$dm_minutensatz = 1.3; + +$dm_klick_farbe = 0.07; +$dm_klick_sw = 0.01; + +$zuschlag_papier = 0.16; +$zuschlag_material = 0.08; +$zuschlag_fremd = 0.08; +$zuschlag_verwaltung = 0.27; +$zuschlag_gewinn = 0.10; diff --git a/tests/Mock/PaperRepostory.php b/tests/Mock/PaperRepostory.php index 15caa78..a5b3e77 100644 --- a/tests/Mock/PaperRepostory.php +++ b/tests/Mock/PaperRepostory.php @@ -1,4 +1,5 @@ setArtNr('bdm135'); $papier['bdm135']->setVolume(0); @@ -63,7 +67,6 @@ class PaperRepostory implements ObjectRepository $papier['bdg250']->setGrammatur(250); $papier['bdg250']->setPapierTyp1(1); - $papier['bdm300'] = new Paper(); $papier['bdm300']->setArtNr('bdm300'); $papier['bdm300']->setDescription1('Bilderdruck matt 300 gr'); @@ -72,7 +75,6 @@ class PaperRepostory implements ObjectRepository $papier['bdg300']->setArtNr('bdg300'); $papier['bdg300']->setDescription1('Bilderdruck glänzend 300 gr'); - $papier['INM115'] = new Paper(); $papier['INM115']->setArtNr('INM115'); $papier['INM115']->setGrammatur('115'); @@ -391,10 +393,42 @@ class PaperRepostory implements ObjectRepository $papier['621995']->setDescription1('80 g/m², Preprint, weiss'); $papier['621995']->setDescription2('80 g/m², Preprint, weiss'); + $papier['ct90'] = new Paper(); + $papier['ct90']->setArtNr('ct90'); + $papier['ct90']->setGrammatur('90'); + $papier['ct90']->setPreis('42.9'); + $papier['ct90']->setUmschlagen(true); + $papier['ct90']->setStaerke(0.125); + $papier['ct100'] = new Paper(); + $papier['ct100']->setArtNr('ct100'); + $papier['ct100']->setGrammatur('100'); + $papier['ct100']->setPreis('42.9'); + $papier['ct100']->setUmschlagen(true); + $papier['ct100']->setStaerke(0.125); + + $papier['ct120'] = new Paper(); + $papier['ct120']->setArtNr('ct120'); + $papier['ct120']->setGrammatur('120'); + $papier['ct120']->setPreis('42.9'); + $papier['ct120']->setUmschlagen(true); + $papier['ct120']->setStaerke(0.125); + + $papier['ct160'] = new Paper(); + $papier['ct160']->setArtNr('ct160'); + $papier['ct160']->setGrammatur('160'); + $papier['ct160']->setPreis('42.9'); + $papier['ct160']->setUmschlagen(true); + $papier['ct160']->setStaerke(0.125); + + $papier['ct200'] = new Paper(); + $papier['ct200']->setArtNr('ct200'); + $papier['ct200']->setGrammatur('200'); + $papier['ct200']->setPreis('71.4'); + $papier['ct200']->setUmschlagen(true); + $papier['ct200']->setStaerke(0.191); return $papier[$criteria['artNr']]; - } public function getClassName(): string