Beispiel #1
0
 public function testGroups()
 {
     Phalcon\Mvc\Router\Route::reset();
     $router = new Phalcon\Mvc\Router(false);
     $blog = new Phalcon\Mvc\Router\Group(array('module' => 'blog', 'controller' => 'index'));
     $blog->setPrefix('/blog');
     $blog->add('/save', array('action' => 'save'));
     $blog->add('/edit/{id}', array('action' => 'edit'));
     $blog->add('/about', array('controller' => 'about', 'action' => 'index'));
     $router->mount($blog);
     $routes = array('/blog/save' => array('module' => 'blog', 'controller' => 'index', 'action' => 'save'), '/blog/edit/1' => array('module' => 'blog', 'controller' => 'index', 'action' => 'edit'), '/blog/about' => array('module' => 'blog', 'controller' => 'about', 'action' => 'index'));
     foreach ($routes as $route => $paths) {
         $router->handle($route);
         $this->assertTrue($router->wasMatched());
         $this->assertEquals($paths['module'], $router->getModuleName());
         $this->assertEquals($paths['controller'], $router->getControllerName());
         $this->assertEquals($paths['action'], $router->getActionName());
         $this->assertEquals($blog, $router->getMatchedRoute()->getGroup());
     }
 }
Beispiel #2
0
 public function testGroups()
 {
     $this->specify("Router Groups don't work properly", function () {
         \Phalcon\Mvc\Router\Route::reset();
         $router = new \Phalcon\Mvc\Router(false);
         $blog = new \Phalcon\Mvc\Router\Group(["module" => "blog", "controller" => "index"]);
         $blog->setPrefix("/blog");
         $blog->add("/save", ["action" => "save"]);
         $blog->add("/edit/{id}", ["action" => "edit"]);
         $blog->add("/about", ["controller" => "about", "action" => "index"]);
         $router->mount($blog);
         $routes = ["/blog/save" => ["module" => "blog", "controller" => "index", "action" => "save"], "/blog/edit/1" => ["module" => "blog", "controller" => "index", "action" => "edit"], "/blog/about" => ["module" => "blog", "controller" => "about", "action" => "index"]];
         foreach ($routes as $route => $paths) {
             $router->handle($route);
             expect($router->wasMatched())->true();
             expect($paths["module"])->equals($router->getModuleName());
             expect($paths["controller"])->equals($router->getControllerName());
             expect($paths["action"])->equals($router->getActionName());
             expect($blog)->equals($router->getMatchedRoute()->getGroup());
         }
     });
 }
Beispiel #3
0
 public function testBeforeMatch()
 {
     Phalcon\Mvc\Router\Route::reset();
     $trace = 0;
     $router = new Phalcon\Mvc\Router(false);
     $router->add('/static/route')->beforeMatch(function () use(&$trace) {
         $trace++;
         return false;
     });
     $router->add('/static/route2')->beforeMatch(function () use(&$trace) {
         $trace++;
         return true;
     });
     $router->handle();
     $this->assertFalse($router->wasMatched());
     $router->handle('/static/route');
     $this->assertFalse($router->wasMatched());
     $router->handle('/static/route2');
     $this->assertTrue($router->wasMatched());
     $this->assertEquals($trace, 2);
 }
Beispiel #4
0
<?php

//These routes simulate real URIs
$testRoutes = array('/', '/index', '/index/index', '/index/test', '/products', '/products/index/', '/products/show/101');
$router = new Phalcon\Mvc\Router();
//Add here your custom routes
//...
//Testing each route
foreach ($testRoutes as $testRoute) {
    //Handle the route
    $router->handle($testRoute);
    echo 'Testing ', $testRoute, '<br>';
    //Check if some route was matched
    if ($router->wasMatched()) {
        echo 'Controller: ', $router->getControllerName(), '<br>';
        echo 'Action: ', $router->getActionName(), '<br>';
    } else {
        echo 'The route wasn\'t matched by any route<br>';
    }
    echo '<br>';
}