Skip to content

Commit

Permalink
Fix bug in ThemeResolveTemplatePath for typed names
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominick Johnson committed Apr 15, 2024
1 parent 9e967f1 commit 7f90abc
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace DMJohnson\Contemplate\Tests\Template\ResolveTemplatePath;

use DMJohnson\Contemplate\Engine;
use DMJohnson\Contemplate\Template\Controller;
use DMJohnson\Contemplate\Template\Name;
use DMJohnson\Contemplate\Template\Resolvable;
use DMJohnson\Contemplate\Template\ResolveTemplatePath\ThemeResolveTemplatePath;
use DMJohnson\Contemplate\Template\Theme;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;

class ThemeResolveTemplatePathTest extends TestCase
{
private $resolver;
private $engine;

protected function setUp(): void
{
vfsStream::setup('templates');
vfsStream::create(
array(
'a' => 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));
}


}

0 comments on commit 7f90abc

Please sign in to comment.