Example #1
0
   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);
   }
Example #2
0
function test_test_assert_request()
{
    assert_true(defined('TESTS_DOC_ROOT'), "Undefined 'TESTS_DOC_ROOT' constant");
    $response = test_request(TESTS_DOC_ROOT . '00-empty.php', 'GET', true);
    assert_header($response, 'Content-type');
    assert_header($response, 'Content-type', 'text/html');
    assert_header($response, 'Content-Type');
    assert_header($response, 'Content-Type', 'text/html');
}
Example #3
0
function test_output_render_file()
{
    $response = test_request(TESTS_DOC_ROOT . '02-outputs.php/text', 'GET', true);
    assert_header($response, 'Content-type', 'text/plain; charset=' . option('encoding'));
    $response = test_request(TESTS_DOC_ROOT . '02-outputs.php/jpeg', 'GET', true);
    assert_header($response, 'Content-type', 'image/jpeg');
    $response = test_request(TESTS_DOC_ROOT . '02-outputs.php/unknown_page', 'GET', true);
    assert_header($response, 'Content-type', 'text/html; charset=' . option('encoding'));
}
Example #4
0
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');
}
Example #5
0
function test_functional_request()
{
    $response = test_request(TESTS_DOC_ROOT . '01-hello_world.php', 'GET', true);
    //echo $response;
    assert_header($response, 'Content-type', 'text/html');
}
Example #6
0
set required values.

The \$config['limonade_base_url'] is required to run functional tests.

NOTE: the Limonade source code must be somewhere in your HTTP server public
folder in order to call testing limonade apps.

---

OUTPUT;
        exit;
    }
    # 2. HTTP+CURL requirements
    if (function_exists('curl_version')) {
        $url = $doc_root . 'index.php';
        $response = test_request($url, 'GET');
        if ($response) {
            $v = phpversion();
            $curl_v = curl_version();
            $cv = $curl_v['version'];
            if ($response == $v) {
                echo <<<OUTPUT

==== RUNNING LIMONADE TESTS [PHP {$v} — cURL {$cv}] =====

OUTPUT;
            } else {
                echo <<<OUTPUT

ERROR: Wrong response to HTTP request test
==========================================
Example #7
0
function test_output_autorender()
{
    $response = test_request(TESTS_DOC_ROOT . '02-outputs.php/autorender', 'GET');
    assert_equal($response, 'AUTORENDERED OUTPUT for empty_controller');
}
Example #8
0
function test_functional_routing()
{
    $path = TESTS_DOC_ROOT . '03-routing.php/';
    $response = test_request($path . 'route0', 'GET');
    assert_equal($response, 'route0');
    $response = test_request($path . 'route1', 'GET');
    assert_equal($response, 'route1');
    $response = test_request($path . 'route2', 'GET');
    assert_equal($response, 10);
    $response = test_request($path . 'route3', 'GET');
    assert_equal($response, 20);
    $response = test_request($path . 'route4', 'GET');
    assert_equal($response, 20);
    $response = test_request($path . 'route5', 'GET');
    assert_equal($response, 'human');
    $response = test_request($path . 'route5b', 'GET');
    assert_equal($response, 'human');
    $response = test_request($path . 'route6', 'GET');
    assert_equal($response, 'human');
    $response = test_request($path . 'route6b', 'GET');
    assert_equal($response, 'human10');
    $response = test_request($path . 'route6c', 'GET');
    assert_equal($response, 'human10');
    $response = test_request($path . 'route7/123', 'GET');
    assert_equal($response, 123);
    $response = test_request($path . 'route7b/123', 'GET');
    assert_equal($response, 123);
    $response = test_request($path . 'route7c/123', 'GET');
    assert_equal($response, 1230);
    $response = test_request($path . 'route7d/123', 'GET');
    assert_equal($response, 1230);
    $response = test_request($path . 'route7e/123', 'GET');
    assert_equal($response, 2460);
    $response = test_request($path . 'route7f/123', 'GET');
    assert_equal($response, 2460);
    $response = test_request($path . 'route7g', 'GET');
    assert_equal($response, 200);
    $response = test_request($path . 'route7h', 'GET');
    assert_equal($response, 200);
    $response = test_request($path . 'route8/123', 'GET');
    assert_equal($response, 123);
    $response = test_request($path . 'route8b/123', 'GET');
    assert_equal($response, 123);
    $response = test_request($path . 'route9/123', 'GET');
    assert_equal($response, 2460);
    $response = test_request($path . 'route9b/123', 'GET');
    assert_equal($response, 2460);
    $response = test_request($path . 'route10/123', 'GET');
    assert_equal($response, 2460);
    $response = test_request($path . 'route10b/123', 'GET');
    assert_equal($response, 2460);
    /* http methods dispatching */
    $response = test_request($path . 'route11', 'GET');
    assert_equal($response, 'GET');
    $response = test_request($path . 'route11', 'POST');
    var_dump($response);
    assert_equal($response, 'POST');
    $response = test_request($path . 'route11', 'PUT');
    assert_equal($response, 'PUT');
    $response = test_request($path . 'route11', 'DELETE');
    assert_equal($response, 'DELETE');
    $response = test_request($path . 'route11', 'HEAD', true);
    assert_header($response, 'X-LIM-CTL', 'route11');
    /* undefined route */
    $response = test_request($path . 'unknown_route', 'GET');
    assert_match('/Page not found/', $response);
}
Example #9
0
function test_functional_errors()
{
    $path = TESTS_DOC_ROOT . '04-errors.php/';
    $response = test_request($path . 'no-error', 'GET', true);
    assert_status($response, 200);
    $response = test_request($path . 'unknow____url', 'GET', true);
    assert_status($response, 404);
    $response = test_request($path . 'not_found', 'GET', true);
    assert_status($response, 404);
    $response = test_request($path . 'server_error', 'GET', true);
    assert_status($response, 500);
    $response = test_request($path . 'halt', 'GET', true);
    assert_status($response, 500);
    assert_no_match("/This shouldn't be outputed/", $response);
    $response = test_request($path . 'trigger_error', 'GET', true);
    assert_status($response, 500);
    assert_no_match("/This shouldn't be outputed/", $response);
    $response = test_request($path . 'trigger_error/E_USER_WARNING', 'GET', true);
    assert_status($response, 200);
    assert_no_match("/This should be seen/", $response);
    $response = test_request($path . 'trigger_error/E_USER_NOTICE', 'GET', true);
    assert_status($response, 200);
    assert_no_match("/This should be seen/", $response);
    $response = test_request($path . 'halt1234', 'GET', true);
    assert_status($response, 501);
    assert_match("/A personnal error #1234/", $response);
}