Fix Calc
This commit is contained in:
parent
70f6ccd51d
commit
65e6e9699d
File diff suppressed because one or more lines are too long
@ -13,7 +13,7 @@
|
||||
}
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.0",
|
||||
"php": ">=7.1",
|
||||
"doctrine/orm": "^2.5",
|
||||
"azuyalabs/yasumi": "^2.5"
|
||||
},
|
||||
|
||||
@ -163,28 +163,44 @@ class Valid
|
||||
*/
|
||||
private function edgeIsValid($section, $edge)
|
||||
{
|
||||
$valid = false;
|
||||
$skipTests = false;
|
||||
|
||||
if(!isset($this->engine->getVariables()[$section])) {
|
||||
return false;
|
||||
$skipTests = true;
|
||||
}
|
||||
|
||||
|
||||
if($edge->isRegion() &&
|
||||
if(!$skipTests && !$valid && $edge->isRegion() &&
|
||||
$edge->getFrom() <= $this->engine->getVariables()[$section] &&
|
||||
$edge->getTo() >= $this->engine->getVariables()[$section]) {
|
||||
return true;
|
||||
$valid = true;
|
||||
}
|
||||
|
||||
if($edge->isRegion() &&
|
||||
if(!$skipTests && !$valid && $edge->isRegion() &&
|
||||
$edge->getFrom() <= $this->engine->getVariables()[$section] &&
|
||||
$edge->getTo() == 0) {
|
||||
return true;
|
||||
$valid = true;
|
||||
}
|
||||
|
||||
if(!$edge->isRegion() && in_array($this->engine->getVariables()[$section], $edge->getValues())) {
|
||||
return true;
|
||||
if(!$skipTests && !$valid && !$edge->isRegion() && in_array($this->engine->getVariables()[$section], $edge->getValues())) {
|
||||
$valid = true;
|
||||
}
|
||||
|
||||
return false;
|
||||
if(!$skipTests && $valid && $edge->getEdgesCollectionContainer()->count()) {
|
||||
$valid = false;
|
||||
/** @var EdgeCollection $collection */
|
||||
foreach($edge->getEdgesCollectionContainer() as $collection) {
|
||||
foreach($collection as $subEdge) {
|
||||
if(!$valid) {
|
||||
$valid = $this->edgeIsValid($collection->getName(), $subEdge);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -70,29 +70,32 @@ class Edge
|
||||
}
|
||||
|
||||
if (isset($this->node->attributes()->value) && $this->node->children()) {
|
||||
$edge->setValues(explode(",", trim((string) $this->node->attributes()->value)));
|
||||
$this->parseCondition($edge, trim((string) $this->node->attributes()->value));
|
||||
if ($this->node->children()) {
|
||||
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node);
|
||||
$edge->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());
|
||||
}
|
||||
} else {
|
||||
|
||||
$value = (string) $this->node;
|
||||
if (preg_match("/^([0-9a-zA-Z_]+)$/", trim($value), $regs)) {
|
||||
$edge->setValues([$regs[1]]);
|
||||
} elseif (preg_match("/^([0-9]+)-([0-9]+)$/", trim($value), $regs)) {
|
||||
$edge->setRegion(true);
|
||||
$edge->setFrom(intval($regs[1]));
|
||||
$edge->setTo(intval($regs[2]));
|
||||
} elseif (preg_match("/^([0-9]+)-$/", trim($value), $regs)) {
|
||||
$edge->setRegion(true);
|
||||
$edge->setFrom(intval($regs[1]));
|
||||
} elseif (strpos(trim($value), ",") !== false) {
|
||||
$values = explode(",", trim($value));
|
||||
$edge->setValues($values);
|
||||
}
|
||||
$this->parseCondition($edge, trim((string) $this->node));
|
||||
}
|
||||
|
||||
return $edge;
|
||||
}
|
||||
|
||||
private function parseCondition(\PSC\Library\Calc\General\Type\Edge $edge, string $condition): void
|
||||
{
|
||||
if (preg_match("/^([0-9a-zA-Z_]+)$/", trim($condition), $regs)) {
|
||||
$edge->setValues([$regs[1]]);
|
||||
} elseif (preg_match("/^([0-9]+)-([0-9]+)$/", trim($condition), $regs)) {
|
||||
$edge->setRegion(true);
|
||||
$edge->setFrom(intval($regs[1]));
|
||||
$edge->setTo(intval($regs[2]));
|
||||
} elseif (preg_match("/^([0-9]+)-$/", trim($condition), $regs)) {
|
||||
$edge->setRegion(true);
|
||||
$edge->setFrom(intval($regs[1]));
|
||||
} elseif (strpos(trim($condition), ",") !== false) {
|
||||
$values = explode(",", trim($condition));
|
||||
$edge->setValues($values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
73
tests/Customer/AA/CalcTest.php
Normal file
73
tests/Customer/AA/CalcTest.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace PSC\Library\Calc\Tests\Customer\AA;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PSC\Library\Calc\Article;
|
||||
use PSC\Library\Calc\Engine;
|
||||
use PSC\Library\Calc\Option\Type\Select;
|
||||
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 testAuflageBelow100(): void
|
||||
{
|
||||
$this->assertEquals("ohne" , $this->engine->getArticle()->getOptionById('druckfarbe')->getRawValue());
|
||||
$this->assertEquals("ohne" , $this->engine->getArticle()->getOptionById('druckart')->getRawValue());
|
||||
}
|
||||
|
||||
public function testAuflageBelow100AndMaterial160(): void
|
||||
{
|
||||
$this->engine->setVariable('auflage', 99);
|
||||
$this->engine->setVariable('material', 160);
|
||||
$this->engine->calc();
|
||||
$this->assertEquals("schwarz" , $this->engine->getArticle()->getOptionById('druckfarbe')->getRawValue());
|
||||
|
||||
/** @var Select $option */
|
||||
$option = $this->engine->getArticle()->getOptionById('druckart');
|
||||
|
||||
$this->assertEquals("einseitig" , $option->getRawValue());
|
||||
$this->assertCount(2, $option->getValidOptions());
|
||||
}
|
||||
|
||||
public function testAuflageBelow100AndMaterial250(): void
|
||||
{
|
||||
$this->engine->setVariable('auflage', 140);
|
||||
$this->engine->calc();
|
||||
$this->assertEquals("ohne" , $this->engine->getArticle()->getOptionById('druckfarbe')->getRawValue());
|
||||
|
||||
/** @var Select $option */
|
||||
$option = $this->engine->getArticle()->getOptionById('druckart');
|
||||
|
||||
$this->assertEquals("ohne" , $option->getRawValue());
|
||||
$this->assertCount(1, $option->getValidOptions());
|
||||
}
|
||||
|
||||
}
|
||||
71
tests/Customer/AA/calc.xml
Normal file
71
tests/Customer/AA/calc.xml
Normal file
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<kalkulation>
|
||||
<artikel>
|
||||
<name>Drahtspiralbindung</name>
|
||||
<kommentar></kommentar>
|
||||
|
||||
<uploads>
|
||||
<upload id="inhalt" name="Druckdaten" description="Bitte laden Sie eine PDF für den Inhalt hoch"></upload>
|
||||
</uploads>
|
||||
|
||||
<!-- Eingabemaske -->
|
||||
<option id="lieferdatum" name="Lieferdatum" type="Input" width="5" default="" help="Tragen Sie hier bitte das gewünschte Lieferdatum ein." require="true"></option>
|
||||
|
||||
<option id="kostenstelle" name="Kostenstelle" type="Select" width="5" default="kst1">
|
||||
<opt id="kst1" name="Kst 1"/>
|
||||
</option>
|
||||
|
||||
<option id="arbeitstitel" name="Arbeitstitel" type="Input" width="5" default="" help="Geben Sie den Arbeitstitel ein." pattern="[A-Za-z0-9\s]+" errorMessage="Bitte verwenden Sie nur alphanumerische Zeichen."></option>
|
||||
|
||||
<option id="auflage" name="Auflage" type="Input" width="5" default="5" min="5" max="250" pattern="[0-9]+" errorMessage="Bitte geben Sie eine Zahl zwischen 5 und 250 ein."></option>
|
||||
|
||||
<option id="material" name="Material" type="Select" width="5" default="ohne" onChange="updateFields()">
|
||||
<opt id="ohne" name="Ohne"/>
|
||||
<opt id="160" name="160 g/m²"/>
|
||||
<opt id="250" name="250 g/m²"/>
|
||||
</option>
|
||||
|
||||
<option id="druckfarbe" name="Druckfarbe" type="Select" width="5" default="ohne">
|
||||
<opt id="ohne" name="Ohne">
|
||||
<material>
|
||||
<grenze>ohne</grenze>
|
||||
</material>
|
||||
</opt>
|
||||
<opt id="schwarz" name="Schwarz">
|
||||
<material>
|
||||
<grenze>160,250</grenze>
|
||||
</material>
|
||||
</opt>
|
||||
</option>
|
||||
|
||||
<option id="druckart" name="Druckart" type="Select" width="5" default="ohne">
|
||||
<opt id="ohne" name="Ohne">
|
||||
<material>
|
||||
<grenze>ohne</grenze>
|
||||
</material>
|
||||
</opt>
|
||||
<opt id="einseitig" name="Einseitig">
|
||||
<material>
|
||||
<grenze>160,250</grenze>
|
||||
</material>
|
||||
</opt>
|
||||
<opt id="zweiseitig" name="Zweiseitig">
|
||||
<auflage>
|
||||
<grenze value="1-99">
|
||||
<material>
|
||||
<grenze>160,250</grenze>
|
||||
</material>
|
||||
</grenze>
|
||||
<grenze value="100-">
|
||||
<material>
|
||||
<grenze>160</grenze>
|
||||
</material>
|
||||
</grenze>
|
||||
</auflage>
|
||||
</opt>
|
||||
</option>
|
||||
</artikel>
|
||||
|
||||
<!-- Weitere Kalkulationselemente hier einfügen -->
|
||||
|
||||
</kalkulation>
|
||||
3
tests/Customer/AA/calcTemplates.xml
Normal file
3
tests/Customer/AA/calcTemplates.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<root>
|
||||
|
||||
</root>
|
||||
0
tests/Customer/AA/formels.txt
Normal file
0
tests/Customer/AA/formels.txt
Normal file
4
tests/Customer/AA/papierContainer.xml
Normal file
4
tests/Customer/AA/papierContainer.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<container>
|
||||
|
||||
</container>
|
||||
0
tests/Customer/AA/parameters.txt
Normal file
0
tests/Customer/AA/parameters.txt
Normal file
@ -7,6 +7,8 @@
|
||||
<upload id="neutral" name="Druckdaten" description="Bitte laden sie eine PDF für den Druck hoch"/>
|
||||
</uploads>
|
||||
|
||||
<option id="auflage" name="auflage" type="Input" default="1"></option>
|
||||
|
||||
// EINGABE *******************************************************************************
|
||||
|
||||
<option id="kalender_typ2" name="Bitte senden Sie mir folgende Muster-Kalender:" type="Checkbox" default="1,2">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user