<?php

class KVB_api_test extends TestCase
{
    private function time()
    {
        date_default_timezone_set('Europe/Berlin');
        $date = date('Y-m-d H:i');
        return $date;
    }

    public function test_departures_get_id_no_departures()
    {
        $output = $this->request('GET', 'station/id/2000');
        $expected = '{"version":"'.API_VERSION.'","timestamp":"'.$this->time().'","available":false,"station":"2000","error":"2","errorDescription":"No departures at the moment"}';
        $this->assertEquals($expected, $output);
        $this->assertResponseCode(200);
    }

    public function test_departures_get_id()
    {
        $output = $this->request('GET', 'station/id/1');
        $this->assertResponseCode(200);
    }

    public function test_departures_get_id_time_until()
    {
        $output = $this->request('GET', 'station/id/1/time/until');
        $this->assertResponseCode(200);
    }

    public function test_departures_get_id_time_arrival()
    {
        $output = $this->request('GET', 'station/id/1/time/arrival');
        $this->assertResponseCode(200);
    }

    public function test_departures_get_id_wrong_input()
    {
        $output = $this->request('GET', 'station/id/test');
        $this->assertResponseCode(404);
    }

    public function test_departures_get_name_unknown()
    {
        $output = $this->request('GET', 'station/name/t');
        $expected = '{"version":"'.API_VERSION.'","timestamp":"'.$this->time().'","available":false,"station":"T","error":"1","errorDescription":"Train Station name unknown"}';
        $this->assertEquals($expected, $output);
        $this->assertResponseCode(200);
    }

    public function test_departures_get_name()
    {
        $output = $this->request('GET', 'station/name/heumarkt');
        $this->assertResponseCode(200);
    }

    public function test_departures_get_name_time_until()
    {
        $output = $this->request('GET', 'station/name/heumarkt/time/until');
        $this->assertResponseCode(200);
    }

    public function test_departures_get_name_time_arrival()
    {
        $output = $this->request('GET', 'station/name/heumarkt/time/arrival');
        $this->assertResponseCode(200);
    }


//    public function test_users_get_id_with_http_accept_header()
//    {
//        $this->request->setHeader('Accept', 'application/csv');
//        $output = $this->request('GET', 'api/example/users/id/1');
//        $expected = "id,name,email,fact\n1,John,john@example.com,\"Loves coding\"\n";
//        $this->assertEquals($expected, $output);
//        $this->assertResponseCode(200);
//        $this->assertResponseHeader('Content-Type', 'application/csv; charset=utf-8');
//    }

//	public function test_post_user_data()
//	{
//		$payload = [
//            'id' => 100, // Automatically generated by the model
//            'name' => 'Person Name',
//            'email' => 'none@none.com',
//            'message' => 'Added a resource'
//        ];
//		$output = $this->request('POST', 'api/example/users', $payload);
//		$expected = '{"id":100,"name":"Person Name","email":"none@none.com","message":"Added a resource"}';
//		$this->assertEquals($expected, $output);
//		$this->assertResponseCode(201);
//	}
}