Error.php

<?php

namespace Liaison\Test\Compo;

class Error extends \Taeluf\Tester {


    public function testErrorGoto(){
        $this->disable();
        return;
        $lia = new \Liaison();
        $routeContent = "Very generic content from a simple route.";
        $lia->addRoute('/',function($req,$resp)use($routeContent){$resp->content = $routeContent;});
        $lia->error_goto($errorMsg="Very generic error_goto message.");
        $response = $lia->getResponse('/', 'GET');

        //Check if redirect headers are correct
        //Then mock the state that would exist after the redirect
        //then getResponse('error_page_url')
        //and verify the error message is correct

        $this->str_contains($response->content, $errorMsg);
        $this->str_not_contains($response->content, $routeContent);
    }

    public function testErrorPage(){
        $lia = new \Liaison();
        $routeContent = "Very generic content from a simple route.";
        $lia->addRoute('/',function($req,$resp)use($routeContent){$resp->content = $routeContent;});
        $lia->error_page($errorMsg="Very generic error_page message.");
        $response = $lia->getResponse('/', 'GET');
        $this->str_contains($response->content, $errorMsg);
        $this->str_not_contains($response->content, $routeContent);

    }

    public function testErrorHeader(){
        $lia = new \Liaison();
        $routeContent = "Very generic content from a simple route.";
        $lia->addRoute('/',function($req,$resp)use($routeContent){$resp->content = $routeContent;});
        $lia->error_header($errorMsg="Very generic error_header message.");
        $response = $lia->getResponse('/', 'GET');
        $this->str_contains($response->content, $errorMsg);
        $this->str_contains($response->content, $routeContent);
    }
    
    public function testSomeStatusCodes(){
        $lia = new \Liaison();
        $errorCompo = $lia->compo('lia:error');

        $codes = [
            100 => 'Continue',
            101 => 'Switching Protocol',
            102 => 'Processing',
            103 => 'Early Hints',
            200 => 'OK',
            201 => 'Created',
            202 => 'Accepted',
        ];
        foreach ($codes as $num=>$text){
            $this->test("Code $num");
            $this->compare($text,$errorCompo->statusCodeText($num));
        }
    }
}