예제 #1
0
파일: run.php 프로젝트: kelvinj/Traffic
function mimick_request($path, $method = 'GET', $use_method_hack = false)
{
    t::request_uri(false);
    $_SERVER['PATH_INFO'] = $path;
    if ($use_method_hack) {
        $_SERVER['REQUEST_METHOD'] = 'POST';
        $_POST['_method'] = $method;
    } else {
        $_SERVER['REQUEST_METHOD'] = $method;
        unset($_POST['_method']);
    }
}
예제 #2
0
            $gather = gather_info(function () {
                t::get('/', array('CallbackTestClass::index', 'CallbackTestClassWithHooks::index'));
            });
            expect($gather)->to_be('index.index.');
        });
        it("should accept a mixture of all the ways one can define a callback", function () {
            mimick_request('/', 'GET');
            $gather = gather_info(function () {
                t::get('/', array('CallbackTestClass::index', 'CallbackTestClassWithHooks->index', array(CallbackTestClass, 'index'), array(new CallbackTestClassWithHooks(), 'index')));
            });
            expect($gather)->to_be('index.before.index.after.index.before.index.after.');
        });
        it("should accept a string representation of a callback", function () {
            mimick_request('/', 'GET');
            $gather = gather_info(function () {
                t::get('/', 'CallbackTestClass::index, CallbackTestClassWithHooks->index');
            });
            expect($gather)->to_be('index.before.index.after.');
        });
    });
});
class CallbackTestClass
{
    function index()
    {
        echo 'index.';
    }
}
class CallbackTestClassWithHooks
{
    function before_route()
예제 #3
0
파일: paths.php 프로젝트: kelvinj/Traffic
            });
            expect($gather)->to_be('3 wildcards. 1, 2, 3');
            reset_request();
            mimick_request('/path/to/file/1,2,3;edit', 'GET');
            $gather = gather_info(function () {
                t::get('/path/to/file/*,*,*;edit', function ($p) {
                    printf('%d wildcards. %s, %s, %s', count($p['splats']), $p[0], $p[1], $p[2]);
                });
                t::not_found(function () {
                    echo 'no rules picked up';
                });
            });
            expect($gather)->to_be('3 wildcards. 1, 2, 3');
        });
    });
    describe("funny characters", function () {
        it("should support funny characters splats", function () {
            // path has trailing slash but not route
            mimick_request('/user/Kélvin', 'GET');
            $gather = gather_info(function () {
                t::get('/user/*', function ($p) {
                    echo $p['splats'][0];
                });
                t::not_found(function () {
                    echo 'no rules picked up';
                });
            });
            expect($gather)->to_be('Kélvin');
        });
    });
});