mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 09:19:08 +00:00 
			
		
		
		
	Implemented TemplateMeta and tests
This commit is contained in:
		
							
								
								
									
										16
									
								
								application/src/Domain/FormManagement/FormMeta.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								application/src/Domain/FormManagement/FormMeta.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,16 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Domain\FormManagement; | ||||
|  | ||||
| use App\Domain\SourceManagement\SourceMetaInterface; | ||||
|  | ||||
| class FormMeta implements FormMetaInterface | ||||
| { | ||||
|     public function __construct(SourceMetaInterface $source) | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     public function getFormPath(): string | ||||
|     { | ||||
|     } | ||||
| } | ||||
| @@ -54,7 +54,7 @@ class SourceMeta implements SourceMetaInterface | ||||
|     private function setBasicPathArray(): void | ||||
|     { | ||||
|         $namespace = $this->sourceReflection->getNamespaceName(); | ||||
|         $namespaceWithoutRoot = str_replace('App\\', '', $namespace); | ||||
|         $namespaceWithoutRoot = str_replace('App\\Entity\\', '', $namespace); | ||||
|         $this->basicPathArray = []; | ||||
|         foreach (explode('\\', $namespaceWithoutRoot) as $element) { | ||||
|             $this->basicPathArray[] = strtolower($element); | ||||
|   | ||||
| @@ -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; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
| } | ||||
|   | ||||
| @@ -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) { | ||||
|   | ||||
| @@ -0,0 +1,52 @@ | ||||
| <?php | ||||
|  | ||||
| namespace Tests\Unit\Domain\TemplateManagement; | ||||
|  | ||||
| use PHPUnit\Framework\TestCase; | ||||
| use App\Domain\TemplateManagement\TemplateMetaInterface; | ||||
| use App\Entity\Source\Primitive\Name\FirstNameSource; | ||||
| use App\Entity\Source\SourceInterface; | ||||
| use App\Domain\TemplateManagement\TemplateMeta; | ||||
| use App\Domain\SourceManagement\SourceMeta; | ||||
|  | ||||
| class TemplateMetaTest extends TestCase | ||||
| { | ||||
|     /** | ||||
|      * @var TemplateMetaInterface | ||||
|      */ | ||||
|     protected $templateMeta; | ||||
|  | ||||
|     /** | ||||
|      * @var SourceInterface | ||||
|      */ | ||||
|     protected $source; | ||||
|  | ||||
|     private function getExpectedPath(string $type, string $context): string | ||||
|     { | ||||
|         return $context.'/source/primitive/name/firstname.'.$type.'.twig'; | ||||
|     } | ||||
|  | ||||
|     public function setUp(): void | ||||
|     { | ||||
|         $this->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()); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user