This commit is contained in:
Thomas Peterson 2025-06-11 09:25:03 +02:00
parent d10f3c3c95
commit df237473cb
21 changed files with 622 additions and 91 deletions

File diff suppressed because one or more lines are too long

View File

@ -2,6 +2,9 @@
namespace PSC\Library\Calc; namespace PSC\Library\Calc;
use ArrayIterator; use ArrayIterator;
use Column;
use PSC\Library\Calc\Option\Type\Base;
use PSC\Library\Calc\Option\Type\Row;
use PSC\Library\Calc\PreCalc\PreCalc; use PSC\Library\Calc\PreCalc\PreCalc;
class Article class Article
@ -93,23 +96,36 @@ class Article
$this->name = $name; $this->name = $name;
} }
public function getOptionById($id) public function getOptionById($id): ?Base
{ {
if($id === false) { if($id === false) {
throw new \Exception('No id provided'); throw new \Exception('No id provided');
} }
/** @var Option\Type\Base $option */ return $this->getOptionByIdRec($this->options, $id);
foreach($this->options as $option)
}
private function getOptionByIdRec($options, $id): ?Base
{
foreach($options as $option)
{ {
if($option instanceOf Row) {
foreach($option->getColumns() as $col) {
if($opt = $this->getOptionByIdRec($col->getOptions(), $id)) {
return $opt;
}
}
}
if($option instanceOf Column) {
return $this->getOptionByIdRec($option->getOptions(), $id);
}
if($option->getId() == $id) { if($option->getId() == $id) {
return $option; return $option;
} }
} }
if($id === false) { return null;
throw new \Exception('Option not found: ' . $id);
}
} }
public function getOptions() public function getOptions()

View File

