This commit is contained in:
Thomas Peterson 2024-11-29 15:47:52 +01:00
parent 99b2b23593
commit d4c00e4c52
8 changed files with 93 additions and 2 deletions

File diff suppressed because one or more lines are too long

View File

@ -128,7 +128,7 @@ class 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();

View 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());
}
}

View 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>

View File

@ -0,0 +1,2 @@
<root>
</root>

View File

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<container>
</container>

View File