From 7f90abc70f21c068a65f771f2eae54bb7dd02fe5 Mon Sep 17 00:00:00 2001 From: Dominick Johnson Date: Mon, 15 Apr 2024 09:45:59 -0600 Subject: [PATCH] Fix bug in ThemeResolveTemplatePath for typed names --- .../ThemeResolveTemplatePath.php | 2 +- .../ThemeResolveTemplatePathTest.php | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 tests/Template/ResolveTemplatePath/ThemeResolveTemplatePathTest.php diff --git a/src/Template/ResolveTemplatePath/ThemeResolveTemplatePath.php b/src/Template/ResolveTemplatePath/ThemeResolveTemplatePath.php index 442eb28..f3667fb 100644 --- a/src/Template/ResolveTemplatePath/ThemeResolveTemplatePath.php +++ b/src/Template/ResolveTemplatePath/ThemeResolveTemplatePath.php @@ -18,7 +18,7 @@ public function __construct(Theme $theme) { public function __invoke(Name $name): string { $searchedPaths = []; foreach ($this->theme->listThemeHierarchy() as $theme) { - $path = $theme->dir() . '/' . $name->getName() . '.' . $name->getEngine()->getFileExtension(); + $path = $theme->dir() . '/' . $name->getFile(); if (is_file($path)) { return $path; } diff --git a/tests/Template/ResolveTemplatePath/ThemeResolveTemplatePathTest.php b/tests/Template/ResolveTemplatePath/ThemeResolveTemplatePathTest.php new file mode 100644 index 0000000..e6184e9 --- /dev/null +++ b/tests/Template/ResolveTemplatePath/ThemeResolveTemplatePathTest.php @@ -0,0 +1,61 @@ + array( + 'thing1.get.php'=>'', + 'thing1.tpl.php'=>'', + 'untyped.php'=>'', + ), + 'b' => array( + + ), + ) + ); + + $this->engine = new Engine(vfsStream::url('templates')); + $this->engine->setFileExtension('tpl.php', Resolvable::TYPE_TEMPLATE); + $this->engine->setFileExtension('get.php', Resolvable::TYPE_CONTROLLER_HTTP_GET); + $this->engine->setFileExtension('post.php', Resolvable::TYPE_CONTROLLER_HTTP_POST); + + $this->resolver = new ThemeResolveTemplatePath(Theme::hierarchy([ + Theme::new(vfsStream::url('templates/a'), 'A'), + Theme::new(vfsStream::url('templates/b'), 'B'), + ])); + } + + public function testGetFromUntypedName() + { + $name = new Name($this->engine, 'untyped'); + $this->assertSame('vfs://templates/a/untyped.php', ($this->resolver)($name)); + } + + public function testGetFromTypedName() + { + $name = new Name($this->engine, 'thing1', Resolvable::TYPE_TEMPLATE); + $this->assertSame('vfs://templates/a/thing1.tpl.php', ($this->resolver)($name)); + } + + +}