Fix Calc
This commit is contained in:
parent
430d646a88
commit
eba3da933c
@ -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);
|
||||
|
||||
@ -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());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
<!-- Änderung: 24.02.2022 12:00 -->
|
||||
<kalkulation>
|
||||
<artikel>
|
||||
<name>Testprodukt Z Test</name>
|
||||
<kommentar>XXX-XXXXX9</kommentar>
|
||||
<name>Testprodukt Z Test 1</name>
|
||||
<kommentar>XXX-XXXXX9-1</kommentar>
|
||||
<!--
|
||||
<option id="selectprodukt" name="Produktauswahl" mode="produktdb" type="Select" container="88127,88128,88129" />
|
||||
-->
|
||||
@ -46,7 +46,6 @@
|
||||
<!--
|
||||
<option id="checkboxen" name="Checkboxen" type="Checkbox" default="1">
|
||||
-->
|
||||
<!--
|
||||
<option id="checkboxen1" name="Checkboxen 1" type="Checkbox">
|
||||
<opt id="1" name="Auswahl 1-1"></opt>
|
||||
<opt id="2" name="Auswahl 1-2"></opt>
|
||||
@ -57,7 +56,96 @@
|
||||
<option id="checkboxen3" name="Checkboxen 3" type="Checkbox">
|
||||
<opt id="1" name="Auswahl 3-1"></opt>
|
||||
</option>
|
||||
<!-- ### Eingabebox einzeilig 1 ### -->
|
||||
<option id="input1" name="Eingabe" type="Input" />
|
||||
<!-- ### Eingabebox mehrzeilig 1 ### -->
|
||||
<option id="input2" name="Eingabe mehrzeilig" type="Textarea" />
|
||||
<!-- ### Text (nur Darstellung) 1 ### -->
|
||||
<option id="text1" name="Hinweis" type="Text" default="Lorem ipsum dolor sit amet, consetetur sadipscing elitr." />
|
||||
<!-- ### Auflage ### -->
|
||||
<option id="auflage" name="Auflage" type="Select" default="100" require="true">
|
||||
<opt id="100" name="100 Stück" />
|
||||
<opt id="200" name="200 Stück" />
|
||||
<opt id="300" name="300 Stück" />
|
||||
<opt id="400" name="400 Stück" />
|
||||
<opt id="500" name="500 Stück" />
|
||||
</option>
|
||||
<!-- ###### Namen für Preisberechnung im kalk-footer ###### -->
|
||||
<option id="MK-Papier" name="Materialkosten Papier" type="Hidden" default="1"><opt id="0" name="False" /><opt id="1" name="True" /></option>
|
||||
<option id="MK-Druck" name="Materialkosten Druck" type="Hidden" default="1"><opt id="0" name="False" /><opt id="1" name="True" /></option>
|
||||
<option id="FK-Druck" name="Fertigungskosten Druck" type="Hidden" default="1"><opt id="0" name="False" /><opt id="1" name="True" /></option>
|
||||
<!-- ###### Preisberechnung ###### -->
|
||||
<option id="preis1" name="Preis 1" type="Hidden">
|
||||
<MK-Papier><grenze formel="round($CVauswahl3_og1$CV+$CVauswahl3_og2$CV,2)">1</grenze></MK-Papier>
|
||||
</option>
|
||||
<option id="preis2" name="Preis 2" type="Hidden">
|
||||
<MK-Druck><grenze formel="round($CVauswahl3_og1_2$CV+$CVauswahl3_og2_2$CV,2)">1</grenze></MK-Druck>
|
||||
</option>
|
||||
<option id="preis3" name="Preis 3" type="Hidden">
|
||||
<FK-Druck><grenze formel="round($CVauswahl3_og1_3$CV+$CVauswahl3_og2_3$CV,2)">1</grenze></FK-Druck>
|
||||
</option>
|
||||
<!-- ### Gewichtsberechnung ### -->
|
||||
<!--
|
||||
<option id="weight_single" name="weight_single" type="Hidden">
|
||||
<auflage><grenze formel="$Fformel1$F">1-</grenze></auflage>
|
||||
</option>
|
||||
-->
|
||||
<option id="weight" name="weight" type="Hidden">
|
||||
<auflage><grenze formel="33.3">1-</grenze></auflage>
|
||||
</option>
|
||||
</artikel>
|
||||
<artikel>
|
||||
<name>Testprodukt Z Test 2</name>
|
||||
<kommentar>XXX-XXXXX9-2</kommentar>
|
||||
<!--
|
||||
<option id="selectprodukt" name="Produktauswahl" mode="produktdb" type="Select" container="88127,88128,88129" />
|
||||
-->
|
||||
<!-- ###### OptGrenze erlaubt Grenzen in <opt> für calc_value ###### -->
|
||||
<option id="og1" name="OptGrenze 1" type="Hidden" default="1"><opt id="0" name="False" /><opt id="1" name="True" /></option>
|
||||
<option id="og2" name="OptGrenze 2" type="Hidden" default="1"><opt id="0" name="False" /><opt id="1" name="True" /></option>
|
||||
<!-- ###### Produktkonfiguration ###### -->
|
||||
<option id="auswahl1" name="Auswahl 1" type="Select" default="10">
|
||||
<opt id="10" name="Option 1-10" />
|
||||
<opt id="11" name="Option 1-11" />
|
||||
<opt id="12" name="Option 1-12" />
|
||||
</option>
|
||||
<!-- ### Auswahl 2 ### -->
|
||||
<option id="auswahl2" name="Auswahl 2" type="Select" default="20">
|
||||
<opt id="20" name="Option 2-10" />
|
||||
<opt id="21" name="Option 2-11" />
|
||||
<opt id="22" name="Option 2-12" />
|
||||
</option>
|
||||
<!-- ### Auswahl 3 ### -->
|
||||
<option id="auswahl3" name="Auswahl 3 (beeinflusst von Auswahl 2)" type="Select" default="30">
|
||||
<opt id="30" name="Option 3-10"><auswahl2><grenze>20</grenze></auswahl2><og1><grenze calc_value="110" calc_value_2="111" calc_value_3="112">1</grenze></og1><og2><grenze calc_value="210" calc_value_2="211" calc_value_3="212">1</grenze></og2></opt>
|
||||
<opt id="31" name="Option 3-11"><auswahl2><grenze>21</grenze></auswahl2><og1><grenze calc_value="120" calc_value_2="121" calc_value_3="122">1</grenze></og1><og2><grenze calc_value="220" calc_value_2="221" calc_value_3="222">1</grenze></og2></opt>
|
||||
<opt id="32" name="Option 3-12"><auswahl2><grenze>20,22</grenze></auswahl2><og1><grenze calc_value="130" calc_value_2="131" calc_value_3="132">1</grenze></og1><og2><grenze calc_value="230" calc_value_2="231" calc_value_3="232">1</grenze></og2></opt>
|
||||
</option>
|
||||
<!-- ### Eingabe 1 ### -->
|
||||
<option id="eingabe1" name="Eingabe 1 (beeinflusst von Auswahl 1)" type="Input" default="1-10"><auswahl1><grenze>10</grenze></auswahl1></option>
|
||||
<!-- ### Eingabe 2 ### -->
|
||||
<option id="eingabe2" name="Eingabe 1 (beeinflusst von Auswahl 1)" type="Input" default="1-11"><auswahl1><grenze>11</grenze></auswahl1></option>
|
||||
<!-- ### Radioboxen 1 ### -->
|
||||
<!--
|
||||
<option id="radioboxen" name="Radioboxen" type="Radio" default="1">
|
||||
<opt id="1" name="Radiobox 1"></opt>
|
||||
<opt id="2" name="Radiobox 2"></opt>
|
||||
</option>
|
||||
-->
|
||||
<!-- ### Checkboxen 1 ### -->
|
||||
<!--
|
||||
<option id="checkboxen" name="Checkboxen" type="Checkbox" default="1">
|
||||
-->
|
||||
<option id="checkboxen1" name="Checkboxen 1" type="Checkbox">
|
||||
<opt id="1" name="Auswahl 1-1"></opt>
|
||||
<opt id="2" name="Auswahl 1-2"></opt>
|
||||
</option>
|
||||
<option id="checkboxen2" name="Checkboxen 2" type="Checkbox">
|
||||
<opt id="1" name="Auswahl 2-1"></opt>
|
||||
</option>
|
||||
<option id="checkboxen3" name="Checkboxen 3" type="Checkbox">
|
||||
<opt id="1" name="Auswahl 3-1"></opt>
|
||||
</option>
|
||||
<!-- ### Eingabebox einzeilig 1 ### -->
|
||||
<option id="input1" name="Eingabe" type="Input" />
|
||||
<!-- ### Eingabebox mehrzeilig 1 ### -->
|
||||
|
||||
51
tests/Customer/S/CalcTest.php
Normal file
51
tests/Customer/S/CalcTest.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace PSC\Library\Calc\Tests\Customer\S;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PSC\Library\Calc\Article;
|
||||
use PSC\Library\Calc\Engine;
|
||||
use PSC\Library\Calc\Error\Validation\Input\Max;
|
||||
use PSC\Library\Calc\Error\Validation\Input\Min;
|
||||
use PSC\Library\Calc\Option\Type\Select;
|
||||
use PSC\Library\Calc\PaperContainer;
|
||||
use PSC\Library\Calc\PreCalc\PreCalc;
|
||||
use PSC\Library\Calc\Tests\Mock\PaperRepostory;
|
||||
|
||||
class CalcTest extends TestCase
|
||||
{
|
||||
|
||||
protected ?Engine $engine;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$repository = new PaperRepostory();
|
||||
|
||||
$paperContainer = new PaperContainer();
|
||||
$paperContainer->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 testCalcPrice(): void
|
||||
{
|
||||
self::assertSame(2, $this->engine->getArticles()->count());
|
||||
self::assertSame(5000.0, $this->engine->getPrice());
|
||||
$this->engine->setActiveArticle($this->engine->getArticles()[1]->getName());
|
||||
self::assertSame(7500.0, $this->engine->getPrice());
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
42
tests/Customer/S/calc.xml
Normal file
42
tests/Customer/S/calc.xml
Normal file
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<kalkulation>
|
||||
<artikel>
|
||||
<name>Aufkleber Select</name>
|
||||
<kommentar>Freies Format</kommentar>
|
||||
|
||||
<uploads>
|
||||
<upload id="neutral" name="Druckdaten" description="Bitte laden sie eine PDF für den Druck hoch"/>
|
||||
</uploads>
|
||||
|
||||
<!-- Beginn der Eingabemaske -->
|
||||
|
||||
<option id="auflage" name="Auflage" type="Select" default="250" helplink="/cms/auflage?show=2&help=1">
|
||||
<opt id="250" name="250 Exemplare"></opt>
|
||||
</option>
|
||||
|
||||
<option id="calc" type="Hidden">
|
||||
<auflage>
|
||||
<grenze formel="20*$Vauflage$V">1-</grenze>
|
||||
</auflage>
|
||||
</option>
|
||||
</artikel>
|
||||
<artikel>
|
||||
<name>Aufkleber Input</name>
|
||||
<kommentar>Freies Format</kommentar>
|
||||
|
||||
<uploads>
|
||||
<upload id="neutral" name="Druckdaten so" description="Bitte laden sie eine PDF für den Druck hoch"/>
|
||||
</uploads>
|
||||
|
||||
<!-- Beginn der Eingabemaske -->
|
||||
|
||||
<option id="auflage" name="Auflage" type="Input" default="250" helplink="/cms/auflage?show=2&help=1">
|
||||
</option>
|
||||
|
||||
<option id="calc" type="Hidden">
|
||||
<auflage>
|
||||
<grenze formel="30*$Vauflage$V">1-</grenze>
|
||||
</auflage>
|
||||
</option>
|
||||
</artikel>
|
||||
</kalkulation>
|
||||
2
tests/Customer/S/calcTemplates.xml
Normal file
2
tests/Customer/S/calcTemplates.xml
Normal file
@ -0,0 +1,2 @@
|
||||
<root>
|
||||
</root>
|
||||
0
tests/Customer/S/formels.txt
Normal file
0
tests/Customer/S/formels.txt
Normal file
4
tests/Customer/S/papierContainer.xml
Normal file
4
tests/Customer/S/papierContainer.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<container>
|
||||
|
||||
</container>
|
||||
0
tests/Customer/S/parameters.txt
Normal file
0
tests/Customer/S/parameters.txt
Normal file
Loading…
Reference in New Issue
Block a user