From 947c93bf1b2fa485e754bc448ec10296699b02f3 Mon Sep 17 00:00:00 2001 From: Thomas Peterson Date: Sat, 30 Jan 2016 00:52:15 +0100 Subject: [PATCH] Add PaperDB --- composer.json | 3 +- composer.lock | 671 +++++++++- src/Article.php | 8 +- src/Engine.php | 42 + src/Option/Parser.php | 15 +- src/Option/Parser/Base.php | 27 +- src/Option/Parser/Input.php | 12 +- src/Option/Parser/Select.php | 85 +- src/Option/Parser/Select/Opt.php | 15 +- src/Option/Type/Select.php | 54 +- src/Option/Type/Select/Opt.php | 41 +- src/PaperContainer.php | 51 + src/PaperContainer/Container.php | 48 + src/PaperContainer/Item.php | 26 + src/Parser.php | 57 +- tests/Article/CalendarXmlTest.php | 48 + tests/Article/SimpleXmlTest.php | 7 +- tests/General/LoadTest.php | 1 + tests/Mock/Paper.php | 1096 +++++++++++++++++ tests/Mock/PaperRepostory.php | 117 ++ tests/Option/Type/InputTest.php | 27 +- tests/Option/Type/SelectTest.php | 72 +- tests/TestFiles/General/calendar.xml | 2 +- .../Option/Select/papierContainer.xml | 20 + .../TestFiles/Option/Select/selectPaperDB.xml | 6 + 25 files changed, 2470 insertions(+), 81 deletions(-) create mode 100644 src/PaperContainer.php create mode 100644 src/PaperContainer/Container.php create mode 100644 src/PaperContainer/Item.php create mode 100644 tests/Mock/Paper.php create mode 100644 tests/Mock/PaperRepostory.php create mode 100644 tests/TestFiles/Option/Select/papierContainer.xml create mode 100644 tests/TestFiles/Option/Select/selectPaperDB.xml diff --git a/composer.json b/composer.json index b6cbe10..b20fca9 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ } }, "require": { - "php": ">=5.4" + "php": ">=5.4", + "doctrine/orm": "^2.5" }, "require-dev": { "phpunit/phpunit": "^4.7" diff --git a/composer.lock b/composer.lock index 0c4ca7c..7803680 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,423 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "b9da4001e3942b87f110cd4dfebcb541", - "packages": [], - "packages-dev": [ + "hash": "c7aedb4a025e243da1c87dfd496221ac", + "packages": [ + { + "name": "doctrine/annotations", + "version": "v1.2.7", + "source": { + "type": "git", + "url": "https://github.com/doctrine/annotations.git", + "reference": "f25c8aab83e0c3e976fd7d19875f198ccf2f7535" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/f25c8aab83e0c3e976fd7d19875f198ccf2f7535", + "reference": "f25c8aab83e0c3e976fd7d19875f198ccf2f7535", + "shasum": "" + }, + "require": { + "doctrine/lexer": "1.*", + "php": ">=5.3.2" + }, + "require-dev": { + "doctrine/cache": "1.*", + "phpunit/phpunit": "4.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Annotations\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Docblock Annotations Parser", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "docblock", + "parser" + ], + "time": "2015-08-31 12:32:49" + }, + { + "name": "doctrine/cache", + "version": "v1.6.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/cache.git", + "reference": "f8af318d14bdb0eff0336795b428b547bd39ccb6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/cache/zipball/f8af318d14bdb0eff0336795b428b547bd39ccb6", + "reference": "f8af318d14bdb0eff0336795b428b547bd39ccb6", + "shasum": "" + }, + "require": { + "php": "~5.5|~7.0" + }, + "conflict": { + "doctrine/common": ">2.2,<2.4" + }, + "require-dev": { + "phpunit/phpunit": "~4.8|~5.0", + "predis/predis": "~1.0", + "satooshi/php-coveralls": "~0.6" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Caching library offering an object-oriented API for many cache backends", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "cache", + "caching" + ], + "time": "2015-12-31 16:37:02" + }, + { + "name": "doctrine/collections", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/collections.git", + "reference": "6c1e4eef75f310ea1b3e30945e9f06e652128b8a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/collections/zipball/6c1e4eef75f310ea1b3e30945e9f06e652128b8a", + "reference": "6c1e4eef75f310ea1b3e30945e9f06e652128b8a", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Collections\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Collections Abstraction library", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "array", + "collections", + "iterator" + ], + "time": "2015-04-14 22:21:58" + }, + { + "name": "doctrine/common", + "version": "v2.6.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/common.git", + "reference": "a579557bc689580c19fee4e27487a67fe60defc0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/common/zipball/a579557bc689580c19fee4e27487a67fe60defc0", + "reference": "a579557bc689580c19fee4e27487a67fe60defc0", + "shasum": "" + }, + "require": { + "doctrine/annotations": "1.*", + "doctrine/cache": "1.*", + "doctrine/collections": "1.*", + "doctrine/inflector": "1.*", + "doctrine/lexer": "1.*", + "php": "~5.5|~7.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.8|~5.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\": "lib/Doctrine/Common" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common Library for Doctrine projects", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "collections", + "eventmanager", + "persistence", + "spl" + ], + "time": "2015-12-25 13:18:31" + }, + { + "name": "doctrine/dbal", + "version": "v2.5.4", + "source": { + "type": "git", + "url": "https://github.com/doctrine/dbal.git", + "reference": "abbdfd1cff43a7b99d027af3be709bc8fc7d4769" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/abbdfd1cff43a7b99d027af3be709bc8fc7d4769", + "reference": "abbdfd1cff43a7b99d027af3be709bc8fc7d4769", + "shasum": "" + }, + "require": { + "doctrine/common": ">=2.4,<2.7-dev", + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "4.*", + "symfony/console": "2.*" + }, + "suggest": { + "symfony/console": "For helpful console commands such as SQL execution and import of files." + }, + "bin": [ + "bin/doctrine-dbal" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.5.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\DBAL\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Database Abstraction Layer", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database", + "dbal", + "persistence", + "queryobject" + ], + "time": "2016-01-05 22:11:12" + }, + { + "name": "doctrine/inflector", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/inflector.git", + "reference": "90b2128806bfde671b6952ab8bea493942c1fdae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/90b2128806bfde671b6952ab8bea493942c1fdae", + "reference": "90b2128806bfde671b6952ab8bea493942c1fdae", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "4.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Inflector\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Common String Manipulations with regard to casing and singular/plural rules.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "inflection", + "pluralize", + "singularize", + "string" + ], + "time": "2015-11-06 14:35:42" + }, { "name": "doctrine/instantiator", "version": "1.0.5", @@ -61,6 +475,257 @@ ], "time": "2015-06-14 21:17:01" }, + { + "name": "doctrine/lexer", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Common\\Lexer\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "lexer", + "parser" + ], + "time": "2014-09-09 13:34:57" + }, + { + "name": "doctrine/orm", + "version": "v2.5.4", + "source": { + "type": "git", + "url": "https://github.com/doctrine/doctrine2.git", + "reference": "bc4ddbfb0114cb33438cc811c9a740d8aa304aab" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/doctrine2/zipball/bc4ddbfb0114cb33438cc811c9a740d8aa304aab", + "reference": "bc4ddbfb0114cb33438cc811c9a740d8aa304aab", + "shasum": "" + }, + "require": { + "doctrine/cache": "~1.4", + "doctrine/collections": "~1.2", + "doctrine/common": ">=2.5-dev,<2.7-dev", + "doctrine/dbal": ">=2.5-dev,<2.6-dev", + "doctrine/instantiator": "~1.0.1", + "ext-pdo": "*", + "php": ">=5.4", + "symfony/console": "~2.5|~3.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0", + "symfony/yaml": "~2.3|~3.0" + }, + "suggest": { + "symfony/yaml": "If you want to use YAML Metadata Mapping Driver" + }, + "bin": [ + "bin/doctrine", + "bin/doctrine.php" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.6.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\ORM\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Object-Relational-Mapper for PHP", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "database", + "orm" + ], + "time": "2016-01-05 21:34:58" + }, + { + "name": "symfony/console", + "version": "v3.0.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "ebcdc507829df915f4ca23067bd59ee4ef61f6c3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/ebcdc507829df915f4ca23067bd59ee4ef61f6c3", + "reference": "ebcdc507829df915f4ca23067bd59ee4ef61f6c3", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/polyfill-mbstring": "~1.0" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/event-dispatcher": "~2.8|~3.0", + "symfony/process": "~2.8|~3.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "time": "2015-12-22 10:39:06" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "1289d16209491b584839022f29257ad859b8532d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/1289d16209491b584839022f29257ad859b8532d", + "reference": "1289d16209491b584839022f29257ad859b8532d", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2016-01-20 09:13:37" + } + ], + "packages-dev": [ { "name": "phpdocumentor/reflection-docblock", "version": "2.0.4", diff --git a/src/Article.php b/src/Article.php index 15a3583..4b3c48d 100644 --- a/src/Article.php +++ b/src/Article.php @@ -57,11 +57,11 @@ class Article throw new \Exception('No id provided'); } - /** @var Option\Type\Base $options */ - foreach($this->options as $options) + /** @var Option\Type\Base $option */ + foreach($this->options as $option) { - if($options->getId() == $id) { - return $options; + if($option->getId() == $id) { + return $option; } } diff --git a/src/Engine.php b/src/Engine.php index a3f89c4..f40ee3a 100644 --- a/src/Engine.php +++ b/src/Engine.php @@ -2,6 +2,9 @@ namespace PSC\Library\Calc; + +use Doctrine\Common\Persistence\ObjectRepository; + class Engine { @@ -11,6 +14,11 @@ class Engine /** @var \ArrayIterator $articles */ protected $articles; + /** @var PaperContainer $paperContainer */ + protected $paperContainer; + + /** @var ObjectRepository */ + protected $paperRepository; /** * Load XML From String @@ -33,6 +41,8 @@ class Engine protected function parse() { $parser = new Parser(); + $parser->setPaperContainer($this->paperContainer); + $parser->setPaperRepository($this->paperRepository); foreach ($this->xml as $article) { $this->articles->append($parser->parse($article)); @@ -72,4 +82,36 @@ class Engine } } + /** + * @return PaperContainer + */ + public function getPaperContainer() + { + return $this->paperContainer; + } + + /** + * @param PaperContainer $paperContainer + */ + public function setPaperContainer($paperContainer) + { + $this->paperContainer = $paperContainer; + } + + /** + * @return ObjectRepository + */ + public function getPaperRepository() + { + return $this->paperRepository; + } + + /** + * @param ObjectRepository $paperRepository + */ + public function setPaperRepository($paperRepository) + { + $this->paperRepository = $paperRepository; + } + } \ No newline at end of file diff --git a/src/Option/Parser.php b/src/Option/Parser.php index cafda1b..89f7cd2 100644 --- a/src/Option/Parser.php +++ b/src/Option/Parser.php @@ -3,12 +3,17 @@ namespace PSC\Library\Calc\Option; use PSC\Library\Calc\Option\Parser\Input; use PSC\Library\Calc\Option\Parser\Select; +use PSC\Library\Calc\PaperContainer\Container; class Parser { protected $node; - public function parse(\SimpleXMLElement $node) + public function __construct() + { + } + + public function getOptByType(\SimpleXMLElement $node) { $this->node = $node; @@ -16,17 +21,13 @@ class Parser switch(strtolower((string)$node['type'])) { case 'input': - $obj = new Input(); + $obj = new Input($node); break; case 'select': - $obj = new Select(); + $obj = new Select($node); break; } - if($obj) { - $obj = $obj->parse($node); - } - return $obj; } diff --git a/src/Option/Parser/Base.php b/src/Option/Parser/Base.php index 20ca2a7..385092f 100644 --- a/src/Option/Parser/Base.php +++ b/src/Option/Parser/Base.php @@ -9,25 +9,24 @@ class Base /** @var \SimpleXMLElement $node */ protected $node; - public function __construct() - { - - } - - protected function parse(\SimpleXMLElement $node) + public function __construct(\SimpleXMLElement $node) { $this->node = $node; - $this->element->setId((string)$node['id']); - $this->element->setName((string)$node['name']); + } - if(isset($node['default'])) { - $this->element->setDefault((string)$node['default']); + protected function parse() + { + $this->element->setId((string)$this->node['id']); + $this->element->setName((string)$this->node['name']); + + if(isset($this->node['default'])) { + $this->element->setDefault((string)$this->node['default']); } - if(isset($node['require'])) { - $this->element->setRequire($this->getBoolean($node['require'])); + if(isset($this->node['require'])) { + $this->element->setRequire($this->getBoolean($this->node['require'])); } - if(isset($node['help'])) { - $this->element->setHelp((string)$node['help']); + if(isset($this->node['help'])) { + $this->element->setHelp((string)$this->node['help']); } } diff --git a/src/Option/Parser/Input.php b/src/Option/Parser/Input.php index 9b6ed93..2c1a5c2 100644 --- a/src/Option/Parser/Input.php +++ b/src/Option/Parser/Input.php @@ -6,15 +6,15 @@ class Input extends Base protected $element; - public function __construct() - { - } - - public function parse(\SimpleXMLElement $node) + public function __construct(\SimpleXMLElement $node) { $this->element = new \PSC\Library\Calc\Option\Type\Input(); + parent::__construct($node); + } - parent::parse($node); + public function parse() + { + parent::parse(); return $this->element; } diff --git a/src/Option/Parser/Select.php b/src/Option/Parser/Select.php index edf5f3a..977627f 100644 --- a/src/Option/Parser/Select.php +++ b/src/Option/Parser/Select.php @@ -1,7 +1,10 @@ element = new \PSC\Library\Calc\Option\Type\Select(); + parent::__construct($node); + } - parent::parse($node); + public function parse() + { + parent::parse(); - $optParser = new Opt(); - - foreach ($this->node->opt as $opt) { - - $this->element->addOption($optParser->parse($opt)); + if(isset($this->node['mode']) && (string)$this->node['mode'] == \PSC\Library\Calc\Option\Type\Select::$modePaperDb) { + $this->parseModePapierDb(); + }else{ + $this->parseModeNormal(); } return $this->element; } + private function parseModePapierDb() + { + /** @var PaperContainer\Container $container */ + $container = $this->getPaperContainer()->getContainerById((string)$this->node['container']); + + /** @var PaperContainer\Item $papier */ + foreach ($container->getItems() as $papier) { + /** @var Paper $papierDb */ + $papierDb = $this->getPaperRepository()->findOneBy(array('artNr' => $papier->getId())); + if($papierDb) { + $optPapier = new \PSC\Library\Calc\Option\Type\Select\Opt(); + $optPapier->setId($papierDb->getArtNr()); + $optPapier->setLabel($papierDb->getDescription1()); + $this->element->addOption($optPapier); + } + } + } + + private function parseModeNormal() + { + foreach ($this->node->opt as $opt) { + $optParser = new Opt($opt); + $this->element->addOption($optParser->parse()); + } + } + + /** + * @return PaperContainer + */ + public function getPaperContainer() + { + return $this->paperContainer; + } + + /** + * @param PaperContainer $paperContainer + */ + public function setPaperContainer($paperContainer) + { + $this->paperContainer = $paperContainer; + } + + /** + * @param ObjectRepository $repostory + */ + public function setPaperRepository($repository) + { + $this->paperRepository = $repository; + } + + /** + * @return ObjectRepository + */ + public function getPaperRepository() + { + return $this->paperRepository; + } + } \ No newline at end of file diff --git a/src/Option/Parser/Select/Opt.php b/src/Option/Parser/Select/Opt.php index bc6cb31..88896ba 100644 --- a/src/Option/Parser/Select/Opt.php +++ b/src/Option/Parser/Select/Opt.php @@ -3,20 +3,21 @@ namespace PSC\Library\Calc\Option\Parser\Select; use PSC\Library\Calc\Option\Parser\Base; -class Opt extends Base +class Opt { protected $element; - public function __construct() - { - } - - public function parse(\SimpleXMLElement $node) + public function __construct(\SimpleXMLElement $node) { $this->element = new \PSC\Library\Calc\Option\Type\Select\Opt(); + $this->node = $node; + } - parent::parse($node); + public function parse() + { + $this->element->setId((string)$this->node['id']); + $this->element->setLabel((string)$this->node['name']); return $this->element; } diff --git a/src/Option/Type/Select.php b/src/Option/Type/Select.php index 8128f8d..1cc82ed 100644 --- a/src/Option/Type/Select.php +++ b/src/Option/Type/Select.php @@ -6,10 +6,20 @@ use PSC\Library\Calc\Option\Type\Select\Opt; class Select extends Base { + static public $modePaperDb = 'papierdb'; + + static public $modeNone = ''; + + static public $type = 'select'; + /** @var \ArrayIterator $options */ protected $options; - static public $type = 'select'; + /** @var String $container */ + protected $container = ''; + + /** @var String $mode */ + protected $mode = ''; public function __construct() { @@ -31,9 +41,49 @@ class Select extends Base foreach($this->options as $opt) { if($opt->getId() == $this->getRawValue()) { - $this->setValue($opt->getName()); + $this->setValue($opt->getLabel()); } } } + /** + * @return String + */ + public function getMode() + { + return $this->mode; + } + + /** + * @param String $mode + */ + public function setMode($mode) + { + $this->mode = $mode; + } + + /** + * @return String + */ + public function getContainer() + { + return $this->container; + } + + /** + * @param String $container + */ + public function setContainer($container) + { + $this->container = $container; + } + + /** + * @return \ArrayIterator + */ + public function getOptions() + { + return $this->options; + } + } \ No newline at end of file diff --git a/src/Option/Type/Select/Opt.php b/src/Option/Type/Select/Opt.php index df02fb1..4b253bb 100644 --- a/src/Option/Type/Select/Opt.php +++ b/src/Option/Type/Select/Opt.php @@ -3,8 +3,45 @@ namespace PSC\Library\Calc\Option\Type\Select; use PSC\Library\Calc\Option\Type\Base; -class Opt extends Base +class Opt { - static public $type = 'opt'; + /** @var string $id */ + protected $id; + + /** @var string $label */ + protected $label; + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return string + */ + public function getLabel() + { + return $this->label; + } + + /** + * @param string $label + */ + public function setLabel($label) + { + $this->label = $label; + } + } \ No newline at end of file diff --git a/src/PaperContainer.php b/src/PaperContainer.php new file mode 100644 index 0000000..15568fe --- /dev/null +++ b/src/PaperContainer.php @@ -0,0 +1,51 @@ +container = new \ArrayIterator(); + } + + public function parse(\SimpleXMLElement $node) + { + foreach($node->papiercontainer as $containerNode) { + $container = new Container(); + $container->setId((string)$containerNode['id']); + foreach($containerNode->papier as $paper) { + $item = new Item(); + $item->setId((string)$paper['id']); + $container->addItem($item); + } + $this->container->append($container); + } + } + + /** + * @return \ArrayIterator + */ + public function getContainer() + { + return $this->container; + } + + public function getContainerById($id) + { + /** @var Container $article */ + foreach($this->container as $container) + { + if($container->getId() == $id) { + return $container; + } + } + } + +} \ No newline at end of file diff --git a/src/PaperContainer/Container.php b/src/PaperContainer/Container.php new file mode 100644 index 0000000..67f98ec --- /dev/null +++ b/src/PaperContainer/Container.php @@ -0,0 +1,48 @@ +items = new \ArrayIterator(); + } + + /** + * @param Item $item + */ + public function addItem(Item $item) { + $this->items->append($item); + } + + /** + * @return \ArrayIterator + */ + public function getItems() + { + return $this->items; + } + + /** + * @return String + */ + public function getId() + { + return $this->id; + } + + /** + * @param String $id + */ + public function setId($id) + { + $this->id = $id; + } + +} \ No newline at end of file diff --git a/src/PaperContainer/Item.php b/src/PaperContainer/Item.php new file mode 100644 index 0000000..2fa75be --- /dev/null +++ b/src/PaperContainer/Item.php @@ -0,0 +1,26 @@ +id; + } + + /** + * @param String $id + */ + public function setId($id) + { + $this->id = $id; + } + +} \ No newline at end of file diff --git a/src/Parser.php b/src/Parser.php index c26597b..d3ede4f 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -1,10 +1,24 @@ article = new Article((string)$node->name); foreach ($node->option as $option) { - $obj = $optionParser->parse($option); + $obj = $optionParser->getOptByType($option); if($obj) { - $this->article->addOption($obj); + + if($obj instanceof Select) { + $obj->setPaperContainer($this->getPaperContainer()); + $obj->setPaperRepository($this->getPaperRepository()); + } + + $element = $obj->parse(); + $this->article->addOption($element); } } return $this->article; } + /** + * @return PaperContainer + */ + public function getPaperContainer() + { + return $this->paperContainer; + } + + /** + * @param PaperContainer $paperContainer + */ + public function setPaperContainer($paperContainer) + { + $this->paperContainer = $paperContainer; + } + + /** + * @return ObjectRepository + */ + public function getPaperRepository() + { + return $this->paperRepository; + } + + /** + * @param ObjectRepository $paperRepository + */ + public function setPaperRepository($paperRepository) + { + $this->paperRepository = $paperRepository; + } + } \ No newline at end of file diff --git a/tests/Article/CalendarXmlTest.php b/tests/Article/CalendarXmlTest.php index fd6594c..81a7831 100644 --- a/tests/Article/CalendarXmlTest.php +++ b/tests/Article/CalendarXmlTest.php @@ -4,12 +4,22 @@ namespace PSC\Library\Calc\Tests\Article; 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\PaperContainer\Container; +use PSC\Library\Calc\Tests\Mock\PaperRepostory; class CalendarXmlTest extends \PHPUnit_Framework_TestCase { public function testIfArticleCountInXmlCorrect() { + $repository = new PaperRepostory(); + + $paperContainer = new PaperContainer(); + $paperContainer->parse(simplexml_load_string(file_get_contents(__DIR__ .'/../TestFiles/Option/Select/papierContainer.xml'))); + $parser = new Engine(); + $parser->setPaperRepository($repository); + $parser->setPaperContainer($paperContainer); $this->assertTrue($parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/calendar.xml'))); $this->assertEquals(1, $parser->getArticles()->Count()); @@ -17,7 +27,14 @@ class CalendarXmlTest extends \PHPUnit_Framework_TestCase public function testGetArticleByName() { + $repository = new PaperRepostory(); + + $paperContainer = new PaperContainer(); + $paperContainer->parse(simplexml_load_string(file_get_contents(__DIR__ .'/../TestFiles/Option/Select/papierContainer.xml'))); + $parser = new Engine(); + $parser->setPaperRepository($repository); + $parser->setPaperContainer($paperContainer); $parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/calendar.xml')); /** @var Article $article */ @@ -28,7 +45,14 @@ class CalendarXmlTest extends \PHPUnit_Framework_TestCase public function testGetOptionById() { + $repository = new PaperRepostory(); + + $paperContainer = new PaperContainer(); + $paperContainer->parse(simplexml_load_string(file_get_contents(__DIR__ .'/../TestFiles/Option/Select/papierContainer.xml'))); + $parser = new Engine(); + $parser->setPaperRepository($repository); + $parser->setPaperContainer($paperContainer); $parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/calendar.xml')); /** @var Article $article */ $article = $parser->getArticleByName('Kalender'); @@ -42,7 +66,14 @@ class CalendarXmlTest extends \PHPUnit_Framework_TestCase public function testGetPrintableValuesFromSavedParamsWithCleaning() { + $repository = new PaperRepostory(); + + $paperContainer = new PaperContainer(); + $paperContainer->parse(simplexml_load_string(file_get_contents(__DIR__ .'/../TestFiles/Option/Select/papierContainer.xml'))); + $parser = new Engine(); + $parser->setPaperRepository($repository); + $parser->setPaperContainer($paperContainer); $parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/calendar.xml')); /** @var Article $article */ @@ -77,7 +108,24 @@ class CalendarXmlTest extends \PHPUnit_Framework_TestCase $this->assertEquals('13', $option->getRawValue()); $this->assertEquals('13 Seiten Monatskalender mit Deckblatt', $option->getValue()); + } + public function testGetOptionsForArticle() + { + $repository = new PaperRepostory(); + + $paperContainer = new PaperContainer(); + $paperContainer->parse(simplexml_load_string(file_get_contents(__DIR__ .'/../TestFiles/Option/Select/papierContainer.xml'))); + + $parser = new Engine(); + $parser->setPaperRepository($repository); + $parser->setPaperContainer($paperContainer); + $parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/calendar.xml')); + + /** @var Article $article */ + $article = $parser->getArticleByName('Kalender'); + + $this->assertEquals(10, $article->getOptions()->count()); } } \ No newline at end of file diff --git a/tests/Article/SimpleXmlTest.php b/tests/Article/SimpleXmlTest.php index f3150d5..f5959f7 100644 --- a/tests/Article/SimpleXmlTest.php +++ b/tests/Article/SimpleXmlTest.php @@ -2,12 +2,13 @@ namespace PSC\Library\Calc\Tests\Article; use PSC\Library\Calc\Engine; +use PSC\Library\Calc\PaperContainer\Container; class SimpleXmlTest extends \PHPUnit_Framework_TestCase { public function testIfArticleCountInXmlCorrect() { - $parser = new Engine(); + $parser = new Engine(new Container()); $this->assertTrue($parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/simple.xml'))); $this->assertEquals(1, $parser->getArticles()->Count()); @@ -15,7 +16,7 @@ class SimpleXmlTest extends \PHPUnit_Framework_TestCase public function testIfArticleCountInXmlCorrectWith2Article() { - $parser = new Engine(); + $parser = new Engine(new Container()); $this->assertTrue($parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/simple2articles.xml'))); $this->assertEquals(2, $parser->getArticles()->Count()); @@ -23,7 +24,7 @@ class SimpleXmlTest extends \PHPUnit_Framework_TestCase public function testGetArticleByName() { - $parser = new Engine(); + $parser = new Engine(new Container()); $parser->loadString(file_get_contents(__DIR__ .'/../TestFiles/General/simple2articles.xml')); $article = $parser->getArticleByName('Blocks A5 25blatt geleimt'); diff --git a/tests/General/LoadTest.php b/tests/General/LoadTest.php index f40043e..5322cf4 100644 --- a/tests/General/LoadTest.php +++ b/tests/General/LoadTest.php @@ -2,6 +2,7 @@ namespace PSC\Library\Calc\Tests\General; use PSC\Library\Calc\Engine; +use PSC\Library\Calc\PaperContainer\Container; class LoadTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Mock/Paper.php b/tests/Mock/Paper.php new file mode 100644 index 0000000..065084c --- /dev/null +++ b/tests/Mock/Paper.php @@ -0,0 +1,1096 @@ + + * @copyright 2012-2013 PrintshopCreator GmbH + * @license Private + * @link http://www.printshopcreator.de + */ +namespace PSC\Library\Calc\Tests\Mock; + +class Paper +{ + private $id; + private $install; + private $artNr; + private $auslauf; + private $description1; + private $description2; + private $grammatur; + private $staerke; + private $breite; + private $hoehe; + private $laenge; + + private $rollenLaenge; + + /** + * @var integer + * + * @ORM\Column(name="gewicht", type="integer", nullable=false) + */ + private $gewicht; + + /** + * @var string + * + * @ORM\Column(name="papierausruestung", type="string", length=60, nullable=false) + */ + private $papierAusruestung; + + /** + * @var string + * + * @ORM\Column(name="farbnummer", type="string", length=60, nullable=false) + */ + private $farbNummer; + + /** + * @var string + * + * @ORM\Column(name="farbbezeichnung", type="string", length=60, nullable=false) + */ + private $farbBezeichnung; + + /** + * @var string + * + * @ORM\Column(name="huelsendurchmesser", type="string", length=60, nullable=false) + */ + private $huelsenDurchmesser; + + /** + * @var string + * + * @ORM\Column(name="kleber", type="string", length=60, nullable=false) + */ + private $kleber; + + /** + * @var string + * + * @ORM\Column(name="abdeckpapier", type="string", length=60, nullable=false) + */ + private $abdeckPapier; + + /** + * @var string + * + * @ORM\Column(name="laufrichtung", type="string", length=2, nullable=false) + */ + private $laufRichtung; + + /** + * @var integer + * + * @ORM\Column(name="mengenangabe", type="integer", nullable=false) + */ + private $mengenAngabe; + + /** + * @var integer + * + * @ORM\Column(name="mengenangabe_palette", type="integer", nullable=false) + */ + private $mengenangabePalette; + + /** + * @var string + * + * @ORM\Column(name="inhalt", type="string", length=60, nullable=false) + */ + private $inhalt; + + /** + * @var string + * + * @ORM\Column(name="etiketten_je_blatt", type="string", length=60, nullable=false) + */ + private $etikettenJeBlatt; + + /** + * @var string + * + * @ORM\Column(name="mengeneinheit", type="string", length=30, nullable=false) + */ + private $mengenEinheit; + + /** + * @var integer + * + * @ORM\Column(name="staffelmenge_1", type="integer", nullable=false) + */ + private $staffelmenge1; + + /** + * @var float + * + * @ORM\Column(name="staffelpreis_1", type="float", precision=10, scale=0, nullable=false) + */ + private $staffelpreis1; + + /** + * @var integer + * + * @ORM\Column(name="staffelmenge_2", type="integer", nullable=false) + */ + private $staffelmenge2; + + /** + * @var float + * + * @ORM\Column(name="staffelpreis_2", type="float", precision=10, scale=0, nullable=false) + */ + private $staffelpreis2; + + /** + * @var integer + * + * @ORM\Column(name="staffelmenge_3", type="integer", nullable=false) + */ + private $staffelmenge3; + + /** + * @var float + * + * @ORM\Column(name="staffelpreis_3", type="float", precision=10, scale=0, nullable=false) + */ + private $staffelpreis3; + + /** + * @var integer + * + * @ORM\Column(name="staffelmenge_4", type="integer", nullable=false) + */ + private $staffelmenge4; + + /** + * @var float + * + * @ORM\Column(name="staffelpreis_4", type="float", precision=10, scale=0, nullable=false) + */ + private $staffelpreis4; + + /** + * @var integer + * + * @ORM\Column(name="staffelmenge_5", type="integer", nullable=false) + */ + private $staffelmenge5; + + /** + * @var float + * + * @ORM\Column(name="staffelpreis_5", type="float", precision=10, scale=0, nullable=false) + */ + private $staffelpreis5; + + /** + * @var string + * + * @ORM\Column(name="lagerort", type="string", length=7, nullable=false) + */ + private $lagerOrt; + + /** + * @var string + * + * @ORM\Column(name="verkaufshinweise", type="text", nullable=false) + */ + private $verkaufshinweise; + + /** + * @var string + * + * @ORM\Column(name="abnahmeinfo", type="string", length=60, nullable=false) + */ + private $abnahmeInfo; + + /** + * @var string + * + * @ORM\Column(name="produkt_beschreibung", type="text", nullable=false) + */ + private $produktBeschreibung; + + private $produktEigenschaften; + + private $produktVorteile; + + private $produktNutzen; + + private $produktAnwendungen; + + private $produktBesonderheit; + + private $musterbuch; + + private $zurAufnahmeVon; + + private $eigenschaften; + + private $preis; + + private $uuid; + + private $offsetFix; + + private $offsetVar; + + private $digitalFix; + + private $digitalVar; + + /** + * @return mixed + */ + public function getId() + { + return $this->id; + } + + /** + * @param mixed $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return mixed + */ + public function getInstall() + { + return $this->install; + } + + /** + * @param mixed $install + */ + public function setInstall($install) + { + $this->install = $install; + } + + /** + * @return mixed + */ + public function getArtNr() + { + return $this->artNr; + } + + /** + * @param mixed $artNr + */ + public function setArtNr($artNr) + { + $this->artNr = $artNr; + } + + /** + * @return mixed + */ + public function getAuslauf() + { + return $this->auslauf; + } + + /** + * @param mixed $auslauf + */ + public function setAuslauf($auslauf) + { + $this->auslauf = $auslauf; + } + + /** + * @return mixed + */ + public function getDescription1() + { + return $this->description1; + } + + /** + * @param mixed $description1 + */ + public function setDescription1($description1) + { + $this->description1 = $description1; + } + + /** + * @return mixed + */ + public function getDescription2() + { + return $this->description2; + } + + /** + * @param mixed $description2 + */ + public function setDescription2($description2) + { + $this->description2 = $description2; + } + + /** + * @return mixed + */ + public function getGrammatur() + { + return $this->grammatur; + } + + /** + * @param mixed $grammatur + */ + public function setGrammatur($grammatur) + { + $this->grammatur = $grammatur; + } + + /** + * @return mixed + */ + public function getStaerke() + { + return $this->staerke; + } + + /** + * @param mixed $staerke + */ + public function setStaerke($staerke) + { + $this->staerke = $staerke; + } + + /** + * @return mixed + */ + public function getBreite() + { + return $this->breite; + } + + /** + * @param mixed $breite + */ + public function setBreite($breite) + { + $this->breite = $breite; + } + + /** + * @return mixed + */ + public function getHoehe() + { + return $this->hoehe; + } + + /** + * @param mixed $hoehe + */ + public function setHoehe($hoehe) + { + $this->hoehe = $hoehe; + } + + /** + * @return mixed + */ + public function getLaenge() + { + return $this->laenge; + } + + /** + * @param mixed $laenge + */ + public function setLaenge($laenge) + { + $this->laenge = $laenge; + } + + /** + * @return mixed + */ + public function getRollenLaenge() + { + return $this->rollenLaenge; + } + + /** + * @param mixed $rollenLaenge + */ + public function setRollenLaenge($rollenLaenge) + { + $this->rollenLaenge = $rollenLaenge; + } + + /** + * @return int + */ + public function getGewicht() + { + return $this->gewicht; + } + + /** + * @param int $gewicht + */ + public function setGewicht($gewicht) + { + $this->gewicht = $gewicht; + } + + /** + * @return string + */ + public function getPapierAusruestung() + { + return $this->papierAusruestung; + } + + /** + * @param string $papierAusruestung + */ + public function setPapierAusruestung($papierAusruestung) + { + $this->papierAusruestung = $papierAusruestung; + } + + /** + * @return string + */ + public function getFarbNummer() + { + return $this->farbNummer; + } + + /** + * @param string $farbNummer + */ + public function setFarbNummer($farbNummer) + { + $this->farbNummer = $farbNummer; + } + + /** + * @return string + */ + public function getFarbBezeichnung() + { + return $this->farbBezeichnung; + } + + /** + * @param string $farbBezeichnung + */ + public function setFarbBezeichnung($farbBezeichnung) + { + $this->farbBezeichnung = $farbBezeichnung; + } + + /** + * @return string + */ + public function getHuelsenDurchmesser() + { + return $this->huelsenDurchmesser; + } + + /** + * @param string $huelsenDurchmesser + */ + public function setHuelsenDurchmesser($huelsenDurchmesser) + { + $this->huelsenDurchmesser = $huelsenDurchmesser; + } + + /** + * @return string + */ + public function getKleber() + { + return $this->kleber; + } + + /** + * @param string $kleber + */ + public function setKleber($kleber) + { + $this->kleber = $kleber; + } + + /** + * @return string + */ + public function getAbdeckPapier() + { + return $this->abdeckPapier; + } + + /** + * @param string $abdeckPapier + */ + public function setAbdeckPapier($abdeckPapier) + { + $this->abdeckPapier = $abdeckPapier; + } + + /** + * @return string + */ + public function getLaufRichtung() + { + return $this->laufRichtung; + } + + /** + * @param string $laufRichtung + */ + public function setLaufRichtung($laufRichtung) + { + $this->laufRichtung = $laufRichtung; + } + + /** + * @return int + */ + public function getMengenAngabe() + { + return $this->mengenAngabe; + } + + /** + * @param int $mengenAngabe + */ + public function setMengenAngabe($mengenAngabe) + { + $this->mengenAngabe = $mengenAngabe; + } + + /** + * @return int + */ + public function getMengenangabePalette() + { + return $this->mengenangabePalette; + } + + /** + * @param int $mengenangabePalette + */ + public function setMengenangabePalette($mengenangabePalette) + { + $this->mengenangabePalette = $mengenangabePalette; + } + + /** + * @return string + */ + public function getInhalt() + { + return $this->inhalt; + } + + /** + * @param string $inhalt + */ + public function setInhalt($inhalt) + { + $this->inhalt = $inhalt; + } + + /** + * @return string + */ + public function getEtikettenJeBlatt() + { + return $this->etikettenJeBlatt; + } + + /** + * @param string $etikettenJeBlatt + */ + public function setEtikettenJeBlatt($etikettenJeBlatt) + { + $this->etikettenJeBlatt = $etikettenJeBlatt; + } + + /** + * @return string + */ + public function getMengenEinheit() + { + return $this->mengenEinheit; + } + + /** + * @param string $mengenEinheit + */ + public function setMengenEinheit($mengenEinheit) + { + $this->mengenEinheit = $mengenEinheit; + } + + /** + * @return int + */ + public function getStaffelmenge1() + { + return $this->staffelmenge1; + } + + /** + * @param int $staffelmenge1 + */ + public function setStaffelmenge1($staffelmenge1) + { + $this->staffelmenge1 = $staffelmenge1; + } + + /** + * @return float + */ + public function getStaffelpreis1() + { + return $this->staffelpreis1; + } + + /** + * @param float $staffelpreis1 + */ + public function setStaffelpreis1($staffelpreis1) + { + $this->staffelpreis1 = $staffelpreis1; + } + + /** + * @return int + */ + public function getStaffelmenge2() + { + return $this->staffelmenge2; + } + + /** + * @param int $staffelmenge2 + */ + public function setStaffelmenge2($staffelmenge2) + { + $this->staffelmenge2 = $staffelmenge2; + } + + /** + * @return float + */ + public function getStaffelpreis2() + { + return $this->staffelpreis2; + } + + /** + * @param float $staffelpreis2 + */ + public function setStaffelpreis2($staffelpreis2) + { + $this->staffelpreis2 = $staffelpreis2; + } + + /** + * @return int + */ + public function getStaffelmenge3() + { + return $this->staffelmenge3; + } + + /** + * @param int $staffelmenge3 + */ + public function setStaffelmenge3($staffelmenge3) + { + $this->staffelmenge3 = $staffelmenge3; + } + + /** + * @return float + */ + public function getStaffelpreis3() + { + return $this->staffelpreis3; + } + + /** + * @param float $staffelpreis3 + */ + public function setStaffelpreis3($staffelpreis3) + { + $this->staffelpreis3 = $staffelpreis3; + } + + /** + * @return int + */ + public function getStaffelmenge4() + { + return $this->staffelmenge4; + } + + /** + * @param int $staffelmenge4 + */ + public function setStaffelmenge4($staffelmenge4) + { + $this->staffelmenge4 = $staffelmenge4; + } + + /** + * @return float + */ + public function getStaffelpreis4() + { + return $this->staffelpreis4; + } + + /** + * @param float $staffelpreis4 + */ + public function setStaffelpreis4($staffelpreis4) + { + $this->staffelpreis4 = $staffelpreis4; + } + + /** + * @return int + */ + public function getStaffelmenge5() + { + return $this->staffelmenge5; + } + + /** + * @param int $staffelmenge5 + */ + public function setStaffelmenge5($staffelmenge5) + { + $this->staffelmenge5 = $staffelmenge5; + } + + /** + * @return float + */ + public function getStaffelpreis5() + { + return $this->staffelpreis5; + } + + /** + * @param float $staffelpreis5 + */ + public function setStaffelpreis5($staffelpreis5) + { + $this->staffelpreis5 = $staffelpreis5; + } + + /** + * @return string + */ + public function getLagerOrt() + { + return $this->lagerOrt; + } + + /** + * @param string $lagerOrt + */ + public function setLagerOrt($lagerOrt) + { + $this->lagerOrt = $lagerOrt; + } + + /** + * @return string + */ + public function getVerkaufshinweise() + { + return $this->verkaufshinweise; + } + + /** + * @param string $verkaufshinweise + */ + public function setVerkaufshinweise($verkaufshinweise) + { + $this->verkaufshinweise = $verkaufshinweise; + } + + /** + * @return string + */ + public function getAbnahmeInfo() + { + return $this->abnahmeInfo; + } + + /** + * @param string $abnahmeInfo + */ + public function setAbnahmeInfo($abnahmeInfo) + { + $this->abnahmeInfo = $abnahmeInfo; + } + + /** + * @return string + */ + public function getProduktBeschreibung() + { + return $this->produktBeschreibung; + } + + /** + * @param string $produktBeschreibung + */ + public function setProduktBeschreibung($produktBeschreibung) + { + $this->produktBeschreibung = $produktBeschreibung; + } + + /** + * @return mixed + */ + public function getProduktEigenschaften() + { + return $this->produktEigenschaften; + } + + /** + * @param mixed $produktEigenschaften + */ + public function setProduktEigenschaften($produktEigenschaften) + { + $this->produktEigenschaften = $produktEigenschaften; + } + + /** + * @return mixed + */ + public function getProduktVorteile() + { + return $this->produktVorteile; + } + + /** + * @param mixed $produktVorteile + */ + public function setProduktVorteile($produktVorteile) + { + $this->produktVorteile = $produktVorteile; + } + + /** + * @return mixed + */ + public function getProduktNutzen() + { + return $this->produktNutzen; + } + + /** + * @param mixed $produktNutzen + */ + public function setProduktNutzen($produktNutzen) + { + $this->produktNutzen = $produktNutzen; + } + + /** + * @return mixed + */ + public function getProduktAnwendungen() + { + return $this->produktAnwendungen; + } + + /** + * @param mixed $produktAnwendungen + */ + public function setProduktAnwendungen($produktAnwendungen) + { + $this->produktAnwendungen = $produktAnwendungen; + } + + /** + * @return mixed + */ + public function getProduktBesonderheit() + { + return $this->produktBesonderheit; + } + + /** + * @param mixed $produktBesonderheit + */ + public function setProduktBesonderheit($produktBesonderheit) + { + $this->produktBesonderheit = $produktBesonderheit; + } + + /** + * @return mixed + */ + public function getMusterbuch() + { + return $this->musterbuch; + } + + /** + * @param mixed $musterbuch + */ + public function setMusterbuch($musterbuch) + { + $this->musterbuch = $musterbuch; + } + + /** + * @return mixed + */ + public function getZurAufnahmeVon() + { + return $this->zurAufnahmeVon; + } + + /** + * @param mixed $zurAufnahmeVon + */ + public function setZurAufnahmeVon($zurAufnahmeVon) + { + $this->zurAufnahmeVon = $zurAufnahmeVon; + } + + /** + * @return mixed + */ + public function getEigenschaften() + { + return $this->eigenschaften; + } + + /** + * @param mixed $eigenschaften + */ + public function setEigenschaften($eigenschaften) + { + $this->eigenschaften = $eigenschaften; + } + + /** + * @return mixed + */ + public function getPreis() + { + return $this->preis; + } + + /** + * @param mixed $preis + */ + public function setPreis($preis) + { + $this->preis = $preis; + } + + /** + * @return mixed + */ + public function getUuid() + { + return $this->uuid; + } + + /** + * @param mixed $uuid + */ + public function setUuid($uuid) + { + $this->uuid = $uuid; + } + + /** + * @return mixed + */ + public function getOffsetFix() + { + return $this->offsetFix; + } + + /** + * @param mixed $offsetFix + */ + public function setOffsetFix($offsetFix) + { + $this->offsetFix = $offsetFix; + } + + /** + * @return mixed + */ + public function getOffsetVar() + { + return $this->offsetVar; + } + + /** + * @param mixed $offsetVar + */ + public function setOffsetVar($offsetVar) + { + $this->offsetVar = $offsetVar; + } + + /** + * @return mixed + */ + public function getDigitalFix() + { + return $this->digitalFix; + } + + /** + * @param mixed $digitalFix + */ + public function setDigitalFix($digitalFix) + { + $this->digitalFix = $digitalFix; + } + + /** + * @return mixed + */ + public function getDigitalVar() + { + return $this->digitalVar; + } + + /** + * @param mixed $digitalVar + */ + public function setDigitalVar($digitalVar) + { + $this->digitalVar = $digitalVar; + } + + +} diff --git a/tests/Mock/PaperRepostory.php b/tests/Mock/PaperRepostory.php new file mode 100644 index 0000000..7f02d3f --- /dev/null +++ b/tests/Mock/PaperRepostory.php @@ -0,0 +1,117 @@ + + * @copyright 2012-2013 PrintshopCreator GmbH + * @license Private + * @link http://www.printshopcreator.de + */ +namespace PSC\Library\Calc\Tests\Mock; + +use Doctrine\Common\Persistence\ObjectRepository; + +class PaperRepostory implements ObjectRepository +{ + + /** + * Finds an object by its primary key / identifier. + * + * @param mixed $id The identifier. + * + * @return object The object. + */ + public function find($id) + { + // TODO: Implement find() method. + } + + /** + * Finds all objects in the repository. + * + * @return array The objects. + */ + public function findAll() + { + // TODO: Implement findAll() method. + } + + /** + * Finds objects by a set of criteria. + * + * Optionally sorting and limiting details can be passed. An implementation may throw + * an UnexpectedValueException if certain values of the sorting or limiting details are + * not supported. + * + * @param array $criteria + * @param array|null $orderBy + * @param int|null $limit + * @param int|null $offset + * + * @return array The objects. + * + * @throws \UnexpectedValueException + */ + public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + { + // TODO: Implement findBy() method. + } + + /** + * Finds a single object by a set of criteria. + * + * @param array $criteria The criteria. + * + * @return object The object. + */ + public function findOneBy(array $criteria) + { + $papier = array(); + $papier['bdm135'] = new Paper(); + $papier['bdm135']->setArtNr('bdm135'); + $papier['bdm135']->setDescription1('Bilderdruck matt 135 gr'); + + $papier['bdg135'] = new Paper(); + $papier['bdg135']->setArtNr('bdg135'); + $papier['bdg135']->setDescription1('Bilderdruck glänzend 135 gr'); + + $papier['bdm170'] = new Paper(); + $papier['bdm170']->setArtNr('bdm170'); + $papier['bdm170']->setDescription1('Bilderdruck matt 170 gr'); + + $papier['bdg170'] = new Paper(); + $papier['bdg170']->setArtNr('bdg170'); + $papier['bdg170']->setDescription1('Bilderdruck glänzend 170 gr'); + + $papier['bdm250'] = new Paper(); + $papier['bdm250']->setArtNr('bdm250'); + $papier['bdm250']->setDescription1('Bilderdruck matt 250 gr'); + + $papier['bdg250'] = new Paper(); + $papier['bdg250']->setArtNr('bdg250'); + $papier['bdg250']->setDescription1('Bilderdruck glänzend 250 gr'); + + $papier['bdm300'] = new Paper(); + $papier['bdm300']->setArtNr('bdm300'); + $papier['bdm300']->setDescription1('Bilderdruck matt 300 gr'); + + $papier['bdg300'] = new Paper(); + $papier['bdg300']->setArtNr('bdg300'); + $papier['bdg300']->setDescription1('Bilderdruck glänzend 300 gr'); + + return $papier[$criteria['artNr']]; + + } + + /** + * Returns the class name of the object managed by the repository. + * + * @return string + */ + public function getClassName() + { + // TODO: Implement getClassName() method. + } +} diff --git a/tests/Option/Type/InputTest.php b/tests/Option/Type/InputTest.php index 6ce2e54..7286697 100644 --- a/tests/Option/Type/InputTest.php +++ b/tests/Option/Type/InputTest.php @@ -3,29 +3,36 @@ namespace PSC\Library\Calc\Tests\Option\Type; use PSC\Library\Calc\Option\Parser; use PSC\Library\Calc\Option\Type\Input; +use PSC\Library\Calc\PaperContainer\Container; class InputTest extends \PHPUnit_Framework_TestCase { public function testIfCorrectType() { $parser = new Parser(); - /** @var Input $obj */ - $obj = $parser->parse(simplexml_load_string(file_get_contents(__DIR__ .'/../../TestFiles/Option/input.xml'))); + /** @var Parser\Input $obj */ + $obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ .'/../../TestFiles/Option/input.xml'))); - $this->assertInstanceOf('PSC\Library\Calc\Option\Type\Input', $obj); + /** @var Input $element */ + $element = $obj->parse(); + + $this->assertInstanceOf('PSC\Library\Calc\Option\Type\Input', $element); } public function testIfCorrectAttributes() { $parser = new Parser(); - /** @var Input $obj */ - $obj = $parser->parse(simplexml_load_string(file_get_contents(__DIR__ .'/../../TestFiles/Option/input.xml'))); + /** @var Parser\Input $obj */ + $obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ .'/../../TestFiles/Option/input.xml'))); - $this->assertInstanceOf('PSC\Library\Calc\Option\Type\Input', $obj); - $this->assertTrue($obj->isRequire()); - $this->assertEquals(5, $obj->getDefault()); - $this->assertEquals('auflage', $obj->getId()); - $this->assertEquals('Auflage', $obj->getName()); + /** @var Input $element */ + $element = $obj->parse(); + + $this->assertInstanceOf('PSC\Library\Calc\Option\Type\Input', $element); + $this->assertTrue($element->isRequire()); + $this->assertEquals(5, $element->getDefault()); + $this->assertEquals('auflage', $element->getId()); + $this->assertEquals('Auflage', $element->getName()); } } \ No newline at end of file diff --git a/tests/Option/Type/SelectTest.php b/tests/Option/Type/SelectTest.php index e8a3bc8..88815b8 100644 --- a/tests/Option/Type/SelectTest.php +++ b/tests/Option/Type/SelectTest.php @@ -3,29 +3,83 @@ namespace PSC\Library\Calc\Tests\Option\Type; use PSC\Library\Calc\Option\Parser; use PSC\Library\Calc\Option\Type\Select; +use PSC\Library\Calc\PaperContainer; +use PSC\Library\Calc\PaperContainer\Container; +use PSC\Library\Calc\Tests\Mock\PaperRepostory; class SelectTest extends \PHPUnit_Framework_TestCase { public function testIfCorrectType() { $parser = new Parser(); - /** @var Select $obj */ - $obj = $parser->parse(simplexml_load_string(file_get_contents(__DIR__ .'/../../TestFiles/Option/select.xml'))); + /** @var Parser\Select $obj */ + $obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ .'/../../TestFiles/Option/select.xml'))); + $obj->setPaperContainer(new PaperContainer()); - $this->assertInstanceOf('PSC\Library\Calc\Option\Type\Select', $obj); + /** @var Select $element */ + $element = $obj->parse(); + + $this->assertInstanceOf('PSC\Library\Calc\Option\Type\Select', $element); } public function testIfCorrectAttributes() { $parser = new Parser(); /** @var Select $obj */ - $obj = $parser->parse(simplexml_load_string(file_get_contents(__DIR__ .'/../../TestFiles/Option/select.xml'))); + $obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ .'/../../TestFiles/Option/select.xml'))); + $obj->setPaperContainer(new PaperContainer()); - $this->assertInstanceOf('PSC\Library\Calc\Option\Type\Select', $obj); - $this->assertTrue($obj->isRequire()); - $this->assertEquals('a4h', $obj->getDefault()); - $this->assertEquals('size', $obj->getId()); - $this->assertEquals('Wählen Sie eine Größe', $obj->getName()); + /** @var Select $element */ + $element = $obj->parse(); + + $this->assertInstanceOf('PSC\Library\Calc\Option\Type\Select', $element); + $this->assertTrue($element->isRequire()); + $this->assertEquals('a4h', $element->getDefault()); + $this->assertEquals('size', $element->getId()); + $this->assertEquals('Wählen Sie eine Größe', $element->getName()); + } + + public function testIfPaperContainerReturnsCorrectItems() + { + $paperContainer = new PaperContainer(); + $paperContainer->parse(simplexml_load_string(file_get_contents(__DIR__ .'/../../TestFiles/Option/Select/papierContainer.xml'))); + + $this->assertEquals(2, $paperContainer->getContainer()->count()); + + /** @var PaperContainer\Container $container */ + $container = $paperContainer->getContainerById('test1'); + + $this->assertInstanceOf('PSC\Library\Calc\PaperContainer\Container', $container); + + $this->assertEquals(5, $container->getItems()->count()); + + $container = $paperContainer->getContainerById('test2'); + + $this->assertInstanceOf('PSC\Library\Calc\PaperContainer\Container', $container); + + $this->assertEquals(8, $container->getItems()->count()); + } + + public function testIfSelectWithPaperContainerModeReturnsCorrectOpt() + { + + $repository = new PaperRepostory(); + + $paperContainer = new PaperContainer(); + $paperContainer->parse(simplexml_load_string(file_get_contents(__DIR__ .'/../../TestFiles/Option/Select/papierContainer.xml'))); + + $parser = new Parser(); + /** @var Parser\Select $obj */ + $obj = $parser->getOptByType(simplexml_load_string(file_get_contents(__DIR__ .'/../../TestFiles/Option/Select/selectPaperDB.xml'))); + $obj->setPaperContainer($paperContainer); + $obj->setPaperRepository($repository); + + /** @var Select $element */ + $element = $obj->parse(); + + $this->assertInstanceOf('PSC\Library\Calc\Option\Type\Select', $element); + + $this->assertEquals(5, $element->getOptions()->count()); } } \ No newline at end of file diff --git a/tests/TestFiles/General/calendar.xml b/tests/TestFiles/General/calendar.xml index da299a3..287b4a6 100644 --- a/tests/TestFiles/General/calendar.xml +++ b/tests/TestFiles/General/calendar.xml @@ -46,7 +46,7 @@ -