FullStack.php

<?php 


namespace Lia\Test\Integration;

class FullStack extends \Lia\Test\Tester {


    public function testDeleteDefaultNoRouteHandler(){
        global $liaison_debug_headers;
        $liaison_debug_headers = [];

        $fake_server = new \Tlf\Tester\FakeServer();

        $response = $fake_server->send_request(
            $this->file('test/Server/deliver.php'),
            '/delete-default-noroute-handler/',
        );

        echo $response;

        $events_list = json_decode($response,true);
        $this->compare_arrays([], $events_list);

    }


    public function testHandleMultipleRoutes(){
        global $liaison_debug_headers;
        $liaison_debug_headers = [];

        $fake_server = new \Tlf\Tester\FakeServer();

        $this->test("Choose first route with custom route chooser");
        $response1 = $fake_server->send_request(
            $this->file('test/Server/deliver.php'),
            '/handle-multiple-routes/',
            'GET',
            ['route_index'=>0],
        );

        $this->compare("first route", $response1);


        $this->test("Choose second route with custom route chooser");
        $response2 = $fake_server->send_request(
            $this->file('test/Server/deliver.php'),
            '/handle-multiple-routes/',
            'GET',
            ['route_index'=>1],
        );

        $this->compare("second route", $response2);

    }
    public function testCustomNoRoute(){
        global $liaison_debug_headers;
        $liaison_debug_headers = [];

        $fake_server = new \Tlf\Tester\FakeServer();

        $response = $fake_server->send_request(
            $this->file('test/Server/deliver.php'),
            '/custom-noroute-handler/',
        );

        $this->test("Custom no-route handler: response & headers");
        $this->compare("CUSTOM NO ROUTE HANDLER", trim($response));

        $this->compare([], $liaison_debug_headers);
        $liaison_debug_headers = [];


        $this->test("Default no-route handler: response & headers");
        $response = $fake_server->send_request(
            $this->file('test/Server/deliver.php'),
            '/default-noroute-handler/',
        );

        $this->compare("No page was found for your request to /default-noroute-handler/", trim($response));

        $this->compare_arrays(
            [['header'=>'HTTP/1.1 404 Not Found',
            'replace'=>true,
            'response_code'=>404,
            ]]
            , $liaison_debug_headers);



        $liaison_debug_headers = [];
    }

    public function testFullDeliver(){
        $fake_server = new \Tlf\Tester\FakeServer();

        $response = $fake_server->send_request(
            $this->file('test/Server/deliver.php'),
            '/',
        );

        echo "\n\n\nResponse:\n-----------\n".trim($response)."\n\n\n-----------\n\n";
        $this->str_contains($response,"<h1>Test Site Home Page</h1>");

    }
}