Beispiel #1
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()
Beispiel #2
0
            expect($gather)->to_be('request');
            reset_request();
            // get
            mimick_request('/', 'DELETE');
            $gather = gather_info(function () {
                t::request('/', function () {
                    echo 'request';
                });
                t::delete('/', function () {
                    echo 'delete';
                });
                t::not_found(function () {
                    echo 'no rules picked up';
                });
            });
            expect($gather)->to_be('request');
        });
        it("should ignore request() for unknown methods, e.g. not GET, POST.", function () {
            mimick_request('/', 'TRUNCATE');
            $gather = gather_info(function () {
                t::request('/', function () {
                    echo 'request';
                });
                t::not_found(function () {
                    echo 'no rules picked up';
                });
            });
            expect($gather)->to_be('no rules picked up');
        });
    });
});
Beispiel #3
0
            });
            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');
        });
    });
});
Beispiel #4
0
 it("allow arguments to be passed in any order", function () {
     mimick_request('/user/123', 'GET');
     $gather = gather_info(function () {
         t::get('/user/:userid', function ($p) {
             echo '1.';
             t::pass();
         }, array(':userid' => '/^[0-9]+$/i'));
         t::get('/user/:userid', array(':userid' => '/^[0-9]+$/i'), function ($p) {
             echo '2.';
             t::pass();
         });
         t::get(array(':userid' => '/^[0-9]+$/i'), '/user/:userid', function ($p) {
             echo '3.';
             t::pass();
         });
         t::get(array(':userid' => '/^[0-9]+$/i'), function ($p) {
             echo '4.';
             t::pass();
         }, '/user/:userid');
         t::get(function ($p) {
             echo '5.';
             t::pass();
         }, '/user/:userid', array(':userid' => '/^[0-9]+$/i'));
         t::get(function ($p) {
             echo '6.';
         }, array(':userid' => '/^[0-9]+$/i'), '/user/:userid');
         t::not_found(function () {
             echo 'no rules picked up';
         });
     });
     expect($gather)->to_be('1.2.3.4.5.6.');
 });