Fixes
This commit is contained in:
parent
062a1a7297
commit
15b9fc24b0
@ -5,6 +5,7 @@ use Doctrine\Common\Persistence\ObjectRepository;
|
||||
use PSC\Library\Calc\Calc\Calc;
|
||||
use PSC\Library\Calc\Calc\Valid;
|
||||
use PSC\Library\Calc\Option\Type\Base;
|
||||
use PSC\Library\Calc\Option\Type\Select\Opt;
|
||||
use PSC\Library\Calc\Option\Type\Text;
|
||||
|
||||
class Engine
|
||||
@ -46,6 +47,9 @@ class Engine
|
||||
/** @var Article */
|
||||
protected $article = null;
|
||||
|
||||
/** @var string */
|
||||
protected $activeArticle = false;
|
||||
|
||||
|
||||
/**
|
||||
* Load XML From String
|
||||
@ -93,8 +97,15 @@ class Engine
|
||||
*/
|
||||
private function getArticleByName($name = false)
|
||||
{
|
||||
if($name === false) {
|
||||
if($name === false && $this->activeArticle === false) {
|
||||
$this->activeArticle = $this->articles[0]->getName();
|
||||
return $this->articles[0];
|
||||
|
||||
}
|
||||
|
||||
if($name === false && $this->activeArticle !== false) {
|
||||
$name = $this->activeArticle;
|
||||
|
||||
}
|
||||
|
||||
/** @var Article $article */
|
||||
@ -191,14 +202,11 @@ class Engine
|
||||
$this->variables = $variables;
|
||||
}
|
||||
|
||||
public function calc($name = false) {
|
||||
public function calc() {
|
||||
|
||||
$this->price = 0;
|
||||
if($name) {
|
||||
$this->article = $this->getArticleByName($name);
|
||||
}else{
|
||||
$this->article = $this->articles[0];
|
||||
}
|
||||
|
||||
$this->article = $this->getArticleByName($this->activeArticle);
|
||||
|
||||
// Prefill with defaults
|
||||
/** @var Base $option */
|
||||
@ -310,12 +318,36 @@ class Engine
|
||||
/**
|
||||
* @return Article
|
||||
*/
|
||||
public function getArticle($name = false)
|
||||
public function getArticle()
|
||||
{
|
||||
if($this->dirty || $this->article == null || ($name != false && $this->article->getName() != $name)) {
|
||||
$this->calc($name);
|
||||
if($this->dirty) {
|
||||
$this->calc();
|
||||
}
|
||||
return $this->article;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $activeArticle
|
||||
*/
|
||||
public function setActiveArticle($activeArticle)
|
||||
{
|
||||
$this->activeArticle = $activeArticle;
|
||||
$this->dirty = true;
|
||||
}
|
||||
|
||||
public function setSymfonyFormVariables($data)
|
||||
{
|
||||
$tmp = [];
|
||||
|
||||
foreach($data as $key => $value) {
|
||||
if($value instanceof Opt) {
|
||||
$tmp[$key] = $value->getId();
|
||||
}else{
|
||||
$tmp[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
}
|
||||
@ -27,7 +27,7 @@ class SimpleXmlTest extends \PHPUnit_Framework_TestCase
|
||||
$parser = new Engine(new Container());
|
||||
$parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/simple2articles.xml'));
|
||||
|
||||
$parser->calc("Blocks A5 25blatt geleimt");
|
||||
$parser->setActiveArticle("Blocks A5 25blatt geleimt");
|
||||
$article = $parser->getArticle();
|
||||
$this->assertInstanceOf('PSC\Library\Calc\Article', $article);
|
||||
$this->assertEquals('Blocks A5 25blatt geleimt', $article->getName());
|
||||
|
||||
@ -8,7 +8,7 @@ use PSC\Library\Calc\Engine;
|
||||
use PSC\Library\Calc\PaperContainer;
|
||||
use PSC\Library\Calc\Tests\Mock\PaperRepostory;
|
||||
|
||||
class selectWithGrenzenTest extends \PHPUnit_Framework_TestCase
|
||||
class papierDbWithFormelTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/** @var Engine */
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
namespace PSC\Library\Calc\Tests\Article;
|
||||
|
||||
use PSC\Library\Calc\Engine;
|
||||
use PSC\Library\Calc\PaperContainer\Container;
|
||||
|
||||
class Complete1Test extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var Engine */
|
||||
protected $engine = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->engine = new Engine(new Container());
|
||||
$this->engine->loadString(file_get_contents(__DIR__ . '/../TestFiles/SampleArticle/article1.xml'));
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->engine = null;
|
||||
}
|
||||
|
||||
public function testIfArticleCountIsCorrect()
|
||||
{
|
||||
$this->assertEquals(1, $this->engine->getArticles()->Count());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user