/
http.php
59 lines (43 loc) · 2.05 KB
/
http.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
if(!defined('LIMONADE')){$h="HTTP/1.0 401 Unauthorized";header($h);die($h);}// Security check
test_case("HTTP");
test_case_describe("Testing limonade HTTP utils functions.");
function test_http_response_status_code()
{
$response = test_request(TESTS_DOC_ROOT.'02-outputs.php/render0', 'GET', true);
assert_match("/HTTP\/1\./", $response);
assert_status($response, 200);
}
function test_http_ua_accepts()
{
$env = env();
$env['SERVER']['HTTP_ACCEPT'] = null;
assert_true(http_ua_accepts('text/plain'));
$env['SERVER']['HTTP_ACCEPT'] = 'text/html';
assert_true(http_ua_accepts('html'));
$env['SERVER']['HTTP_ACCEPT'] = 'text/*; application/json';
assert_true(http_ua_accepts('html'));
assert_true(http_ua_accepts('text/html'));
assert_true(http_ua_accepts('text/plain'));
assert_true(http_ua_accepts('application/json'));
assert_false(http_ua_accepts('image/png'));
assert_false(http_ua_accepts('png'));
assert_true(defined('TESTS_DOC_ROOT'), "Undefined 'TESTS_DOC_ROOT' constant");
$response = test_request(TESTS_DOC_ROOT.'05-content_negociation.php', 'GET', false, array(), array("Accept: image/png"));
assert_equal("Oops", $response);
$response = test_request(TESTS_DOC_ROOT.'05-content_negociation.php', 'GET', false, array(), array("Accept: text/html"));
assert_equal("<h1>HTML</h1>", $response);
$response = test_request(TESTS_DOC_ROOT.'05-content_negociation.php', 'GET', false, array(), array("Accept: application/json"));
assert_equal("json", $response);
}
function test_http_redirect()
{
$url = TESTS_DOC_ROOT.'09-redirect.php?/';
$response = test_request($url, 'GET');
assert_equal($response, '/redirected');
$response = test_request($url.'&key1=value1', 'GET');
assert_equal($response, '/redirected&key1=value1');
$response = test_request($url.'&key1=value1&key2=value2', 'GET');
assert_equal($response, '/redirected&key1=value1&key2=value2');
}
end_test_case();