diff --git a/tests/unit/Resolver/TestThemeResolver.php b/tests/unit/Resolver/TestThemeResolver.php deleted file mode 100644 index 16a7d38828e55a6c8aaecea1a8cafcc19069ac89..0000000000000000000000000000000000000000 --- a/tests/unit/Resolver/TestThemeResolver.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php - - -class TestThemeResolver extends \PHPUnit\Framework\TestCase -{ - - - public function testEndpoint() - { - $resolver = new \WPDesk\View\Resolver\ThemeResolver(); - } -} \ No newline at end of file diff --git a/tests/unit/Resolver/TestWpThemeResolver.php b/tests/unit/Resolver/TestWpThemeResolver.php new file mode 100644 index 0000000000000000000000000000000000000000..af7a08bfaf65444c564d4ebfe19e03fdee7e3f5b --- /dev/null +++ b/tests/unit/Resolver/TestWpThemeResolver.php @@ -0,0 +1,69 @@ +<?php + + +use WPDesk\View\Resolver\Exception\CanNotResolve; + +class TestThemeResolver extends \PHPUnit\Framework\TestCase +{ + const TEMPLATE_NAME = 'some_template'; + const TEMPLATE_FILE = 'some_template.php'; + const TEMPLATE_SUBDIR = 'templates'; + + public function setUp() + { + \WP_Mock::setUp(); + + \WP_Mock::userFunction('locate_template', [ + 'return' => function ($template_names, $load = false, $require_once = true) { + $located = ''; + foreach ((array)$template_names as $template_name) { + if ( ! $template_name) { + continue; + } + if (file_exists(STYLESHEETPATH . '/' . $template_name)) { + $located = STYLESHEETPATH . '/' . $template_name; + break; + } + } + + return $located; + } + ]); + + \WP_Mock::userFunction('trailingslashit', [ + 'return' => function ($string) { + return untrailingslashit($string) . '/'; + } + ]); + + \WP_Mock::userFunction('untrailingslashit', [ + 'return' => function ($string) { + return rtrim($string, '/\\'); + } + ]); + } + + public function tearDown() + { + \WP_Mock::tearDown(); + } + + public function testCanFindInStyleSheetPath() + { + define('STYLESHEETPATH', __DIR__); + + $template_base_path = self::TEMPLATE_SUBDIR; + $resolver = new \WPDesk\View\Resolver\WPThemeResolver($template_base_path); + + $this->assertStringEndsWith(self::TEMPLATE_FILE, $resolver->resolve(self::TEMPLATE_NAME), + 'Template should be found in stylesheetpath'); + } + + public function testThrowExceptionWhenCannotFind() + { + $this->expectException(CanNotResolve::class); + + $resolver = new \WPDesk\View\Resolver\WPThemeResolver('whatever'); + $resolver->resolve('whatever2'); + } +} \ No newline at end of file diff --git a/tests/unit/Resolver/templates/some_template.php b/tests/unit/Resolver/templates/some_template.php new file mode 100644 index 0000000000000000000000000000000000000000..fcd781aa62d0947505006ff55743136fd003c5d2 --- /dev/null +++ b/tests/unit/Resolver/templates/some_template.php @@ -0,0 +1,2 @@ +<?php + echo 'outputText'; \ No newline at end of file