public function testShouldFindLocaleFromRequest()
 {
     $requestFactory = new RequestFactory();
     $localeFinder = new LocaleFinder($requestFactory->get());
     $locale = $localeFinder->get('en-gb');
     $this->assertThat($locale, $this->equalTo('en_gb'));
     $this->assertThat($localeFinder->getRequest()->getRequestURI(RequestParameter::REQUEST_LOCALE), $this->equalTo('en-gb'));
 }
 public function testShouldFindControllerNameFromRequest()
 {
     $requestFactory = new RequestFactory();
     $controllerFinder = new ControllerFinder($requestFactory->get());
     $controller = $controllerFinder->get('amazing');
     $this->assertThat($controller, $this->equalTo('AmazingController'));
     $this->assertThat($controllerFinder->getRequest()->getRequestURI(RequestParameter::REQUEST_CONTROLLER), $this->equalTo('amazing'));
 }
 public function testShouldFindSimpleActionFromRequest()
 {
     $requestFactory = new RequestFactory();
     $actionFinder = new SimpleActionFinder($requestFactory->get());
     $action = $actionFinder->get('do-something');
     $this->assertThat($action, $this->equalTo('doSomethingAction'));
     $this->assertThat($actionFinder->getRequest()->getRequestURI(RequestParameter::REQUEST_ACTION), $this->equalTo('do-something'));
 }
 public function testShouldFindResourceActionFromRequestByDelete()
 {
     $_SERVER['REQUEST_METHOD'] = 'DELETE';
     $requestFactory = new RequestFactory();
     $actionFinder = new ResourceActionFinder($requestFactory->get());
     $action = $actionFinder->get('do-something-now');
     $this->assertThat($action, $this->equalTo('doSomethingNowDeleteAction'));
     $this->assertThat($actionFinder->getRequest()->getRequestURI(RequestParameter::REQUEST_ACTION), $this->equalTo('do-something-now'));
 }
 public function testShouldFindParametersFromRequest()
 {
     $arguments = ['arg0', 'arg1', 'arg2'];
     $requestFactory = new RequestFactory();
     $parameterFinder = new ParameterFinder($requestFactory->get());
     $parameters = $parameterFinder->get($arguments);
     $this->assertThat(count($arguments), $this->greaterThan(0));
     foreach ($arguments as $argument) {
         $this->assertThat($parameters, $this->contains($argument), 'Attribute was not mapped properly!');
     }
     $this->assertThat($parameterFinder->getRequest()->getRequestURI(RequestParameter::REQUEST_ACTION_PARAMETERS), $this->equalTo('arg0/arg1/arg2'));
 }
 public function testShouldBuildRouteToRequest()
 {
     // Simulates a GET request
     $_SERVER["SCRIPT_NAME"] = "http://localhost/app/index.php";
     $_SERVER["REQUEST_URI"] = "http://localhost/app/pt-br/test/test/attribute1/attribute2";
     $_SERVER["REQUEST_METHOD"] = "GET";
     $requestFactory = new RequestFactory();
     $dispatcherHelper = DispatcherHelper::getHelper($requestFactory->get()->toArray(), true);
     $localeFinder = FinderFactory::getLocaleFinder($requestFactory);
     $controllerFinder = FinderFactory::getControllerFinder($requestFactory);
     $actionFinder = FinderFactory::getActionFinder($requestFactory);
     $parameterFinder = FinderFactory::getParameterFinder($requestFactory);
     $routeBuilder = new I18nRouteBuilder($localeFinder, $controllerFinder, $actionFinder, $parameterFinder);
     $route = $routeBuilder->locale($dispatcherHelper->getLocale())->controller($dispatcherHelper->getController())->action($dispatcherHelper->getAction())->parameters($dispatcherHelper->getParameters())->build();
     $this->assertThat($route->locale, $this->equalTo("pt_br"), "Locale is not translated correctly!");
     $this->assertThat($route->controller, $this->equalTo("TestController"), "Controller is not translated correctly!");
     $this->assertThat($route->action, $this->equalTo("testAction"), "Action is not translated correctly!");
     $this->assertThat($route->parameters[0], $this->logicalNot($this->isNull()), "Parameter 1 is not translated correctly!");
     $this->assertThat($route->parameters[1], $this->logicalNot($this->isNull()), "Parameter 2 is not translated correctly!");
 }