function test_load_handler_()
{
    $handler = 'testhandler' . rand();
    testhelper_create_handler_($handler);
    should_return(1, when_passed($handler));
    testhelper_remove_handler_($handler);
}
function test_select_function_()
{
    should_return('default_function_to_call', when_passed('test_webserver', 'function_to_call'));
    function test_webserver_function_to_call()
    {
        return;
    }
    should_return('test_webserver_function_to_call', when_passed('test_webserver', 'function_to_call'));
}
function test_response_is_valid_()
{
    should_return(false, when_passed(''));
    should_return(false, when_passed(array('status_code' => 200, 'headers' => '', 'body' => '')));
    should_return(true, when_passed(array('status_code' => 200, 'headers' => array(), 'body' => '')));
    should_return(false, when_passed(array('headers' => array(), 'body' => '')));
    should_return(false, when_passed(array('status_code' => 200, 'body' => '')));
    should_return(false, when_passed(array('status_code' => 200, 'headers' => array())));
    should_return(true, when_passed(array('status_code' => 200, 'headers' => array(), 'body' => '', 'foo' => 'bar')));
}
Exemple #4
0
function test_server_var()
{
    should_return($_SERVER['PHP_SELF'], when_passed('PHP_SELF'));
    should_return(NULL, when_passed('FOO_BAR_BAZ'));
    unset($_SERVER['REMOTE_ADDR']);
    should_return(getenv('REMOTE_ADDR'), when_passed('REMOTE_ADDR'));
    $env_var = 'FOO' . rand();
    putenv("{$env_var}=bar");
    should_return('bar', when_passed($env_var));
}
Exemple #5
0
function test_handler_match_()
{
    should_return(handler_('GET', array('/', '/{home}'), array(), array('func')), when_passed(handler_('GET', array('/', '/{home}'), array(), array('func')), request_(array('method' => 'GET', 'path' => '/hand'))));
    should_return(handler_('GET', array('/'), array(), array('func')), when_passed(handler_('GET', array('/'), array(), array('func')), request_(array('method' => 'GET', 'path' => '/', 'query' => array('foo' => 'bar')))));
    should_return(handler_('GET', array('/'), array('query' => true), array('func')), when_passed(handler_('GET', array('/'), array('query' => true), array('func')), request_(array('method' => 'GET', 'path' => '/', 'query' => array('foo' => 'bar')))));
    should_return(NULL, when_passed(handler_('GET', array('/'), array('query' => true), array('func')), request_(array('method' => 'GET', 'path' => '/', 'query' => array()))));
    should_return(handler_('POST', array('/'), array('action' => 'save_me'), array('func')), when_passed(handler_('POST', array('/'), array('action' => 'save_me'), array('func')), request_(array('method' => 'POST', 'path' => '/', 'form' => array('action' => 'Save Me')))));
    should_return(handler_('POST', array('/'), array(), array('func')), when_passed(handler_('POST', array('/'), array(), array('func')), request_(array('method' => 'POST', 'path' => '/', 'form' => array('action' => 'Save Me')))));
    should_return(NULL, when_passed(handler_('POST', array('/'), array('action' => 'save'), array('func')), request_(array('method' => 'POST', 'path' => '/', 'form' => array('action' => 'Save Me')))));
    should_return(NULL, when_passed(handler_('POST', array('/'), array('action' => 'save'), array('func')), request_(array('method' => 'POST', 'path' => '/', 'form' => array()))));
}
function test_sub_path_()
{
    should_return('', when_passed('', 0));
    should_return('/', when_passed('/', 0));
    should_return('//', when_passed('//', 0));
    should_return(false, when_passed('/foo', 2));
    should_return('/foo/bar/', when_passed('/foo/bar/', 0));
    should_return('/foo/bar', when_passed('/foo/bar', 0));
    should_return('/bar', when_passed('/foo/bar', -1));
    should_return('/foo', when_passed('/foo/bar', 0, 1));
    should_return('/bar', when_passed('/foo/bar/', 1, -1));
    should_return('/bar', when_passed('/foo/bar/', -2, -1));
    should_return('/foo/bar', when_passed('/foo/bar', -10));
    should_return('/foo/bar', when_passed('/foo/bar', 0, 10));
    should_return('foo', when_passed('foo/bar', 0, 1));
}
function test_minimal_html_()
{
    $html = "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n" . "<html>\n<head>\n<title>Hello</title>\n</head>\n<body>\nHello World\n</body>\n</html>";
    should_return($html, when_passed('Hello', 'Hello World'));
}
Exemple #8
0
function test_when_passed()
{
    should_return(array('foo', 'bar'), when_passed('foo', 'bar'));
}
function test_default_uri_()
{
    should_return('http://example.com/index.php?path_=/foo', when_passed('http://example.com/', '/foo'));
    should_return('http://example.com/index.php?path_=/foo&bar=baz', when_passed('http://example.com/', '/foo?bar=baz'));
}
function test_apache_uri_helper_()
{
    should_return('http://example.com/foo', when_passed('http://example.com/', '/foo'));
    should_return('http://example.com/foo', when_passed('http://example.com/', 'foo'));
}
Exemple #11
0
function test_str_xss_sanitize()
{
    should_return('&lt;script type=&quot;javascript&quot;&gt;alert(&quot;hello &amp; welcome&quot;)&lt;/script&gt;', when_passed('<script type="javascript">alert("hello & welcome")</script>'));
}
Exemple #12
0
function test_array_stripslashes_()
{
    should_return(array("f'oo", "b'ar", array("fo'o", "b'ar")), when_passed(array("f\\'oo", "b\\'ar", array("fo\\'o", "b\\'ar"))));
}
Exemple #13
0
function test_uri_relative_base()
{
    should_return('/', when_passed(''));
    should_return('/foobar/', when_passed('/foobar'));
}
Exemple #14
0
function test_convert_named_part_filters_to_regex()
{
    require dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'filters.config.php';
    should_return('(?P<foo>[^/]+)', when_passed(array('{foo}', 'foo'), $filters));
    should_return('(?P<foo>.+)', when_passed(array('{foo:any}', 'foo:any'), $filters));
}
Exemple #15
0
function test_handler_dir()
{
    should_return(php_self_dir() . 'handlers' . DIRECTORY_SEPARATOR . 'foo' . DIRECTORY_SEPARATOR, when_passed('foo'));
}
function test_uri_relative_base_()
{
    should_return('/', when_passed(''));
    should_return('/inertia/', when_passed('/inertia'));
}
Exemple #17
0
function test_valid_body_()
{
    $data = 'hello world';
    should_return($data, when_passed($data));
    should_return(NULL, when_passed(false));
}
function test_prepend_path_with_slash_()
{
    should_return('/foo', when_passed('/foo'));
    should_return('/foo', when_passed('/foo'));
    should_return(array('foo', '/bar'), when_passed(array('foo', 'bar')));
    should_return(array('foo', array('bar', '/baz')), when_passed(array('foo', array('bar', 'baz'))));
}
function test_function_exists_()
{
    should_return(__FUNCTION__, when_passed(__FUNCTION__));
    should_return(false, when_passed(__FUNCTION__ . rand()));
}
function test_request_body_()
{
    $data = 'hello world';
    should_return($data, when_passed($data));
    should_return(NULL, when_passed(''));
}