コード例 #1
0
 public function testAnnotations()
 {
     $di = new Di();
     $di['request'] = new \Phalcon\Http\Request();
     $di['annotations'] = new \Phalcon\Annotations\Adapter\Memory();
     $router = new \Phalcon\Mvc\Router\Annotations(false);
     $router->setDI($di);
     $loader = new AnnotationRouteLoader($router);
     $loader->load(__DIR__ . '/Fixtures');
     $router->handle();
     $this->assertCount(3, $router->getRoutes());
     $routes = [['uri' => '/test1', 'method' => 'GET', 'controller' => 'test1', 'action' => 'test1'], ['uri' => '/test2', 'method' => 'POST', 'controller' => 'test2', 'action' => 'test2'], ['uri' => '/test3', 'method' => 'GET', 'controller' => 'test3', 'action' => 'test3']];
     foreach ($routes as $route) {
         $_SERVER['REQUEST_METHOD'] = $route['method'];
         $router->handle($route['uri']);
         $this->assertEquals($router->getControllerName(), $route['controller']);
         $this->assertEquals($router->getActionName(), $route['action']);
         $this->assertEquals($router->isExactControllerName(), true);
     }
 }
コード例 #2
0
 public function testRouteConfig()
 {
     $di = new Di();
     $di['request'] = new \Phalcon\Http\Request();
     $di['annotations'] = new \Phalcon\Annotations\Adapter\Memory();
     $router = new \Phalcon\Mvc\Router\Annotations(false);
     $router->setDI($di);
     $resolver = new RouterResolver($router);
     $resolver->resolve(include __DIR__ . '/Fixtures/route_config.php');
     $router->handle();
     $routes = [['uri' => '/test4', 'method' => 'GET', 'controller' => 'test4', 'action' => 'test4'], ['uri' => '/test4', 'method' => 'POST', 'controller' => 'test4', 'action' => 'test4'], ['uri' => '/test5', 'method' => 'POST', 'controller' => 'test5', 'action' => 'test5'], ['uri' => '/test6', 'method' => 'GET', 'controller' => 'test6', 'action' => 'test6'], ['uri' => '/test1', 'method' => 'GET', 'controller' => 'test1', 'action' => 'test1'], ['uri' => '/test2', 'method' => 'POST', 'controller' => 'test2', 'action' => 'test2'], ['uri' => '/test3', 'method' => 'GET', 'controller' => 'test3', 'action' => 'test3']];
     $this->assertCount(count($routes) - 1, $router->getRoutes());
     foreach ($routes as $route) {
         $_SERVER['REQUEST_METHOD'] = $route['method'];
         $router->handle($route['uri']);
         $this->assertEquals($router->getControllerName(), $route['controller']);
         $this->assertEquals($router->getActionName(), $route['action']);
         $this->assertEquals($router->isExactControllerName(), true);
     }
 }
コード例 #3
0
 public function testRouterFullResources()
 {
     $router = new Phalcon\Mvc\Router\Annotations(false);
     $router->setDI($this->_getDI());
     $router->addResource('Robots', '/');
     $router->addResource('Products', '/products');
     $router->addResource('About', '/about');
     $router->handle('/products');
     $this->assertEquals(count($router->getRoutes()), 6);
     $router = new Phalcon\Mvc\Router\Annotations(false);
     $router->setDI($this->_getDI());
     $router->addResource('Robots', '/');
     $router->addResource('Products', '/products');
     $router->addResource('About', '/about');
     $router->handle('/about');
     $this->assertEquals(count($router->getRoutes()), 5);
     $router = new Phalcon\Mvc\Router\Annotations(false);
     $router->setDI($this->_getDI());
     $router->addResource('Robots');
     $router->addResource('Products');
     $router->addResource('About');
     $router->addResource('Main');
     $router->handle();
     $this->assertEquals(count($router->getRoutes()), 9);
     $route = $router->getRouteByName('save-robot');
     $this->assertTrue(is_object($route));
     $this->assertEquals(get_class($route), 'Phalcon\\Mvc\\Router\\Route');
     $route = $router->getRouteByName('save-product');
     $this->assertTrue(is_object($route));
     $this->assertEquals(get_class($route), 'Phalcon\\Mvc\\Router\\Route');
     $routes = array(array('uri' => '/products/save', 'method' => 'PUT', 'controller' => 'products', 'action' => 'save', 'params' => array()), array('uri' => '/products/save', 'method' => 'POST', 'controller' => 'products', 'action' => 'save', 'params' => array()), array('uri' => '/products/edit/100', 'method' => 'GET', 'controller' => 'products', 'action' => 'edit', 'params' => array('id' => '100')), array('uri' => '/products', 'method' => 'GET', 'controller' => 'products', 'action' => 'index', 'params' => array()), array('uri' => '/robots/edit/100', 'method' => 'GET', 'controller' => 'robots', 'action' => 'edit', 'params' => array('id' => '100')), array('uri' => '/robots', 'method' => 'GET', 'controller' => 'robots', 'action' => 'index', 'params' => array()), array('uri' => '/robots/save', 'method' => 'PUT', 'controller' => 'robots', 'action' => 'save', 'params' => array()), array('uri' => '/about/team', 'method' => 'GET', 'controller' => 'about', 'action' => 'team', 'params' => array()), array('uri' => '/about/team', 'method' => 'POST', 'controller' => 'about', 'action' => 'teampost', 'params' => array()), array('uri' => '/', 'method' => 'GET', 'controller' => 'main', 'action' => 'index', 'params' => array()));
     foreach ($routes as $route) {
         $_SERVER['REQUEST_METHOD'] = $route['method'];
         $router->handle($route['uri']);
         $this->assertEquals($router->getControllerName(), $route['controller']);
         $this->assertEquals($router->getActionName(), $route['action']);
         $this->assertEquals($router->getParams(), $route['params']);
         $this->assertEquals($router->isExactControllerName(), true);
     }
 }