From b9a312cfd92b56bd49d906822eba08e8e6e7086b Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Fri, 23 Nov 2018 15:23:43 +0100 Subject: [PATCH] Implemented TemplateMeta and tests --- .../src/Domain/FormManagement/FormMeta.php | 16 ++++++ .../Domain/SourceManagement/SourceMeta.php | 2 +- .../TemplateManagement/TemplateMeta.php | 55 +++++++++++++++++-- .../TemplateMetaInterface.php | 13 ++--- .../SourceManagement/SourceMetaTest.php | 2 +- .../TemplateManagement/TemplateMetaTest.php | 52 ++++++++++++++++++ 6 files changed, 124 insertions(+), 16 deletions(-) create mode 100644 application/src/Domain/FormManagement/FormMeta.php create mode 100644 application/tests/Unit/Domain/TemplateManagement/TemplateMetaTest.php diff --git a/application/src/Domain/FormManagement/FormMeta.php b/application/src/Domain/FormManagement/FormMeta.php new file mode 100644 index 0000000..9ecba3f --- /dev/null +++ b/application/src/Domain/FormManagement/FormMeta.php @@ -0,0 +1,16 @@ +sourceReflection->getNamespaceName(); - $namespaceWithoutRoot = str_replace('App\\', '', $namespace); + $namespaceWithoutRoot = str_replace('App\\Entity\\', '', $namespace); $this->basicPathArray = []; foreach (explode('\\', $namespaceWithoutRoot) as $element) { $this->basicPathArray[] = strtolower($element); diff --git a/application/src/Domain/TemplateManagement/TemplateMeta.php b/application/src/Domain/TemplateManagement/TemplateMeta.php index dc4be08..b0374d8 100644 --- a/application/src/Domain/TemplateManagement/TemplateMeta.php +++ b/application/src/Domain/TemplateManagement/TemplateMeta.php @@ -2,14 +2,16 @@ namespace App\Domain\TemplateManagement; -use App\Domain\FormManagement\FormMetaInterface; use App\Domain\SourceManagement\SourceMetaInterface; use App\DBAL\Types\TemplateType; +/** + * @author kevinfrantz + */ class TemplateMeta implements TemplateMetaInterface { /** - * @var TemplateMetaInterface + * @var SourceMetaInterface */ private $sourceMeta; @@ -18,24 +20,67 @@ class TemplateMeta implements TemplateMetaInterface */ private $type = TemplateType::HTML; + /** + * @var string + */ + private $pathSuffix; + + /** + * @var string + */ + private $frameTemplatePath; + + /** + * @var string + */ + private $contentTemplatePath; + public function __construct(SourceMetaInterface $sourceMeta) { $this->sourceMeta = $sourceMeta; + $this->init(); } - public function getFramedTemplatePath(): string + private function init() { + $this->setPathSuffix(); + $this->setFrameTemplatePath(); + $this->setContentTemplatePath(); } - public function getFramelessTemplatePath(): string + private function setPathSuffix(): void { + $this->pathSuffix = implode('/', $this->sourceMeta->getBasicPathArray()).'/'.$this->sourceMeta->getBasicName().'.'.$this->type.'.twig'; } - public function getFormMeta(): FormMetaInterface + private function setFrameTemplatePath(): void { + $this->frameTemplatePath = 'frame/'.$this->pathSuffix; + } + + private function setContentTemplatePath(): void + { + $this->contentTemplatePath = 'content/'.$this->pathSuffix; + } + + public function getFrameTemplatePath(): string + { + return $this->frameTemplatePath; + } + + public function getContentTemplatePath(): string + { + return $this->contentTemplatePath; } public function setTemplateType(string $type): void { + $this->type = $type; + $this->init(); + } + + public function getTemplateType(): string + { + return $this->type; } } diff --git a/application/src/Domain/TemplateManagement/TemplateMetaInterface.php b/application/src/Domain/TemplateManagement/TemplateMetaInterface.php index 7950757..168835d 100644 --- a/application/src/Domain/TemplateManagement/TemplateMetaInterface.php +++ b/application/src/Domain/TemplateManagement/TemplateMetaInterface.php @@ -2,8 +2,6 @@ namespace App\Domain\TemplateManagement; -use App\Domain\FormManagement\FormMetaInterface; - /** * Manages all informations which are needed to process templates. * @@ -16,22 +14,19 @@ interface TemplateMetaInterface */ public function setTemplateType(string $type): void; + public function getTemplateType(): string; + /** * Returns a template inclusiv frame. * * @return string */ - public function getFramedTemplatePath(): string; + public function getFrameTemplatePath(): string; /** * Returns a template without a frame. * * @return string */ - public function getFramelessTemplatePath(): string; - - /** - * @return FormMetaInterface - */ - public function getFormMeta(): FormMetaInterface; + public function getContentTemplatePath(): string; } diff --git a/application/tests/Unit/Domain/SourceManagement/SourceMetaTest.php b/application/tests/Unit/Domain/SourceManagement/SourceMetaTest.php index f2767b6..1af9256 100644 --- a/application/tests/Unit/Domain/SourceManagement/SourceMetaTest.php +++ b/application/tests/Unit/Domain/SourceManagement/SourceMetaTest.php @@ -36,7 +36,7 @@ class SourceMetaTest extends TestCase public function testBasicPath(): void { - $subset = ['entity', 'source', 'complex']; + $subset = ['source', 'complex']; $amount = count($subset); $basicPathArray = $this->sourceMeta->getBasicPathArray(); for ($index = 0; $index < $amount; ++$index) { diff --git a/application/tests/Unit/Domain/TemplateManagement/TemplateMetaTest.php b/application/tests/Unit/Domain/TemplateManagement/TemplateMetaTest.php new file mode 100644 index 0000000..0a75d51 --- /dev/null +++ b/application/tests/Unit/Domain/TemplateManagement/TemplateMetaTest.php @@ -0,0 +1,52 @@ +source = new FirstNameSource(); + $this->templateMeta = new TemplateMeta(new SourceMeta($this->source)); + } + + public function testFrameTemplatePath(): void + { + $this->assertEquals($this->getExpectedPath('html', 'frame'), $this->templateMeta->getFrameTemplatePath()); + } + + public function testContentTemplatePath(): void + { + $this->assertEquals($this->getExpectedPath('html', 'content'), $this->templateMeta->getContentTemplatePath()); + } + + public function testSetType(): void + { + $this->templateMeta->setTemplateType('json'); + $this->assertEquals($this->getExpectedPath('json', 'content'), $this->templateMeta->getContentTemplatePath()); + $this->assertEquals($this->getExpectedPath('json', 'frame'), $this->templateMeta->getFrameTemplatePath()); + $this->assertEquals('json', $this->templateMeta->getTemplateType()); + } +}