Skip to content

Instantly share code, notes, and snippets.

@ringmaster
Created August 17, 2011 17:00
Show Gist options
  • Save ringmaster/1152018 to your computer and use it in GitHub Desktop.
Save ringmaster/1152018 to your computer and use it in GitHub Desktop.
/**
* Test matching routes based on HTTP method verbs.
*/
public function testMethodBasedMatching() {
$parameters = array('controller' => 'users', 'action' => 'edit');
$route = new Route(array(
'template' => '/method',
'params' => $parameters + array('http:method' => 'POST')
));
$this->assertFalse($route->match($parameters));
$this->assertEqual('/method', $route->match($parameters + array('http:method' => 'POST')));
$route = new Route(array(
'template' => '/method/{:controller}/{:id:[0-9]+}',
'params' => $parameters + array('http:method' => array('POST', 'PUT'))
));
$this->assertFalse($route->match($parameters));
$this->assertFalse($route->match($parameters + array('id' => '54')));
$this->assertFalse($route->match($parameters + array('id' => '54') + array('http:method' => 'GET')));
$this->assertEqual('/method/users/54', $route->match($parameters + array('id' => '54') + array('http:method' => 'POST')));
$this->assertEqual('/method/users/54', $route->match($parameters + array('id' => '54') + array('http:method' => 'PUT')));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment