Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding convenience method to add multiple routes with xmlhttp and req…

…uest type
  • Loading branch information...
commit 80bb9901f6b045512a679f88fd536e80a69dd9ab 1 parent ef5433b
@mAu888 authored
Showing with 32 additions and 1 deletion.
  1. +9 −1 Zurv/Router/Base.php
  2. +23 −0 tests/Zurv/Router/BaseTest.php
View
10 Zurv/Router/Base.php
@@ -32,7 +32,15 @@ public function addRoutes($routes) {
unset($options['controller']);
}
- $this->addRoute($route, $controller, $action, $options);
+ $route = $this->addRoute($route, $controller, $action, $options);
+
+ if(isset($options['isAjax']) && $options['isAjax'] === true) {
+ $route->setRequireXmlHttpRequest(true);
+ }
+
+ if(isset($options['requestTypes']) && is_array($options['requestTypes'])) {
+ call_user_func_array(array($route, 'setRequestTypes'), $options['requestTypes']);
+ }
}
}
View
23 tests/Zurv/Router/BaseTest.php
@@ -190,6 +190,29 @@ function requiringRequestToBeAjaxExpectsRouterToSuccessOnAjaxRequest() {
}
/**
+ * @test
+ **/
+ function assignMultipleRoutesByArraySettingAdditionalRequirements() {
+ $this->_router->addRoutes(
+ array(
+ '/foo/bar' => array(
+ 'controller' => 'Foo',
+ 'action' => 'bar',
+ 'isAjax' => true,
+ 'requestTypes' => array(Route::GET, Route::POST)
+ )
+ )
+ );
+
+ $requestMock = $this->_getRequestMockWithPathControllerAction('/foo/bar', 'Foo', 'bar');
+ $requestMock->expects($this->atLeastOnce())
+ ->method('isXmlHttpRequest')
+ ->will($this->returnValue(true));
+
+ $route = $this->_router->route($requestMock);
+ }
+
+ /**
* Creates a mock object for a \Zurv\Request class instance.
* @param string $path
* @param string $controller
Please sign in to comment.
Something went wrong with that request. Please try again.