Fixes
This commit is contained in:
parent
d4c00e4c52
commit
1831fca802
File diff suppressed because one or more lines are too long
@ -96,7 +96,9 @@ class Calc
|
||||
$var = $this->engine->getVariables()[$collection->getName()];
|
||||
}
|
||||
}
|
||||
|
||||
if($collection->getDefault() != "" && $var === "XXXXXXXXXXXX") {
|
||||
$var = $collection->getDefault();
|
||||
}
|
||||
/** @var Edge $edge */
|
||||
foreach ($collection as $edge) {
|
||||
|
||||
|
||||
@ -31,6 +31,10 @@ class EdgeCollection
|
||||
$collection->setFormel((string)$this->node->attributes()->formel);
|
||||
}
|
||||
|
||||
if(isset($this->node->attributes()->default)) {
|
||||
$collection->setDefault((string)$this->node->attributes()->default);
|
||||
}
|
||||
|
||||
foreach($this->node->grenze as $row) {
|
||||
$edgeParser = new Edge($row);
|
||||
$edge = $edgeParser->parse();
|
||||
|
||||
@ -5,41 +5,41 @@ namespace PSC\Library\Calc\General\Type;
|
||||
class EdgeCollection extends \ArrayIterator
|
||||
{
|
||||
|
||||
protected $name = '';
|
||||
protected string $name = '';
|
||||
|
||||
protected $formel = '';
|
||||
protected string $formel = '';
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
protected string $default = '';
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
return (string)$this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name)
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFormel()
|
||||
public function getFormel(): string
|
||||
{
|
||||
return $this->formel;
|
||||
return (string)$this->formel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $formel
|
||||
*/
|
||||
public function setFormel($formel)
|
||||
public function setFormel(string $formel): void
|
||||
{
|
||||
$this->formel = $formel;
|
||||
}
|
||||
|
||||
public function getDefault(): string
|
||||
{
|
||||
return (string)$this->default;
|
||||
}
|
||||
|
||||
public function setDefault(string $default): void
|
||||
{
|
||||
$this->default = $default;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
61
tests/Contact/Account/CalcTest.php
Normal file
61
tests/Contact/Account/CalcTest.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
namespace PSC\Library\Calc\Tests\Contact\Account;
|
||||
|
||||
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 testPriceDefault(): void
|
||||
{
|
||||
self::assertSame(4.5, $this->engine->getPrice());
|
||||
}
|
||||
|
||||
public function testPrice1(): void
|
||||
{
|
||||
$this->engine->setVariable('contact.account', 12);
|
||||
self::assertSame(4.5, $this->engine->getPrice());
|
||||
}
|
||||
|
||||
public function testPrice123(): void
|
||||
{
|
||||
$this->engine->setVariable('contact.account', 123);
|
||||
self::assertSame(5.4, $this->engine->getPrice());
|
||||
}
|
||||
|
||||
public function testPrice334(): void
|
||||
{
|
||||
$this->engine->setVariable('contact.account', 334);
|
||||
self::assertSame(2.25, $this->engine->getPrice());
|
||||
}
|
||||
}
|
||||
25
tests/Contact/Account/calc.xml
Normal file
25
tests/Contact/Account/calc.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?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.account default="12">
|
||||
<grenze calc_value="1">12</grenze>
|
||||
<grenze calc_value="1.2">123</grenze>
|
||||
<grenze calc_value="0.8">21</grenze>
|
||||
<grenze calc_value="0.5">334</grenze>
|
||||
</contact.account>
|
||||
</option>
|
||||
|
||||
<option id="calc" type="Hidden">
|
||||
<auflage>
|
||||
<grenze formel="0.45*$Vauflage$V*$CVcalc_rabatt_contact.account$CV">1-</grenze>
|
||||
</auflage>
|
||||
</option>
|
||||
|
||||
</artikel>
|
||||
</kalkulation>
|
||||
2
tests/Contact/Account/calcTemplates.xml
Normal file
2
tests/Contact/Account/calcTemplates.xml
Normal file
@ -0,0 +1,2 @@
|
||||
<root>
|
||||
</root>
|
||||
0
tests/Contact/Account/formels.txt
Normal file
0
tests/Contact/Account/formels.txt
Normal file
4
tests/Contact/Account/papierContainer.xml
Normal file
4
tests/Contact/Account/papierContainer.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<container>
|
||||
|
||||
</container>
|
||||
0
tests/Contact/Account/parameters.txt
Normal file
0
tests/Contact/Account/parameters.txt
Normal file
@ -8,7 +8,7 @@
|
||||
|
||||
<option id="calc_rabatt" type="Hidden">
|
||||
<contact.accountType>
|
||||
<grenze calc_value="1">0-1</grenze>
|
||||
<grenze calc_value="1">1</grenze>
|
||||
<grenze calc_value="0.8">2</grenze>
|
||||
<grenze calc_value="0.5">3</grenze>
|
||||
</contact.accountType>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user