Пример #1
0
 public function testShouldUseDefaultActionForRouteWithoutActionInPaths()
 {
     $router = new \Vegas\Mvc\Router\Adapter\Standard(DI::getDefault());
     $route = new Route('def', ['paths' => ['module' => 'Def', 'controller' => 'DefController', 'action' => 'def']]);
     $defaultRoute = new Route\DefaultRoute();
     $defaultRoute->add($router, $route);
     $testRoute = new Route('test', ['route' => '/test', 'paths' => ['module' => 'Test', 'controller' => 'TestCon'], 'params' => ['param' => 'value']]);
     $baseRoute = new Route\BaseRoute();
     $baseRoute->add($router, $testRoute);
     $router->handle('/test');
     $matchedRoute = $router->getMatchedRoute();
     $this->assertEquals($route->getPaths()['action'], $router->getActionName());
     $this->assertEquals($testRoute->getPaths()['controller'], $router->getControllerName());
     $this->assertEquals($testRoute->getPaths()['module'], $router->getModuleName());
     $this->assertEquals($testRoute->getRoute(), $matchedRoute->getPattern());
     $this->assertEquals($testRoute->getPaths()['controller'], $matchedRoute->getPaths()['controller']);
     $this->assertEquals($testRoute->getPaths()['module'], $matchedRoute->getPaths()['module']);
     $this->assertArrayNotHasKey('action', $testRoute->getPaths());
 }
Пример #2
0
 public function testShouldMatchBaseRoute()
 {
     $router = new \Vegas\Mvc\Router\Adapter\Standard(DI::getDefault());
     $route = new Route('test', ['route' => '/test', 'paths' => ['module' => 'Test', 'controller' => 'TestCon', 'action' => 'test'], 'params' => ['param' => 'value', 'hostname' => 'test.localhost']]);
     $baseRoute = new BaseRoute();
     $baseRoute->add($router, $route);
     //note. the HTTP_HOST is empty atm
     $router->handle('/test');
     $this->assertNull($router->getMatchedRoute());
     //hardcode the HTTP_HOST
     $_SERVER['HTTP_HOST'] = 'test.localhost';
     $router->handle('/test');
     $matchedRoute = $router->getMatchedRoute();
     $this->assertNotNull($matchedRoute);
     $this->assertEquals($route->getName(), $matchedRoute->getName());
     $this->assertEquals($matchedRoute->getPaths()['module'], $route->getPaths()['module']);
     $this->assertEquals($matchedRoute->getPaths()['controller'], $route->getPaths()['controller']);
     $this->assertEquals($matchedRoute->getPaths()['action'], $route->getPaths()['action']);
     $this->assertEquals($route->getRoute(), $matchedRoute->getPattern());
 }