Skip to content

Commit

Permalink
Merge pull request #12580 from beporter/reverse-route-default-match-get
Browse files Browse the repository at this point in the history
Make reverse routes match `[_method => GET]` by default.
  • Loading branch information
markstory committed Sep 24, 2018
2 parents b4809ce + 09f1772 commit d59dfbe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Routing/Route/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ protected function _matchMethod($url)
$url['_method'] = $url['[method]'];
}
if (empty($url['_method'])) {
return false;
$url['_method'] = 'GET';
}
$methods = array_map('strtoupper', (array)$url['_method']);
foreach ($methods as $value) {
Expand Down
18 changes: 18 additions & 0 deletions tests/TestCase/Routing/Route/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,24 @@ public function testMatchWithMultibytePattern()
$this->assertEquals("/articles/view/\xC4\x81", $result);
}

/**
* Test that match() matches explicit GET routes
*
* @return void
*/
public function testMatchWithExplicitGet()
{
$route = new Route(
'/anything',
['controller' => 'Articles', 'action' => 'foo', '_method' => 'GET']
);
$result = $route->match([
'controller' => 'Articles',
'action' => 'foo'
]);
$this->assertEquals("/anything", $result);
}

/**
* Test separartor.
*
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/TestSuite/IntegrationTestTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ public function testAssertTemplateAfterCellRender()
*/
public function testArrayUrls()
{
$this->post(['controller' => 'Posts', 'action' => 'index']);
$this->post(['controller' => 'Posts', 'action' => 'index', '_method' => 'POST']);
$this->assertEquals('value', $this->viewVariable('test'));
}

Expand Down Expand Up @@ -932,10 +932,10 @@ public function testAssertResponseStatusCodes()
public function testAssertRedirect()
{
$this->_response = new Response();
$this->_response = $this->_response->withHeader('Location', 'http://localhost/tasks/index');
$this->_response = $this->_response->withHeader('Location', 'http://localhost/get/tasks/index');

$this->assertRedirect();
$this->assertRedirect('/tasks/index');
$this->assertRedirect('/get/tasks/index');
$this->assertRedirect(['controller' => 'Tasks', 'action' => 'index']);

$this->assertResponseEmpty();
Expand Down

0 comments on commit d59dfbe

Please sign in to comment.