예제 #1
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", ''));
 }
예제 #2
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());
 }
예제 #3
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());
 }
예제 #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;
 }