Fix Calc
This commit is contained in:
parent
896efa4758
commit
71011d6ba3
@ -238,6 +238,10 @@ class Engine
|
||||
|
||||
public function calc() {
|
||||
|
||||
$this->debugCalcFormel = [];
|
||||
$this->debugCalcVariables = [];
|
||||
$this->debugFlatPrice = [];
|
||||
$this->debugPrice = [];
|
||||
$this->price = 0;
|
||||
|
||||
$tmp = [];
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
56
tests/Customer/R/CheckboxTest.php
Normal file
56
tests/Customer/R/CheckboxTest.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace PSC\Library\Calc\Tests\Customer\R;
|
||||
|
||||
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 CheckboxTest 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_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());
|
||||
}
|
||||
}
|
||||
56
tests/Customer/R/RadioboxTest.php
Normal file
56
tests/Customer/R/RadioboxTest.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace PSC\Library\Calc\Tests\Customer\R;
|
||||
|
||||
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 RadioboxTest 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_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());
|
||||
}
|
||||
}
|
||||
@ -50,11 +50,32 @@
|
||||
<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">
|
||||
<option id="checkboxen2" name="Checkboxen 2" type="Checkbox" default="1,2">
|
||||
<opt id="1" name="Auswahl 2-1"></opt>
|
||||
<opt id="2" name="Auswahl 2-2"></opt>
|
||||
</option>
|
||||
<option id="checkboxen3" name="Checkboxen 3" type="Checkbox">
|
||||
<option id="checkboxen3" name="Checkboxen 3" type="Checkbox" default="2">
|
||||
<opt id="1" name="Auswahl 3-1"></opt>
|
||||
<opt id="2" name="Auswahl 3-2"></opt>
|
||||
</option>
|
||||
|
||||
<option id="radio1" name="Radio 1" type="Radio" default="2">
|
||||
<opt id="1" name="Radio 1-1"></opt>
|
||||
<opt id="2" name="Radio 1-2"></opt>
|
||||
</option>
|
||||
|
||||
|
||||
<option id="checkbox_calc" name="checkbox_calc" type="Hidden">
|
||||
<checkboxen2>
|
||||
<grenze formel="12">1</grenze>
|
||||
<grenze formel="14">2</grenze>
|
||||
</checkboxen2>
|
||||
</option>
|
||||
<option id="radio_calc" name="radio_calc" type="Hidden">
|
||||
<radio1>
|
||||
<grenze formel="52">1</grenze>
|
||||
<grenze formel="56">2</grenze>
|
||||
</radio1>
|
||||
</option>
|
||||
<!-- ### Eingabebox einzeilig 1 ### -->
|
||||
<option id="input1" name="Eingabe" type="Input" />
|
||||
@ -148,6 +169,24 @@
|
||||
<opt id="1" name="Auswahl 3-1"></opt>
|
||||
<opt id="2" name="Auswahl 3-2"></opt>
|
||||
</option>
|
||||
|
||||
<option id="radio1" name="Radio 1" type="Radio" default="2">
|
||||
<opt id="1" name="Radio 1-1"></opt>
|
||||
<opt id="2" name="Radio 1-2"></opt>
|
||||
</option>
|
||||
|
||||
<option id="checkbox_calc" name="checkbox_calc" type="Hidden">
|
||||
<checkboxen1>
|
||||
<grenze formel="12">1</grenze>
|
||||
<grenze formel="14">2</grenze>
|
||||
</checkboxen1>
|
||||
</option>
|
||||
<option id="radio_calc" name="radio_calc" type="Hidden">
|
||||
<radio1>
|
||||
<grenze formel="52">1</grenze>
|
||||
<grenze formel="56">2</grenze>
|
||||
</radio1>
|
||||
</option>
|
||||
<!-- ### Eingabebox einzeilig 1 ### -->
|
||||
<option id="input1" name="Eingabe" type="Input" />
|
||||
<!-- ### Eingabebox mehrzeilig 1 ### -->
|
||||
|
||||
20
tests/Customer/R/calc_checkbox.xml
Normal file
20
tests/Customer/R/calc_checkbox.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<kalkulation>
|
||||
<artikel>
|
||||
<name>Checkbox Grenze Formel</name>
|
||||
<kommentar></kommentar>
|
||||
|
||||
<option id="checkbox" name="Checkboxen 1" type="Checkbox" default="1,2">
|
||||
<opt id="1" name="Auswahl 1-1"></opt>
|
||||
<opt id="2" name="Auswahl 1-2"></opt>
|
||||
</option>
|
||||
|
||||
|
||||
<option id="checkbox_calc" name="checkbox_calc" type="Hidden">
|
||||
<checkbox>
|
||||
<grenze formel="12">1</grenze>
|
||||
<grenze formel="14">2</grenze>
|
||||
</checkbox>
|
||||
</option>
|
||||
</artikel>
|
||||
</kalkulation>
|
||||
20
tests/Customer/R/calc_radiobox.xml
Normal file
20
tests/Customer/R/calc_radiobox.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<kalkulation>
|
||||
<artikel>
|
||||
<name>Checkbox Grenze Formel</name>
|
||||
<kommentar></kommentar>
|
||||
|
||||
<option id="radiobox" name="Radiobox" type="Radio" default="1">
|
||||
<opt id="1" name="Auswahl 1-1"></opt>
|
||||
<opt id="2" name="Auswahl 1-2"></opt>
|
||||
</option>
|
||||
|
||||
|
||||
<option id="checkbox_calc" name="checkbox_calc" type="Hidden">
|
||||
<radiobox>
|
||||
<grenze formel="12">1</grenze>
|
||||
<grenze formel="14">2</grenze>
|
||||
</radiobox>
|
||||
</option>
|
||||
</artikel>
|
||||
</kalkulation>
|
||||
Loading…
Reference in New Issue
Block a user