Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added additional tests to route

  • Loading branch information...
commit f793c4f41a7e82e8efa8f3ee325a5183b8c24b76 1 parent 5c61d35
@bquilitz bquilitz authored
Showing with 54 additions and 37 deletions.
  1. +54 −37 tests/cases/net/http/RouteTest.php
View
91 tests/cases/net/http/RouteTest.php
@@ -547,57 +547,74 @@ public function testMatchingEmptyRoute() {
* Test route matching for routes with specified request method (http:method)
*/
public function testMatchWithRequestMethod() {
- $parameters = array('controller' => 'resource', 'action' => 'create');
+ $parameters = array('controller' => 'resource', 'action' => 'create');
- $route = new Route(array(
- 'template' => '/resource',
- 'params' => $parameters + array('http:method' => 'POST')
- ));
+ $route = new Route(array(
+ 'template' => '/resource',
+ 'params' => $parameters + array('http:method' => 'POST')
+ ));
- //success
- $result = $route->match(array('controller' => 'resource', 'action' => 'create', 'http:method' => 'POST'));
- $this->assertEqual('/resource', $result);
+ //success
+ $result = $route->match(array('controller' => 'resource', 'action' => 'create', 'http:method' => 'POST'));
+ $this->assertEqual('/resource', $result);
- // no match because of missing POST
- $result = $route->match(array('controller' => 'resource', 'action' => 'create'));
- $this->assertEqual(false, $result);
+ // no match because of missing POST
+ $result = $route->match(array('controller' => 'resource', 'action' => 'create'));
+ $this->assertEqual(false, $result);
- // we test params in route here because this made a difference in the original li3 routing implementation
- $route = new Route(array(
- 'template' => '/{:param}',
- 'params' => $parameters + array('http:method' => 'POST')
- ));
+ // we test params in route here because this made a difference in the original li3 routing implementation
+ $route = new Route(array(
+ 'template' => '/{:param}',
+ 'params' => $parameters + array('http:method' => 'POST')
+ ));
- $result = $route->match(array('controller' => 'resource', 'action' => 'create', 'param' => 'value', 'http:method' => 'POST'));
- $this->assertEqual('/value', $result);
+ $result = $route->match(array('controller' => 'resource', 'action' => 'create', 'param' => 'value', 'http:method' => 'POST'));
+ $this->assertEqual('/value', $result);
- // no match because of missing POST
- $result = $route->match(array('controller' => 'resource', 'action' => 'create', 'param' => 'value'));
- $this->assertEqual(false, $result);
+ // no match because of missing POST
+ $result = $route->match(array('controller' => 'resource', 'action' => 'create', 'param' => 'value'));
+ $this->assertEqual(false, $result);
- $route = new Route(array(
- 'template' => '/resource',
- 'params' => $parameters + array('http:method' => 'GET')
- ));
+ // route without request method matches all
+ $route = new Route(array(
+ 'template' => '/resource',
+ 'params' => $parameters
+ ));
- //success
- $result = $route->match(array('controller' => 'resource', 'action' => 'create', 'http:method' => 'GET'));
- $this->assertEqual('/resource', $result);
+ $result = $route->match(array('controller' => 'resource', 'action' => 'create'));
+ $this->assertEqual('/resource', $result);
+ $result = $route->match(array('controller' => 'resource', 'action' => 'create', 'http:method' => 'GET'));
+ $this->assertEqual('/resource', $result);
+ $result = $route->match(array('controller' => 'resource', 'action' => 'create', 'http:method' => 'POST'));
+ $this->assertEqual('/resource', $result);
+ $result = $route->match(array('controller' => 'resource', 'action' => 'create', 'http:method' => 'PUT'));
+ $this->assertEqual('/resource', $result);
- // success even with missing GET because it's the default
- $result = $route->match(array('controller' => 'resource', 'action' => 'create'));
- $this->assertEqual('/resource', $result);
- // other request methods should fail
- $result = $route->match(array('controller' => 'resource', 'action' => 'create', 'http:method' => 'POST'));
- $this->assertEqual(false, $result);
- $result = $route->match(array('controller' => 'resource', 'action' => 'create', 'http:method' => 'PUT'));
- $this->assertEqual(false, $result);
+ // Test route with request method GET
+ $route = new Route(array(
+ 'template' => '/resource',
+ 'params' => $parameters + array('http:method' => 'GET')
+ ));
+ //success
+ $result = $route->match(array('controller' => 'resource', 'action' => 'create', 'http:method' => 'GET'));
+ $this->assertEqual('/resource', $result);
- }
+ // success even with missing GET because it's the default
+ $result = $route->match(array('controller' => 'resource', 'action' => 'create'));
+ $this->assertEqual('/resource', $result);
+
+ // other request methods should fail
+ $result = $route->match(array('controller' => 'resource', 'action' => 'create', 'http:method' => 'POST'));
+ $this->assertEqual(false, $result);
+ $result = $route->match(array('controller' => 'resource', 'action' => 'create', 'http:method' => 'PUT'));
+ $this->assertEqual(false, $result);
+
+
+ }
Please sign in to comment.
Something went wrong with that request. Please try again.