Phalcon\Test\Unit\Mvc\RouterTest::testUsingRouteConverters PHP Method

testUsingRouteConverters() public method

Tests routing by use Route::convert
Since: 2012-12-25
Author: Andy Gutierrez ([email protected])
    public function testUsingRouteConverters()
    {
        $this->specify('The Route::convert doest not work as expected', function ($route, $paths) {
            $router = $this->getRouter();
            $router->add('/{controller:[a-z\\-]+}/{action:[a-z\\-]+}/this-is-a-country')->convert('controller', function ($controller) {
                return str_replace('-', '', $controller);
            })->convert('action', function ($action) {
                return str_replace('-', '', $action);
            });
            $router->add('/([A-Z]+)/([0-9]+)', ['controller' => 1, 'action' => 'default', 'id' => 2])->convert('controller', function ($controller) {
                return strtolower($controller);
            })->convert('action', function ($action) {
                return $action == 'default' ? 'index' : $action;
            })->convert('id', function ($id) {
                return strrev($id);
            });
            $router->handle($route);
            expect($router->wasMatched())->true();
            expect($router->getControllerName())->equals($paths['controller']);
            expect($router->getActionName())->equals($paths['action']);
        }, ['examples' => $this->convertersProvider()]);
    }