Fixes
This commit is contained in:
parent
99b2b23593
commit
d4c00e4c52
File diff suppressed because one or more lines are too long
@ -128,7 +128,7 @@ class Formel
|
|||||||
|
|
||||||
private function parseCalcVariables($formel)
|
private function parseCalcVariables($formel)
|
||||||
{
|
{
|
||||||
preg_match_all('/\$CV\w*\$CV/', $formel, $founds);
|
preg_match_all('/\$CV[\w\.]*\$CV/', $formel, $founds);
|
||||||
|
|
||||||
$variables = $this->engine->getCalcVariables();
|
$variables = $this->engine->getCalcVariables();
|
||||||
|
|
||||||
|
|||||||
61
tests/Contact/AccountType/CalcTest.php
Normal file
61
tests/Contact/AccountType/CalcTest.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
namespace PSC\Library\Calc\Tests\Contact\AccountType;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use PSC\Library\Calc\Article;
|
||||||
|
use PSC\Library\Calc\Engine;
|
||||||
|
use PSC\Library\Calc\PaperContainer;
|
||||||
|
use PSC\Library\Calc\Tests\Mock\PaperRepostory;
|
||||||
|
|
||||||
|
class CalcTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var Engine */
|
||||||
|
protected $engine = null;
|
||||||
|
|
||||||
|
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 testPriceWithout(): void
|
||||||
|
{
|
||||||
|
self::assertSame(0.0, $this->engine->getPrice());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPrice(): void
|
||||||
|
{
|
||||||
|
$this->engine->setVariable('contact.accountType', 1);
|
||||||
|
self::assertSame(100.0, $this->engine->getPrice());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPriceCompany(): void
|
||||||
|
{
|
||||||
|
$this->engine->setVariable('contact.accountType', 2);
|
||||||
|
self::assertSame(80.0, $this->engine->getPrice());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPriceAsso(): void
|
||||||
|
{
|
||||||
|
$this->engine->setVariable('contact.accountType', 3);
|
||||||
|
self::assertSame(50.0, $this->engine->getPrice());
|
||||||
|
}
|
||||||
|
}
|
||||||
24
tests/Contact/AccountType/calc.xml
Normal file
24
tests/Contact/AccountType/calc.xml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<kalkulation>
|
||||||
|
<artikel>
|
||||||
|
<name>SD-Durchschreibesätze A4-Blocks</name>
|
||||||
|
<kommentar>210 mm x 297 mm</kommentar>
|
||||||
|
|
||||||
|
<option id="auflage" name="Auflage" type="Input" default="10"/>
|
||||||
|
|
||||||
|
<option id="calc_rabatt" type="Hidden">
|
||||||
|
<contact.accountType>
|
||||||
|
<grenze calc_value="1">0-1</grenze>
|
||||||
|
<grenze calc_value="0.8">2</grenze>
|
||||||
|
<grenze calc_value="0.5">3</grenze>
|
||||||
|
</contact.accountType>
|
||||||
|
</option>
|
||||||
|
|
||||||
|
<option id="calc" type="Hidden">
|
||||||
|
<auflage>
|
||||||
|
<grenze formel="10*$Vauflage$V*$CVcalc_rabatt_contact.accountType$CV">1-</grenze>
|
||||||
|
</auflage>
|
||||||
|
</option>
|
||||||
|
|
||||||
|
</artikel>
|
||||||
|
</kalkulation>
|
||||||
2
tests/Contact/AccountType/calcTemplates.xml
Normal file
2
tests/Contact/AccountType/calcTemplates.xml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<root>
|
||||||
|
</root>
|
||||||
0
tests/Contact/AccountType/formels.txt
Normal file
0
tests/Contact/AccountType/formels.txt
Normal file
4
tests/Contact/AccountType/papierContainer.xml
Normal file
4
tests/Contact/AccountType/papierContainer.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<container>
|
||||||
|
|
||||||
|
</container>
|
||||||
0
tests/Contact/AccountType/parameters.txt
Normal file
0
tests/Contact/AccountType/parameters.txt
Normal file
Loading…
Reference in New Issue
Block a user