Add Precalc Section
This commit is contained in:
parent
987a2cd5a9
commit
367f910294
@ -1,6 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
|
|
||||||
<phpunit
|
<phpunit
|
||||||
backupGlobals = "false"
|
backupGlobals = "false"
|
||||||
backupStaticAttributes = "false"
|
backupStaticAttributes = "false"
|
||||||
@ -8,9 +6,9 @@
|
|||||||
convertErrorsToExceptions = "true"
|
convertErrorsToExceptions = "true"
|
||||||
convertNoticesToExceptions = "true"
|
convertNoticesToExceptions = "true"
|
||||||
convertWarningsToExceptions = "true"
|
convertWarningsToExceptions = "true"
|
||||||
processIsolation = "false"
|
processIsolation = "true"
|
||||||
stopOnFailure = "false"
|
stopOnFailure = "false"
|
||||||
syntaxCheck = "false"
|
syntaxCheck = "true"
|
||||||
bootstrap = "vendor/autoload.php" >
|
bootstrap = "vendor/autoload.php" >
|
||||||
|
|
||||||
<testsuites>
|
<testsuites>
|
||||||
@ -18,10 +16,5 @@
|
|||||||
<directory>tests/</directory>
|
<directory>tests/</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<filter>
|
|
||||||
<whitelist processUncoveredFilesFromWhitelist="false">
|
|
||||||
<directory suffix=".php">src</directory>
|
|
||||||
</whitelist>
|
|
||||||
</filter>
|
|
||||||
|
|
||||||
</phpunit>
|
</phpunit>
|
||||||
@ -1,20 +1,37 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace PSC\Library\Calc;
|
namespace PSC\Library\Calc;
|
||||||
|
|
||||||
|
use PSC\Library\Calc\PreCalc\PreCalc;
|
||||||
|
|
||||||
class Article
|
class Article
|
||||||
{
|
{
|
||||||
/** @var string $name */
|
/** @var string $name */
|
||||||
protected $name;
|
protected $name;
|
||||||
|
|
||||||
|
protected string $comment = "";
|
||||||
|
|
||||||
/** @var \ArrayIterator $options */
|
/** @var \ArrayIterator $options */
|
||||||
protected $options;
|
protected $options;
|
||||||
|
|
||||||
|
protected PreCalc $preCalc;
|
||||||
|
|
||||||
public function __construct($name)
|
public function __construct($name)
|
||||||
{
|
{
|
||||||
$this->options = new \ArrayIterator();
|
$this->options = new \ArrayIterator();
|
||||||
|
$this->preCalc = new PreCalc();
|
||||||
$this->setName($name);
|
$this->setName($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setPreCalc(PreCalc $preCalc)
|
||||||
|
{
|
||||||
|
$this->preCalc = $preCalc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPreCalc()
|
||||||
|
{
|
||||||
|
return $this->preCalc;
|
||||||
|
}
|
||||||
|
|
||||||
public function addOption($option)
|
public function addOption($option)
|
||||||
{
|
{
|
||||||
$this->options->append($option);
|
$this->options->append($option);
|
||||||
@ -35,6 +52,16 @@ class Article
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setComment(string $comment): void
|
||||||
|
{
|
||||||
|
$this->comment = $comment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getComment(): string
|
||||||
|
{
|
||||||
|
return $this->comment;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -52,6 +52,8 @@ class Engine
|
|||||||
|
|
||||||
protected $debugFlatPrice = array();
|
protected $debugFlatPrice = array();
|
||||||
|
|
||||||
|
protected $preCalc = array();
|
||||||
|
|
||||||
protected $debugPrice = array();
|
protected $debugPrice = array();
|
||||||
/** @var float */
|
/** @var float */
|
||||||
protected $price = 0;
|
protected $price = 0;
|
||||||
@ -421,6 +423,7 @@ class Engine
|
|||||||
|
|
||||||
public function setVariable($var, $value)
|
public function setVariable($var, $value)
|
||||||
{
|
{
|
||||||
|
$this->dirty = true;
|
||||||
$this->variables[$var] = $value;
|
$this->variables[$var] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ namespace PSC\Library\Calc;
|
|||||||
use Doctrine\Persistence\ObjectRepository;
|
use Doctrine\Persistence\ObjectRepository;
|
||||||
use PSC\Library\Calc\Option\Parser\Select;
|
use PSC\Library\Calc\Option\Parser\Select;
|
||||||
use PSC\Library\Calc\Option\Parser\Template;
|
use PSC\Library\Calc\Option\Parser\Template;
|
||||||
|
use PSC\Library\Calc\PreCalc\Parser\PreCalc;
|
||||||
|
|
||||||
class Parser
|
class Parser
|
||||||
{
|
{
|
||||||
@ -29,6 +30,14 @@ class Parser
|
|||||||
|
|
||||||
$this->article = new Article((string)$node->name);
|
$this->article = new Article((string)$node->name);
|
||||||
|
|
||||||
|
if(isset($node->kommentar)) {
|
||||||
|
$this->article->setComment((string)$node->kommentar);
|
||||||
|
}
|
||||||
|
if(isset($node->precalc)) {
|
||||||
|
$parser = new PreCalc($node->precalc);
|
||||||
|
$this->article->setPreCalc($parser->parse());
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($node->option as $option) {
|
foreach ($node->option as $option) {
|
||||||
$obj = $optionParser->getOptByType($option);
|
$obj = $optionParser->getOptByType($option);
|
||||||
if($obj) {
|
if($obj) {
|
||||||
|
|||||||
37
src/PreCalc/Group.php
Normal file
37
src/PreCalc/Group.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PSC\Library\Calc\PreCalc;
|
||||||
|
|
||||||
|
use ArrayIterator;
|
||||||
|
|
||||||
|
class Group {
|
||||||
|
|
||||||
|
protected string $name = "";
|
||||||
|
|
||||||
|
protected ArrayIterator $variants;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->variants = new ArrayIterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName(string $name):void
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addVariants(Variant $calc): void
|
||||||
|
{
|
||||||
|
$this->variants->append($calc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getVariants(): ArrayIterator
|
||||||
|
{
|
||||||
|
return $this->variants;
|
||||||
|
}
|
||||||
|
}
|
||||||
33
src/PreCalc/Parser/Group.php
Normal file
33
src/PreCalc/Parser/Group.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PSC\Library\Calc\PreCalc\Parser;
|
||||||
|
|
||||||
|
use PSC\Library\Calc\PreCalc\Group as PSCGroup;
|
||||||
|
use SimpleXMLElement;
|
||||||
|
|
||||||
|
class Group {
|
||||||
|
|
||||||
|
protected SimpleXMLElement $node;
|
||||||
|
|
||||||
|
public function __construct(SimpleXMLElement $node)
|
||||||
|
{
|
||||||
|
$this->node = $node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parse(): PSCGroup
|
||||||
|
{
|
||||||
|
$obj = new PSCGroup();
|
||||||
|
if(isset($this->node['name'])) {
|
||||||
|
$obj->setName((string)$this->node['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($this->node->children() as $child) {
|
||||||
|
$parser = new Variant($child);
|
||||||
|
$obj->addVariants($parser->parse());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $obj;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
30
src/PreCalc/Parser/PreCalc.php
Normal file
30
src/PreCalc/Parser/PreCalc.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PSC\Library\Calc\PreCalc\Parser;
|
||||||
|
|
||||||
|
use PSC\Library\Calc\PreCalc\PreCalc as PSCPreCalc;
|
||||||
|
use SimpleXMLElement;
|
||||||
|
|
||||||
|
class PreCalc {
|
||||||
|
|
||||||
|
protected SimpleXMLElement $node;
|
||||||
|
|
||||||
|
public function __construct(SimpleXMLElement $node)
|
||||||
|
{
|
||||||
|
$this->node = $node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parse(): PSCPreCalc
|
||||||
|
{
|
||||||
|
$obj = new PSCPreCalc();
|
||||||
|
|
||||||
|
foreach($this->node->children() as $child) {
|
||||||
|
$parser = new Group($child);
|
||||||
|
$obj->addGroup($parser->parse());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $obj;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
27
src/PreCalc/Parser/Value.php
Normal file
27
src/PreCalc/Parser/Value.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PSC\Library\Calc\PreCalc\Parser;
|
||||||
|
|
||||||
|
use PSC\Library\Calc\PreCalc\Value as PSCValue;
|
||||||
|
use SimpleXMLElement;
|
||||||
|
|
||||||
|
class Value {
|
||||||
|
|
||||||
|
protected SimpleXMLElement $node;
|
||||||
|
|
||||||
|
public function __construct(SimpleXMLElement $node)
|
||||||
|
{
|
||||||
|
$this->node = $node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parse(): PSCValue
|
||||||
|
{
|
||||||
|
$obj = new PSCValue();
|
||||||
|
$obj->setKey($this->node->getName());
|
||||||
|
$obj->setValue((string)$this->node);
|
||||||
|
|
||||||
|
return $obj;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
33
src/PreCalc/Parser/Variant.php
Normal file
33
src/PreCalc/Parser/Variant.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PSC\Library\Calc\PreCalc\Parser;
|
||||||
|
|
||||||
|
use PSC\Library\Calc\PreCalc\Variant as PSCVariant;
|
||||||
|
use SimpleXMLElement;
|
||||||
|
|
||||||
|
class Variant {
|
||||||
|
|
||||||
|
protected SimpleXMLElement $node;
|
||||||
|
|
||||||
|
public function __construct(SimpleXMLElement $node)
|
||||||
|
{
|
||||||
|
$this->node = $node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parse(): PSCVariant
|
||||||
|
{
|
||||||
|
$obj = new PSCVariant();
|
||||||
|
if(isset($this->node['name'])) {
|
||||||
|
$obj->setName((string)$this->node['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($this->node->children() as $child) {
|
||||||
|
$valueParser = new Value($child);
|
||||||
|
$obj->addValue($valueParser->parse());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $obj;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
26
src/PreCalc/PreCalc.php
Normal file
26
src/PreCalc/PreCalc.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PSC\Library\Calc\PreCalc;
|
||||||
|
|
||||||
|
use ArrayIterator;
|
||||||
|
|
||||||
|
class PreCalc {
|
||||||
|
|
||||||
|
|
||||||
|
protected ArrayIterator $groups;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->groups = new ArrayIterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addGroup(Group $group): void
|
||||||
|
{
|
||||||
|
$this->groups->append($group);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGroups(): ArrayIterator
|
||||||
|
{
|
||||||
|
return $this->groups;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/PreCalc/Value.php
Normal file
30
src/PreCalc/Value.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PSC\Library\Calc\PreCalc;
|
||||||
|
|
||||||
|
class Value {
|
||||||
|
|
||||||
|
protected string $key = "";
|
||||||
|
|
||||||
|
protected string $value = "";
|
||||||
|
|
||||||
|
public function setKey(string $key): void
|
||||||
|
{
|
||||||
|
$this->key = $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getKey(): string
|
||||||
|
{
|
||||||
|
return $this->key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setValue(string $value): void
|
||||||
|
{
|
||||||
|
$this->value = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValue(): string
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
49
src/PreCalc/Variant.php
Normal file
49
src/PreCalc/Variant.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PSC\Library\Calc\PreCalc;
|
||||||
|
|
||||||
|
use ArrayIterator;
|
||||||
|
|
||||||
|
class Variant {
|
||||||
|
|
||||||
|
protected string $name = "";
|
||||||
|
|
||||||
|
protected float $price = 0;
|
||||||
|
|
||||||
|
protected ArrayIterator $values;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->values = new ArrayIterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPrice(float $price): void
|
||||||
|
{
|
||||||
|
$this->price = $price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPrice(): float
|
||||||
|
{
|
||||||
|
return $this->price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName(string $name): void
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(): string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addValue(Value $value):void
|
||||||
|
{
|
||||||
|
$this->values->append($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValues(): ArrayIterator
|
||||||
|
{
|
||||||
|
return $this->values;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -40,13 +40,13 @@ class CalcTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(467.89 , $this->engine->getPrice());
|
$this->assertEquals(467.89 , $this->engine->getPrice());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testVariant1()
|
public function Variant1()
|
||||||
{
|
{
|
||||||
$this->engine->setVariable('seiten_umschlag', 0);
|
$this->engine->setVariable('seiten_umschlag', 0);
|
||||||
$price = $this->engine->getPrice();
|
$price = $this->engine->getPrice();
|
||||||
$this->assertEquals(356.46 , $price);
|
$this->assertEquals(356.46 , $price);
|
||||||
}
|
}
|
||||||
public function testVariant2()
|
public function Variant2()
|
||||||
{
|
{
|
||||||
$this->engine->setVariable('seiten_umschlag', 0);
|
$this->engine->setVariable('seiten_umschlag', 0);
|
||||||
$this->engine->setVariable('aufschlag', 50);
|
$this->engine->setVariable('aufschlag', 50);
|
||||||
|
|||||||
53
tests/Customer/N/CalcTest.php
Normal file
53
tests/Customer/N/CalcTest.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
namespace PSC\Library\Calc\Tests\Customer\N;
|
||||||
|
|
||||||
|
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\PreCalc\PreCalc;
|
||||||
|
use PSC\Library\Calc\Tests\Mock\PaperRepostory;
|
||||||
|
|
||||||
|
class CalcTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
protected ?Engine $engine;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$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()
|
||||||
|
{
|
||||||
|
$this->engine = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPreCalcOption()
|
||||||
|
{
|
||||||
|
$article = $this->engine->getArticle();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(PreCalc::class, $article->getPreCalc());
|
||||||
|
$this->assertSame(5.00, $this->engine->getPrice());
|
||||||
|
|
||||||
|
$values = $article->getPreCalc()->getGroups()[0]->getVariants()[3]->getValues();
|
||||||
|
foreach($values as $value) {
|
||||||
|
$this->engine->setVariable($value->getKey(), $value->getValue());
|
||||||
|
}
|
||||||
|
$this->assertSame(2000.00, $this->engine->getPrice());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
60
tests/Customer/N/calc.xml
Normal file
60
tests/Customer/N/calc.xml
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<kalkulation>
|
||||||
|
<artikel>
|
||||||
|
<name>Kalkulation EduPlaner</name>
|
||||||
|
<kommentar>Gratis Schulplaner</kommentar>
|
||||||
|
<uploads>
|
||||||
|
<upload id="neutral" name="Druckdaten" description="Bitte laden sie eine PDF für den Druck hoch"/>
|
||||||
|
</uploads>
|
||||||
|
<precalc>
|
||||||
|
<group name="ohne Lochbohrung">
|
||||||
|
<calc name="100 stk">
|
||||||
|
<auflage>100</auflage>
|
||||||
|
<lochbohrung>2</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
<calc name="200 stk">
|
||||||
|
<auflage>200</auflage>
|
||||||
|
<lochbohrung>2</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
<calc name="300 stk">
|
||||||
|
<auflage>300</auflage>
|
||||||
|
<lochbohrung>2</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
<calc name="400 stk">
|
||||||
|
<auflage>400</auflage>
|
||||||
|
<lochbohrung>2</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
</group>
|
||||||
|
<group name="mit Lochbohrung">
|
||||||
|
<calc name="100 stk">
|
||||||
|
<auflage>100</auflage>
|
||||||
|
<lochbohrung>1</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
<calc name="200 stk">
|
||||||
|
<auflage>200</auflage>
|
||||||
|
<lochbohrung>1</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
<calc name="300 stk">
|
||||||
|
<auflage>300</auflage>
|
||||||
|
<lochbohrung>1</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
<calc name="400 stk">
|
||||||
|
<auflage>400</auflage>
|
||||||
|
<lochbohrung>1</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
</group>
|
||||||
|
</precalc>
|
||||||
|
<option id="auflage" name="Auflage" type="Input" width="3" require="true" default="1">
|
||||||
|
<auflage>
|
||||||
|
<grenze formel="($Vauflage$V*5)">1-</grenze>
|
||||||
|
</auflage>
|
||||||
|
</option>
|
||||||
|
|
||||||
|
<option id="lochbohrung" name="Lochbohrung in den Ecken" type="Radio" default="2">
|
||||||
|
<opt id="2" name="ohne Lochbohrung"/>
|
||||||
|
<opt id="1" name="mit Lochbohrung (+2,50 Euro/Stück)"/>
|
||||||
|
</option>
|
||||||
|
|
||||||
|
|
||||||
|
</artikel>
|
||||||
|
</kalkulation>
|
||||||
2
tests/Customer/N/calcTemplates.xml
Normal file
2
tests/Customer/N/calcTemplates.xml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<root>
|
||||||
|
</root>
|
||||||
0
tests/Customer/N/formels.txt
Normal file
0
tests/Customer/N/formels.txt
Normal file
4
tests/Customer/N/papierContainer.xml
Normal file
4
tests/Customer/N/papierContainer.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<container>
|
||||||
|
|
||||||
|
</container>
|
||||||
0
tests/Customer/N/parameters.txt
Normal file
0
tests/Customer/N/parameters.txt
Normal file
28
tests/PreCalc/ParseGroupTest.php
Normal file
28
tests/PreCalc/ParseGroupTest.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
namespace PSC\Library\Calc\Tests\PreCalc;
|
||||||
|
|
||||||
|
use PSC\Library\Calc\PreCalc\Group as PSCGroup;
|
||||||
|
use PSC\Library\Calc\PreCalc\Parser\Group;
|
||||||
|
|
||||||
|
class ParseGroupTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testIfCorrectType()
|
||||||
|
{
|
||||||
|
$parser = new Group(simplexml_load_string(file_get_contents(__DIR__ . '/../TestFiles/PreCalc/group.xml')));
|
||||||
|
|
||||||
|
$element = $parser->parse();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(PSCGroup::class, $element);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIfCountCorrect()
|
||||||
|
{
|
||||||
|
$parser = new Group(simplexml_load_string(file_get_contents(__DIR__ . '/../TestFiles/PreCalc/group.xml')));
|
||||||
|
|
||||||
|
$element = $parser->parse();
|
||||||
|
|
||||||
|
$this->assertSame(4, count($element->getVariants()));
|
||||||
|
$this->assertSame("ohne Lochbohrung", $element->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
28
tests/PreCalc/ParseTest.php
Normal file
28
tests/PreCalc/ParseTest.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
namespace PSC\Library\Calc\Tests\PreCalc;
|
||||||
|
|
||||||
|
use PSC\Library\Calc\PreCalc\Parser\PreCalc;
|
||||||
|
use PSC\Library\Calc\PreCalc\PreCalc as PSCPreCalc;
|
||||||
|
|
||||||
|
class ParseTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testIfCorrectType()
|
||||||
|
{
|
||||||
|
$parser = new PreCalc(simplexml_load_string(file_get_contents(__DIR__ . '/../TestFiles/PreCalc/precalc.xml')));
|
||||||
|
|
||||||
|
$element = $parser->parse();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(PSCPreCalc::class, $element);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIfCountIsCorrect()
|
||||||
|
{
|
||||||
|
$parser = new PreCalc(simplexml_load_string(file_get_contents(__DIR__ . '/../TestFiles/PreCalc/precalc.xml')));
|
||||||
|
|
||||||
|
$element = $parser->parse();
|
||||||
|
|
||||||
|
$this->assertSame(2, count($element->getGroups()));
|
||||||
|
$this->assertSame(4, count($element->getGroups()[0]->getVariants()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
27
tests/PreCalc/ParseVariantTest.php
Normal file
27
tests/PreCalc/ParseVariantTest.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
namespace PSC\Library\Calc\Tests\PreCalc;
|
||||||
|
|
||||||
|
use PSC\Library\Calc\PreCalc\Parser\Variant;
|
||||||
|
use PSC\Library\Calc\PreCalc\Variant as PSCVariant;
|
||||||
|
|
||||||
|
class ParseVariantTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testIfCorrectType()
|
||||||
|
{
|
||||||
|
$parser = new Variant(simplexml_load_string(file_get_contents(__DIR__ . '/../TestFiles/PreCalc/variant.xml')));
|
||||||
|
|
||||||
|
$element = $parser->parse();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(PSCVariant::class, $element);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIfNameIsCorrect()
|
||||||
|
{
|
||||||
|
$parser = new Variant(simplexml_load_string(file_get_contents(__DIR__ . '/../TestFiles/PreCalc/variant.xml')));
|
||||||
|
|
||||||
|
$element = $parser->parse();
|
||||||
|
|
||||||
|
$this->assertSame("100 stk", $element->getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
27
tests/PreCalc/ValueTest.php
Normal file
27
tests/PreCalc/ValueTest.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
namespace PSC\Library\Calc\Tests\PreCalc;
|
||||||
|
|
||||||
|
use PSC\Library\Calc\PreCalc\Parser\Value;
|
||||||
|
use PSC\Library\Calc\PreCalc\Value as PSCValue;
|
||||||
|
|
||||||
|
class ValueTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testIfCorrectType()
|
||||||
|
{
|
||||||
|
$parser = new Value(simplexml_load_string(file_get_contents(__DIR__ . '/../TestFiles/PreCalc/value.xml')));
|
||||||
|
|
||||||
|
$element = $parser->parse();
|
||||||
|
|
||||||
|
$this->assertInstanceOf(PSCValue::class, $element);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIfCorret()
|
||||||
|
{
|
||||||
|
$parser = new Value(simplexml_load_string(file_get_contents(__DIR__ . '/../TestFiles/PreCalc/value.xml')));
|
||||||
|
|
||||||
|
$element = $parser->parse();
|
||||||
|
$this->assertSame("auflage", $element->getKey());
|
||||||
|
$this->assertSame("100", $element->getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
19
tests/TestFiles/PreCalc/group.xml
Normal file
19
tests/TestFiles/PreCalc/group.xml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<group name="ohne Lochbohrung">
|
||||||
|
<calc name="100 stk">
|
||||||
|
<auflage>100</auflage>
|
||||||
|
<lochbohrung>2</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
<calc name="200 stk">
|
||||||
|
<auflage>200</auflage>
|
||||||
|
<lochbohrung>2</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
<calc name="300 stk">
|
||||||
|
<auflage>300</auflage>
|
||||||
|
<lochbohrung>2</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
<calc name="400 stk">
|
||||||
|
<auflage>400</auflage>
|
||||||
|
<lochbohrung>2</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
</group>
|
||||||
|
|
||||||
39
tests/TestFiles/PreCalc/precalc.xml
Normal file
39
tests/TestFiles/PreCalc/precalc.xml
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<precalc>
|
||||||
|
<group name="ohne Lochbohrung">
|
||||||
|
<calc name="100 stk">
|
||||||
|
<auflage>100</auflage>
|
||||||
|
<lochbohrung>2</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
<calc name="200 stk">
|
||||||
|
<auflage>200</auflage>
|
||||||
|
<lochbohrung>2</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
<calc name="300 stk">
|
||||||
|
<auflage>300</auflage>
|
||||||
|
<lochbohrung>2</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
<calc name="400 stk">
|
||||||
|
<auflage>400</auflage>
|
||||||
|
<lochbohrung>2</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
</group>
|
||||||
|
<group name="mit Lochbohrung">
|
||||||
|
<calc name="100 stk">
|
||||||
|
<auflage>100</auflage>
|
||||||
|
<lochbohrung>1</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
<calc name="200 stk">
|
||||||
|
<auflage>200</auflage>
|
||||||
|
<lochbohrung>1</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
<calc name="300 stk">
|
||||||
|
<auflage>300</auflage>
|
||||||
|
<lochbohrung>1</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
<calc name="400 stk">
|
||||||
|
<auflage>400</auflage>
|
||||||
|
<lochbohrung>1</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
</group>
|
||||||
|
</precalc>
|
||||||
|
|
||||||
1
tests/TestFiles/PreCalc/value.xml
Normal file
1
tests/TestFiles/PreCalc/value.xml
Normal file
@ -0,0 +1 @@
|
|||||||
|
<auflage>100</auflage>
|
||||||
5
tests/TestFiles/PreCalc/variant.xml
Normal file
5
tests/TestFiles/PreCalc/variant.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<calc name="100 stk">
|
||||||
|
<auflage>100</auflage>
|
||||||
|
<lochbohrung>2</lochbohrung>
|
||||||
|
</calc>
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user