Skip to content
Permalink
Browse files

Add tests for type + method conditions.

  • Loading branch information...
markstory committed Jul 15, 2012
1 parent a08f4e7 commit a203d67ee85ed2bf0c5fa494e6dd362b7ca0921b
Showing with 69 additions and 3 deletions.
  1. +2 −2 lib/Cake/Routing/Route/Route.php
  2. +67 −1 lib/Cake/Test/TestCase/Routing/Route/RouteTest.php
@@ -141,8 +141,8 @@ public function compiled() {
}
/**
* Compiles the route's regular expression. Modifies defaults property so all necessary keys are set
* and populates $this->names with the named routing elements.
* Compiles the route's regular expression. Modifies defaults property so all necessary
* keys are set and populates $this->names with the named routing elements.
*
* @return array Returns a string regular expression of the compiled route.
*/
@@ -634,9 +634,75 @@ public function testParseWithPassDefaults() {
*/
public function testParseWithHttpHeaderConditions() {
$_SERVER['REQUEST_METHOD'] = 'GET';
$route = new Route('/sample', array('controller' => 'posts', 'action' => 'index', '[method]' => 'POST'));
$route = new Route('/sample', ['controller' => 'posts', 'action' => 'index', '[method]' => 'POST']);
$this->assertFalse($route->parse('/sample'));
$_SERVER['REQUEST_METHOD'] = 'POST';
$expected = [
'controller' => 'posts',
'action' => 'index',
'pass' => [],
'[method]' => 'POST',
];
$this->assertEquals($expected, $route->parse('/sample'));
}
/**
* test that http header conditions can cause route failures.
*
* @return void
*/
public function testParseWithMultipleHttpMethodConditions() {
$_SERVER['REQUEST_METHOD'] = 'GET';
$route = new Route('/sample', [
'controller' => 'posts',
'action' => 'index',
'[method]' => ['PUT', 'POST']
]);
$this->assertFalse($route->parse('/sample'));
$_SERVER['REQUEST_METHOD'] = 'POST';
$expected = [
'controller' => 'posts',
'action' => 'index',
'pass' => [],
'[method]' => ['PUT', 'POST'],
];
$this->assertEquals($expected, $route->parse('/sample'));
}
/**
* Test that the [type] condition works.
*
* @return void
*/
public function testParseWithContentTypeCondition() {
$_SERVER['REQUEST_METHOD'] = 'POST';
unset($_SERVER['CONTENT_TYPE']);
$route = new Route('/sample', [
'controller' => 'posts',
'action' => 'index',
'[method]' => 'POST',
'[type]' => 'application/xml'
]);
$this->assertFalse($route->parse('/sample'), 'No content type set.');
$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['CONTENT_TYPE'] = 'application/json';
$this->assertFalse($route->parse('/sample'), 'Wrong content type set.');
$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['CONTENT_TYPE'] = 'application/xml';
$expected = [
'controller' => 'posts',
'action' => 'index',
'pass' => [],
'[method]' => 'POST',
'[type]' => 'application/xml',
];
$this->assertEquals($expected, $route->parse('/sample'));
}
/**

0 comments on commit a203d67

Please sign in to comment.
You can’t perform that action at this time.