Skip to content
Snippets Groups Projects
Select Git revision
  • ead0498f4a3e9061005b7012513e9b5c458fc26d
  • master default protected
  • feat/woo-template
  • organize-tests
  • feat/add-show-rendered-method
  • devel
  • 2.1.0
  • 2.0.0
  • 1.1.0
  • 1.0.2
  • 1.0.1
  • 1.0
12 results

TestWpThemeResolver.php

Blame
  • TestWpThemeResolver.php 1.98 KiB
    <?php
    
    
    use WPDesk\View\Resolver\Exception\CanNotResolve;
    
    class TestThemeResolver extends \PHPUnit\Framework\TestCase
    {
        const TEMPLATE_NAME = 'some_template.php';
        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');
        }
    }