Server.php

<?php

namespace Liaison\Test\Addon;

class Server extends \Tlf\Tester {

    public function testSetTheme(){
        $_SERVER['REQUEST_URI'] = '/';
        $dir = $this->file('test/input/Themes/');

        $lia = new \Lia\Simple();
        $lia->debug = true;

        $lia->root_dir = $dir;

        $lia->load_apps("$dir/");
        $lia->setup();


        $response = $lia->getResponse();
        $this->str_contains($response->content, "--main theme--", "content", );

        $lia->setTheme('one');
        $response = $lia->getResponse();
        $this->str_contains($response->content, "--one--", "content", );


        $lia->setTheme('two');
        $response = $lia->getResponse();
        $this->str_contains($response->content, "--two--", "content", );

    }

    public function testResponseContentNoTheme(){
        $lia = new \Lia();
        $package = new \Lia\Package($lia, 'test:idk');
        $server = new \Lia\Addon\Server($package);
        $server->init_lia();
        $server->useTheme = false;
        $hook = new \Lia\Addon\Hook($package);
        $hook->init_lia();
        $router = new \Lia\Addon\Router($package);
        $router->init_lia();
        $router->addRoute('/test/', [$this, 'sample_content']);

        $response = $server->getResponse('/test/');

        $this->compare('test-content', $response->content);
    }

    public function testResponseContentWithTheme(){
        $lia = new \Lia();
        $package = new \Lia\Package($lia, 'test:idk');
        $server = new \Lia\Addon\Server($package);
        $server->init_lia();
        $view = new \Lia\Addon\View($package);
        $view->init_lia();
        $view->addViewCallable('theme', [$this, 'theme_view']);
        $hook = new \Lia\Addon\Hook($package);
        $hook->init_lia();
        $router = new \Lia\Addon\Router($package);
        $router->init_lia();
        $router->addRoute('/test/', [$this, 'sample_content']);

        $response = $server->getResponse('/test/');

        $this->compare('<theme>test-content</theme>', $response->content);
    }


    public function theme_view($name, $args){
        $response = $args['response'];
        return '<theme>'.$response->content.'</theme>';
    }

    public function sample_content($route, $response){
        $response->content = 'test-content';
    }
}