예제 #1
0
 public function testRouteData()
 {
     $data = ["name" => "john", "surname" => "smith"];
     $route = new Route();
     $route->setRouteData($data);
     $this->assertEquals($data, $route->getRouteData());
     $route->setRouteData("invalid");
     $this->assertNull($route->getRouteData());
     $staticRoute = Route::create("a", $data);
     $this->assertEquals($data, $staticRoute->getRouteData());
 }
예제 #2
0
 public function testCreateRoute()
 {
     $route = Route::create("my route");
     $router = new Router();
     $this->assertSame($route, $router->createRoute($route));
     $this->assertInstanceOf('\\Cubex\\Routing\\Route', $router->createRoute("ab", ''));
 }
예제 #3
0
 /**
  * @param $route
  * @param $expect
  *
  * @dataProvider responseProvider
  */
 public function testResponsesWithNoLayout($route, $expect)
 {
     $controller = new TestLayoutController();
     $controller->setCubex(new Cubex());
     $controller->disableLayout();
     $response = $controller->executeRoute(Route::create($route), Request::createFromGlobals(), HttpKernelInterface::MASTER_REQUEST, false);
     $this->assertEquals($expect, $response->getContent());
 }
예제 #4
0
 public function autoRoute(Request $request, $pathParts)
 {
     // check auto-routing
     $method = $this->attemptMethod(head($pathParts), $request);
     if ($method) {
         // remove path upto and including $method
         return Route::create($method, array_slice($pathParts, 1));
     }
     // sub routing
     $classPath = ucfirst(head($pathParts));
     $classPath = ucwords(str_replace(['-', '_'], ' ', $classPath));
     $classPath = str_replace(' ', '', $classPath);
     $namespace = Objects::getNamespace(get_called_class());
     $subRoutes = $this->subRouteTo();
     //No subroutes available
     if ($subRoutes !== null && !empty($subRoutes)) {
         foreach ($subRoutes as $subRoute) {
             //Half sprintf style, but changed to str_replace for multiple instances
             $attempt = Path::buildWindows($namespace, str_replace('%s', $classPath, $subRoute));
             if (class_exists($attempt)) {
                 return Route::create($attempt, array_slice($pathParts, 1), head($pathParts));
             }
         }
     }
     return null;
 }
예제 #5
0
 /**
  * @param CubexKernel $kernel
  * @param             $routeData
  * @param             $expect
  * @param null        $exception
  *
  * @dataProvider executeRouteProvider
  */
 public function testExecuteRoute(CubexKernel $kernel, $routeData, $expect, $exception = null)
 {
     $route = new Route();
     $route->createFromRaw($routeData);
     $request = Request::createFromGlobals();
     $type = Cubex::MASTER_REQUEST;
     $catch = $exception === null;
     if (!$catch) {
         $this->setExpectedException('Exception', $exception);
     }
     $result = $kernel->executeRoute($route, $request, $type, $catch);
     if ($expect instanceof RedirectResponse) {
         $this->assertInstanceOf('\\Symfony\\Component\\HttpFoundation\\RedirectResponse', $result);
         /**
          * @var RedirectResponse $result
          */
         $this->assertEquals($expect->getTargetUrl(), $result->getTargetUrl());
     } else {
         if ($expect instanceof \Symfony\Component\HttpFoundation\Response) {
             $this->assertInstanceOf('\\Symfony\\Component\\HttpFoundation\\Response', $result);
             $this->assertEquals($expect->getContent(), $result->getContent());
         } else {
             if ($result instanceof \Symfony\Component\HttpFoundation\Response) {
                 $this->assertEquals($expect, $result->getContent());
             } else {
                 $this->assertEquals($expect, $result);
             }
         }
     }
 }