Fix Calc php 8

This commit is contained in:
Thomas Peterson 2023-01-18 10:39:17 +01:00
parent b7d5623310
commit d30779c3ce
7 changed files with 82 additions and 1 deletions

View File

@ -145,7 +145,11 @@ class Formel
if ($variables [$foundvalue] == '') {
$formel = str_replace($found, 0, $formel);
} else {
$formel = str_replace($found, $variables [$foundvalue], $formel);
if(is_array($variables [$foundvalue])) {
$formel = str_replace($found, 0, $formel);
}else{
$formel = str_replace($found, $variables [$foundvalue], $formel);
}
}
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace PSC\Library\Calc\Tests\Customer\U;
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 testIfDefaultPriceIsOk(): void
{
$this->engine->calc();
$this->assertEquals(202 , $this->engine->getPrice());
$this->assertEquals('135 g/m² Bilderdruck matt gestrichen', $this->engine->getArticle()->getOptionById('papier')->getValue());
}
}

19
tests/Customer/U/calc.xml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- ACHTUNG STA+ PRÄ verwendet wegen "A < 682 cm2 Problem" hier IMMER den Fixwert von Fischer statt Tiegel -->
<kalkulation>
<artikel>
<name>Banderolen</name>
<kommentar/>
<option id="auflage" name="Auflage" type="Input" default="4" min="1" max="50000"/>
<option id="papier" name="Papier" type="Select" mode="papierdb" container="test_1" default="INM135ND">
</option>
<option id="calc_formel" name="calc_formel" type="Hidden" default="1">
<auflage>
<grenze formel="$Vauflage$V*$Vpapier_value$V">1-</grenze>
</auflage>
</option>
</artikel>
</kalkulation>

View File

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

View File

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<container>
<papiercontainer id="test_1">
<papier id="INM135"/>
<papier id="INM115"/>
<papier id="INM135ND"/>
</papiercontainer>
</container>

View File