@ -17,6 +17,7 @@ use PSC\Library\Calc\Option\Type\Base;
use PSC\Library\Calc\Option\Type\Checkbox; use PSC\Library\Calc\Option\Type\Checkbox;
use PSC\Library\Calc\Option\Type\PaperDbSelect; use PSC\Library\Calc\Option\Type\PaperDbSelect;
use PSC\Library\Calc\Option\Type\Radio; use PSC\Library\Calc\Option\Type\Radio;
use PSC\Library\Calc\Option\Type\Row;
use PSC\Library\Calc\Option\Type\Select; use PSC\Library\Calc\Option\Type\Select;
use PSC\Library\Calc\Tests\Mock\Paper; use PSC\Library\Calc\Tests\Mock\Paper;
@ -48,11 +49,18 @@ class Calc
public function calc() public function calc()
{ {
$gesamt = 0; return $this->calcRec(0, $this->article->getOptions());
}
/** @var Base $option */ private function calcRec($gesamt, $options)
foreach ($this->article->getOptions() as $option) { {
foreach ($options as $option) {
if ($option instanceof Row) {
foreach($option->getColumns() as $col) {
$price = $this->calcRec($gesamt, $col->getOptions());
}
}
if ($option instanceof Select || $option instanceof Checkbox || $option instanceof Radio) { if ($option instanceof Select || $option instanceof Checkbox || $option instanceof Radio) {
foreach($option->getSelectedOptions() as $opt) { foreach($option->getSelectedOptions() as $opt) {
if ($opt->isValid()) { if ($opt->isValid()) {

View File

@ -17,6 +17,7 @@ use PSC\Library\Calc\General\Type\EdgeCollectionContainer;
use PSC\Library\Calc\Option\Type\Base; use PSC\Library\Calc\Option\Type\Base;
use PSC\Library\Calc\Option\Type\Checkbox; use PSC\Library\Calc\Option\Type\Checkbox;
use PSC\Library\Calc\Option\Type\PaperDbSelect; use PSC\Library\Calc\Option\Type\PaperDbSelect;
use PSC\Library\Calc\Option\Type\Row;
use PSC\Library\Calc\Option\Type\Select; use PSC\Library\Calc\Option\Type\Select;
use PSC\Library\Calc\Tests\Mock\Paper; use PSC\Library\Calc\Tests\Mock\Paper;
use SebastianBergmann\CodeCoverage\Report\PHP; use SebastianBergmann\CodeCoverage\Report\PHP;
@ -47,13 +48,20 @@ class CalcValues
$this->formelCalc = new Formel($engine, $article); $this->formelCalc = new Formel($engine, $article);
} }
public function calc() public function calc(): float
{ {
$price = 0; return $this->calcRec(0, $this->article->getOptions());
}
/** @var Base $option */ private function calcRec($price = 0, $options): float
foreach ($this->article->getOptions() as $option) { {
foreach ($options as $option) {
if ($option instanceof Row) {
foreach($option->getColumns() as $col) {
$price = $this->calcRec($price, $col->getOptions());
}
}
if ($option instanceof Select || $option instanceof Checkbox) { if ($option instanceof Select || $option instanceof Checkbox) {
foreach($option->getSelectedOptions() as $opt) { foreach($option->getSelectedOptions() as $opt) {
if ($opt->isValid()) { if ($opt->isValid()) {
@ -66,14 +74,9 @@ class CalcValues
} }
return $price; return $price;
} }
/**
* @param $price
* @param id
* @param EdgeCollectionContainer $container
* @return int
*/
private function parseEdgeCollection($price, $id, EdgeCollectionContainer $container, $isSub = false) private function parseEdgeCollection($price, $id, EdgeCollectionContainer $container, $isSub = false)
{ {

View File

@ -11,8 +11,10 @@ use PSC\Library\Calc\General\Type\EdgeCollectionContainer;
use PSC\Library\Calc\Option\Type\Base; use PSC\Library\Calc\Option\Type\Base;
use PSC\Library\Calc\Option\Type\Checkbox; use PSC\Library\Calc\Option\Type\Checkbox;
use PSC\Library\Calc\Option\Type\Input; use PSC\Library\Calc\Option\Type\Input;
use PSC\Library\Calc\Option\Type\Row;
use PSC\Library\Calc\Option\Type\Select; use PSC\Library\Calc\Option\Type\Select;
use PSC\Library\Calc\Option\Type\ColorDBSelect; use PSC\Library\Calc\Option\Type\ColorDBSelect;
use PSC\Library\Calc\Option\Type\Select\ColorOpt;
class Valid class Valid
{ {
@ -33,14 +35,19 @@ class Valid
$this->formelCalc = new Formel($engine, $article); $this->formelCalc = new Formel($engine, $article);
} }
/** public function perform($withFormel = true): void
* @return void
*/
public function perform($withFormel = true)
{ {
$this->validRec($withFormel, $this->article->getOptions());
}
/** @var Base $option */ private function validRec($withFormel = true, \ArrayIterator $options): void
foreach($this->article->getOptions() as $option) { {
foreach($options as $option) {
if($option instanceof Row) {
foreach($option->getColumns() as $col) {
$this->validRec($withFormel, $col->getOptions());
}
}
if($option instanceof Input) { if($option instanceof Input) {
if($option->getMaxValue() && $option->getRawValue() > $option->getMaxValue()) { if($option->getMaxValue() && $option->getRawValue() > $option->getMaxValue()) {
$option->addValidationError(new Max(intval($option->getRawValue()), $option->getMaxValue())); $option->addValidationError(new Max(intval($option->getRawValue()), $option->getMaxValue()));
@ -116,10 +123,7 @@ class Valid
if($option instanceof Checkbox) { if($option instanceof Checkbox) {
if (isset($this->engine->getVariables()[$option->getId()]) && is_array($this->engine->getVariables()[$option->getId()]) && in_array($opt->getId(), $this->engine->getVariables()[$option->getId()])) { if (isset($this->engine->getVariables()[$option->getId()]) && is_array($this->engine->getVariables()[$option->getId()]) && in_array($opt->getId(), $this->engine->getVariables()[$option->getId()])) {
$option->addSelectedOption($opt); $option->addSelectedOption($opt);
} else {
//$opt->setIsSelected(false);
} }
}else { }else {
if (isset($this->engine->getVariables()[$option->getId()]) && $this->engine->getVariables()[$option->getId()] == $opt->getId()) { if (isset($this->engine->getVariables()[$option->getId()]) && $this->engine->getVariables()[$option->getId()] == $opt->getId()) {
if(!$opt->isValid()) { if(!$opt->isValid()) {
@ -133,10 +137,7 @@ class Valid
$this->engine->getVariables()[$option->getId()] = $opt->getId(); $this->engine->getVariables()[$option->getId()] = $opt->getId();
$option->addSelectedOption($opt); $option->addSelectedOption($opt);
$nextShouldBeValid = false; $nextShouldBeValid = false;
} else{
// $option->setSelectedOption(null);
} }
} }
} }
@ -159,9 +160,28 @@ class Valid
} }
if($option instanceof ColorDBSelect) {
if (isset($this->engine->getVariables()[$option->getId()])) {
$element = array_find((array)$option->getOptions(), function(ColorOpt $o1) use ($option) {
return $o1->getId() === $this->engine->getVariables()[$option->getId()];
});
if($element) {
$option->addSelectedOption($element);
}else{
$option->addSelectedOption($option->getOptions()[0]);
}
}elseif($option->getDefault() != null) {
$element = array_find((array)$option->getOptions(), function(ColorOpt $o1) use ($option) {
return $o1->getId() === $option->getDefault();
});
$option->addSelectedOption($element);
}else{
$option->addSelectedOption($option->getOptions()[0]);
}
}
$mainEdges = true; $mainEdges = true;
/** @var EdgeCollection $collection */
foreach($option->getEdgesCollectionContainer() as $collection) { foreach($option->getEdgesCollectionContainer() as $collection) {
/** @var Edge $edge */ /** @var Edge $edge */
$collValid = false; $collValid = false;
@ -184,14 +204,10 @@ class Valid
$this->engine->addCalcVariable($option->getId() . '_valid', (int)$option->isValid()); $this->engine->addCalcVariable($option->getId() . '_valid', (int)$option->isValid());
} }
} }
/** private function edgeIsValid(mixed $section, Edge $edge): bool
* @param $section
* @param Edge $edge
* @return bool
*/
private function edgeIsValid($section, $edge)
{ {
$valid = false; $valid = false;
$skipTests = false; $skipTests = false;
@ -232,12 +248,7 @@ class Valid
return $valid; return $valid;
} }
/** private function edgeIsValidWithValue(mixed $value, Edge $edge): bool
* @param $section
* @param Edge $edge
* @return bool
*/
private function edgeIsValidWithValue($value, $edge)
{ {
if($edge->isRegion() && if($edge->isRegion() &&
$edge->getFrom() <= $value && $edge->getFrom() <= $value &&

View File

@ -8,6 +8,7 @@ use PSC\Library\Calc\Calc\Valid;
use PSC\Library\Calc\Option\Type\Base; use PSC\Library\Calc\Option\Type\Base;
use PSC\Library\Calc\Option\Type\Checkbox; use PSC\Library\Calc\Option\Type\Checkbox;
use PSC\Library\Calc\Option\Type\PaperDbSelect; use PSC\Library\Calc\Option\Type\PaperDbSelect;
use PSC\Library\Calc\Option\Type\Row;
use PSC\Library\Calc\Option\Type\Select\Opt; use PSC\Library\Calc\Option\Type\Select\Opt;
use PSC\Library\Calc\Option\Type\Text; use PSC\Library\Calc\Option\Type\Text;
@ -270,23 +271,7 @@ class Engine
// Prefill with defaults // Prefill with defaults
/** @var Base $option */ /** @var Base $option */
foreach($this->article->getOptions() as $option) { $this->prefillVars($this->article->getOptions());
$option->setSavedCalcValues($this->savedCalcValues);
if(!isset($this->variables[$option->getId()]) && $option->getDefault() !== null && !$option instanceof Text) {
if($option instanceof Checkbox) {
$this->variables[$option->getId()] = explode(",", $option->getDefault());
}else{
$this->variables[$option->getId()] = $option->getDefault();
}
}
if(isset($this->variables[$option->getId()])) {
$option->setRawValue($this->variables[$option->getId()]);
$option->processValue();
}
}
$this->processCalc(); $this->processCalc();
$switchedOptions = $this->checkDoubleOptions(); $switchedOptions = $this->checkDoubleOptions();
@ -313,9 +298,33 @@ class Engine
return true; return true;
} }
/** public function prefillVars(\ArrayIterator $options): void
* @return mixed {
*/ foreach($options as $option) {
if($option instanceof Row) {
foreach($option->getColumns() as $column) {
$this->prefillVars($column->getOptions());
}
continue;
}
$option->setSavedCalcValues($this->savedCalcValues);
if(!isset($this->variables[$option->getId()]) && $option->getDefault() !== null && !$option instanceof Text) {
if($option instanceof Checkbox) {
$this->variables[$option->getId()] = explode(",", $option->getDefault());
}else{
$this->variables[$option->getId()] = $option->getDefault();
}
}
if(isset($this->variables[$option->getId()])) {
$option->setRawValue($this->variables[$option->getId()]);
$option->processValue();
}
}
}
public function getPrice() public function getPrice()
{ {
if($this->dirty) { if($this->dirty) {

View File

@ -2,6 +2,7 @@
namespace PSC\Library\Calc\Option; namespace PSC\Library\Calc\Option;
use PSC\Library\Calc\Option\Parser\Checkbox; use PSC\Library\Calc\Option\Parser\Checkbox;
use PSC\Library\Calc\Option\Parser\Headline;
use PSC\Library\Calc\Option\Parser\Hidden; use PSC\Library\Calc\Option\Parser\Hidden;
use PSC\Library\Calc\Option\Parser\Input; use PSC\Library\Calc\Option\Parser\Input;
use PSC\Library\Calc\Option\Parser\Radio; use PSC\Library\Calc\Option\Parser\Radio;
@ -9,7 +10,6 @@ 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\Option\Parser\Text; use PSC\Library\Calc\Option\Parser\Text;
use PSC\Library\Calc\Option\Parser\Textarea; use PSC\Library\Calc\Option\Parser\Textarea;
use PSC\Library\Calc\PaperContainer\Container;
class Parser class Parser
{ {
@ -24,7 +24,6 @@ class Parser
$this->node = $node; $this->node = $node;
$obj = false; $obj = false;
switch(strtolower((string)$node['type'])) { switch(strtolower((string)$node['type'])) {
case 'input': case 'input':
$obj = new Input($node); $obj = new Input($node);
@ -38,6 +37,9 @@ class Parser
case 'checkbox': case 'checkbox':
$obj = new Checkbox($node); $obj = new Checkbox($node);
break; break;
case 'headline':
$obj = new Headline($node);
break;
case 'text': case 'text':
$obj = new Text($node); $obj = new Text($node);
break; break;

View File

@ -0,0 +1,42 @@
<?php
namespace PSC\Library\Calc\Option\Parser;
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
class Headline extends Base
{
protected $element;
public function __construct(\SimpleXMLElement $node)
{
$this->element = new \PSC\Library\Calc\Option\Type\Headline();
parent::__construct($node);
}
public function parse()
{
parent::parse();
if($this->node->data) {
$this->element->setValue((string)$this->node->data);
}
if($this->node['variant']) {
$this->element->setVariant((int)$this->node['variant']);
}
if($this->element->getDefault() != null) {
$this->element->setValue($this->element->getDefault());
}
if($this->node->children()) {
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node);
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());
}
return $this->element;
}
}

33
src/Option/Parser/Row.php Normal file
View File

@ -0,0 +1,33 @@
<?php
namespace PSC\Library\Calc\Option\Parser;
use PSC\Library\Calc\General\Parser\EdgeCollectionContainer;
use PSC\Library\Calc\Option\Parser\Row\Column;
use PSC\Library\Calc\Option\Parser\Base;
use PSC\Library\Calc\Option\Type\Base as PSCBase;
class Row extends Base
{
protected $element;
public function __construct(\SimpleXMLElement $node, private $paperContainer, private $paperRepository, private $templates)
{
$this->element = new \PSC\Library\Calc\Option\Type\Row();
parent::__construct($node);
}
public function parse(): PSCBase
{
parent::parse();
foreach($this->node->children() as $key => $node) {
$p = new Column($node, $this->paperContainer, $this->paperRepository, $this->templates);
$element = $p->parse();
$this->element->addColumn($element);
}
return $this->element;
}
}

View File

@ -0,0 +1,61 @@
<?php
namespace PSC\Library\Calc\Option\Parser\Row;
use PSC\Library\Calc\Option\Parser;
use PSC\Library\Calc\Option\Parser\Base;
use PSC\Library\Calc\Option\Parser\Row;
use PSC\Library\Calc\Option\Type\Select;
use PSC\Library\Calc\Option\Type\Template;
class Column extends Base
{
private Parser $optionParser;
public function __construct(\SimpleXMLElement $node, private $paperContainer, private $paperRepository, private $templates)
{
$this->element = new \PSC\Library\Calc\Option\Type\Row\Column();
$this->node = $node;
$this->optionParser = new \PSC\Library\Calc\Option\Parser($paperContainer, $paperRepository, $templates);
}
public function parse()
{
parent::parse();
foreach ($this->node->children() as $key => $option) {
if($key == 'option') {
$obj = $this->optionParser->getOptByType($option);
if($obj) {
if($obj instanceof Select) {
$obj->setPaperContainer($this->paperContainer);
$obj->setPaperRepository($this->paperRepository);
}
if($obj instanceof Template) {
$element = $obj->parse();
$default = $element->getDefault();
$node = $this->templates->xpath('//option[@id="' . $element->getSelect() . '"]');
$obj = $this->optionParser->getOptByType($node[0]);
$element = $obj->parse();
if($default != "") {
$element->setDefault($default);
}
}else{
$element = $obj->parse();
}
$this->element->addOption($element);
}
}elseif($key == 'row') {
$obj = new Row($option, $this->paperContainer, $this->paperRepository, $this->templates);
$element = $obj->parse();
$this->element->addOption($element);
}
}
return $this->element;
}
}

View File

@ -18,6 +18,14 @@ class Text extends Base
{ {
parent::parse(); parent::parse();
if($this->node->data) {
$this->element->setValue((string)$this->node->data);
}
if($this->element->getDefault() != null) {
$this->element->setValue($this->element->getDefault());
}
if($this->node->children()) { if($this->node->children()) {
$edgeCollectionContainerParser = new EdgeCollectionContainer($this->node); $edgeCollectionContainerParser = new EdgeCollectionContainer($this->node);
$this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parse()); $this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parse());

View File

@ -0,0 +1,17 @@
<?php
namespace PSC\Library\Calc\Option\Type;
class Headline extends Base
{
private int $variant = 1;
public $type = 'headline';
public function setVariant(int $variant):void {
$this->variant = $variant;
}
public function getVariant():int {
return $this->variant;
}
}

34
src/Option/Type/Row.php Normal file
View File

@ -0,0 +1,34 @@
<?php
namespace PSC\Library\Calc\Option\Type;
use PSC\Library\Calc\Option\Type\Row\Column;
class Row extends Base
{
private \ArrayIterator $columns;
public $type = 'row';
public function __construct()
{
parent::__construct();
$this->columns = new \ArrayIterator();
}
public function addColumn(Column $column): void
{
$this->columns->append($column);
}
public function getColumns(): \ArrayIterator
{
return $this->columns;
}
public function getColumnById(string $id): ?Column
{
return array_find((array)$this->columns, function(Column $c) use ($id) {
return $c->getId() == $id;
});
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace PSC\Library\Calc\Option\Type\Row;
use PSC\Library\Calc\Option\Type\Base;
class Column extends Base
{
private \ArrayIterator $options;
public function __construct()
{
parent::__construct();
$this->options = new \ArrayIterator();
}
public function addOption(Base $option):void
{
$this->options->append($option);
}
public function getOptions(): \ArrayIterator
{
return $this->options;
}
public function getOptionById(string $id): ?Base
{
return array_find((array)$this->options, function(Base $c) use ($id) {
return $c->getId() == $id;
});
}
}

View File

@ -3,13 +3,14 @@ namespace PSC\Library\Calc;
use Doctrine\Persistence\ObjectRepository; use Doctrine\Persistence\ObjectRepository;
use PSC\Library\Calc\Option\Parser\Row;
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; use PSC\Library\Calc\PreCalc\Parser\PreCalc;
class Parser class Parser
{ {
protected $article; protected Article $article;
/** @var PaperContainer */ /** @var PaperContainer */
protected $paperContainer; protected $paperContainer;
@ -24,9 +25,9 @@ class Parser
{ {
} }
public function parse(\SimpleXMLElement $node) public function parse(\SimpleXMLElement $node): Article
{ {
$optionParser = new \PSC\Library\Calc\Option\Parser(); $optionParser = new \PSC\Library\Calc\Option\Parser($this->paperContainer, $this->paperRepository, $this->templates);
$this->article = new Article((string)$node->name); $this->article = new Article((string)$node->name);
@ -53,27 +54,33 @@ class Parser
} }
} }
foreach ($node->option as $option) { foreach ($node->children() as $key => $option) {
$obj = $optionParser->getOptByType($option); if($key == 'option') {
if($obj) { $obj = $optionParser->getOptByType($option);
if($obj) {
if($obj instanceof Select) { if($obj instanceof Select) {
$obj->setPaperContainer($this->getPaperContainer()); $obj->setPaperContainer($this->getPaperContainer());
$obj->setPaperRepository($this->getPaperRepository()); $obj->setPaperRepository($this->getPaperRepository());
}
if($obj instanceof Template) {
$element = $obj->parse();
$default = $element->getDefault();
$node = $this->templates->xpath('//option[@id="' . $element->getSelect() . '"]');
$obj = $optionParser->getOptByType($node[0]);
$element = $obj->parse();
if($default != "") {
$element->setDefault($default);
} }
}else{ if($obj instanceof Template) {
$element = $obj->parse(); $element = $obj->parse();
$default = $element->getDefault();
$node = $this->templates->xpath('//option[@id="' . $element->getSelect() . '"]');
$obj = $optionParser->getOptByType($node[0]);
$element = $obj->parse();
if($default != "") {
$element->setDefault($default);
}
}else{
$element = $obj->parse();
}
$this->article->addOption($element);
} }
}elseif($key == 'row') {
$obj = new Row($option, $this->paperContainer, $this->paperRepository, $this->templates);
$element = $obj->parse();
$this->article->addOption($element); $this->article->addOption($element);
} }
} }

View File

@ -0,0 +1,65 @@
<?php
namespace PSC\Library\Calc\Tests\CMS\Type\Container;
use PHPUnit\Framework\TestCase;
use PSC\Library\Calc\Engine;
use PSC\Library\Calc\Option\Type\Input;
use PSC\Library\Calc\Option\Type\Row;
use PSC\Library\Calc\Option\Type\Text;
use PSC\Library\Calc\PaperContainer\Container;
class ColumnTest extends TestCase
{
/** @var Engine */
protected $engine = null;
public function setUp(): void
{
$this->engine = new Engine(new Container());
$this->engine->loadString(file_get_contents(__DIR__ . '/cms1.xml'));
}
public function tearDown(): void
{
$this->engine = null;
}
public function tesRowColumn()
{
$row1 = $this->engine->getArticle()->getOptionById('row1');
$col2 = $this->engine->getArticle()->getOptionById('row1')->getColumnById('col2');
self::assertInstanceOf(Row::class, $row1);
self::assertCount(2, $row1->getColumns());
self::assertCount(4, $col2->getOptions());
}
public function tesTextOption()
{
$textOption = $this->engine->getArticle()->getOptionById('text3');
self::assertInstanceOf(Text::class, $textOption);
self::assertSame('Text3', $textOption->getValue());
}
public function testInputOption()
{
$inputOption = $this->engine->getArticle()->getOptionById('auflage');
$inputOption1 = $this->engine->getArticle()->getOptionById('auflage1');
self::assertFalse($inputOption->isValid());
self::assertInstanceOf(Input::class, $inputOption);
self::assertInstanceOf(Input::class, $inputOption1);
self::assertSame('100', $inputOption1->getValue());
self::assertSame('100', $inputOption->getValue());
}
public function testSubRowsOption()
{
$inputOption = $this->engine->getArticle()->getOptionById('auflage31');
$inputOption1 = $this->engine->getArticle()->getOptionById('auflage33');
self::assertFalse($inputOption->isValid());
self::assertTrue($inputOption1->isValid());
self::assertInstanceOf(Input::class, $inputOption);
self::assertInstanceOf(Input::class, $inputOption1);
self::assertSame('1500', $inputOption1->getValue());
self::assertSame('100', $inputOption->getValue());
}
}

View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<row>
<option id="auflage1" type="Input" default="100"/>
<row id="row1">
<column id="col1">
<option id="text3" type="Text" default="Text3">
</option>
<option id="text4" type="Text" default="Text4">
</option>
</column>
<column id="col2">
<option id="text5" type="Text" default="Text6">
</option>
<option id="text6" type="Text" default="Text6">
</option>
<option id="auflage" type="Input" default="100">
<auflage1>
<grenze>200-</grenze>
</auflage1>
</option>
<option id="papier" type="Select" mode="paperdb"/>
</column>
</row>
<row id="row2">
<column id="col3">
<row id="row21">
<column id="col31">
<option id="auflage31" type="Input" default="100">
<auflage1>
<grenze>200-</grenze>
</auflage1>
</option>
<option id="auflage32" type="Input" default="200">
<auflage1>
<grenze>1-</grenze>
</auflage1>
</option>
</column>
<column id="col32">
<option id="text10" type="Text" default="Text10">
</option>
<option id="auflage33" type="Input" default="1500">
<auflage1>
<grenze>1-</grenze>
</auflage1>
</option>
</column>
</row>
<option id="text7" type="Text" default="Text7">
</option>
</column>
<column id="col4">
<option id="text8" type="Text" default="Text8">
</option>
<option id="text9" type="Text" default="Text9">
</option>
<option id="auflage" type="Input" default="100">
<auflage1>
<grenze>200-</grenze>
</auflage1>
</option>
</column>
</row>
<option id="text1" type="Text">
<data><![CDATA[Text1]]></data>
</option>
<option id="text2" type="Text" default="Text2">
</option>
</row>
</root>

View File

@ -0,0 +1,41 @@
<?php
namespace PSC\Library\Calc\Tests\CMS\Type\Text;
use PHPUnit\Framework\TestCase;
use PSC\Library\Calc\Engine;
use PSC\Library\Calc\Option\Type\Headline;
use PSC\Library\Calc\PaperContainer\Container;
class HeadlineTest extends TestCase
{
/** @var Engine */
protected $engine = null;
public function setUp(): void
{
$this->engine = new Engine(new Container());
$this->engine->loadString(file_get_contents(__DIR__ . '/headline.xml'));
}
public function tearDown(): void
{
$this->engine = null;
}
public function testHeadLine1Option()
{
$headlineOption = $this->engine->getArticle()->getOptionById('headline1');
self::assertInstanceOf(Headline::class, $headlineOption);
self::assertSame('Headline 1', $headlineOption->getValue());
self::assertSame(1, $headlineOption->getVariant());
}
public function testHeadLine5Option()
{
$headlineOption = $this->engine->getArticle()->getOptionById('headline5');
self::assertInstanceOf(Headline::class, $headlineOption);
self::assertSame('Headline 5', $headlineOption->getValue());
self::assertSame(5, $headlineOption->getVariant());
}
}

View File

@ -0,0 +1,38 @@
<?php
namespace PSC\Library\Calc\Tests\CMS\Type\Text;
use PHPUnit\Framework\TestCase;
use PSC\Library\Calc\Engine;
use PSC\Library\Calc\Option\Type\Text;
use PSC\Library\Calc\PaperContainer\Container;
class TextTest extends TestCase
{
/** @var Engine */
protected $engine = null;
public function setUp(): void
{
$this->engine = new Engine(new Container());
$this->engine->loadString(file_get_contents(__DIR__ . '/cms1.xml'));
}
public function tearDown(): void
{
$this->engine = null;
}
public function testTextOption()
{
$textOption = $this->engine->getArticle()->getOptionById('text1');
self::assertInstanceOf(Text::class, $textOption);
self::assertSame('Text1', $textOption->getValue());
}
public function testText2Option()
{
$textOption = $this->engine->getArticle()->getOptionById('text2');
self::assertInstanceOf(Text::class, $textOption);
self::assertSame('Text2', $textOption->getValue());
}
}

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<row>
<option id="text1" type="Text">
<data><![CDATA[Text1]]></data>
</option>
<option id="text2" type="Text" default="Text2">
</option>
</row>
</root>

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<row>
<option id="headline1" type="Headline" variant="1">
<data><![CDATA[Headline 1]]></data>
</option>
<option id="headline2" type="Headline" variant="2">
<data><![CDATA[Headline 2]]></data>
</option>
<option id="headline3" type="Headline" variant="3">
<data><![CDATA[Headline 3]]></data>
</option>
<option id="headline4" type="Headline" variant="4">
<data><![CDATA[Headline 4]]></data>
</option>
<option id="headline5" type="Headline" variant="5">
<data><![CDATA[Headline 5]]></data>
</option>
</row>
</root>