Skip to content

Commit

Permalink
Merge pull request #1524 from natanfelles/test_routes
Browse files Browse the repository at this point in the history
Test routes resource with 'websafe' option
  • Loading branch information
jim-parry authored Nov 22, 2018
2 parents 3a3218f + a1d03e0 commit 90f6f37
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ protected function discoverRoutes()

/**
* Sets the default constraint to be used in the system. Typically
* for use with the 'resources' method.
* for use with the 'resource' method.
*
* @param string $placeholder
*
Expand Down Expand Up @@ -722,7 +722,7 @@ public function getRedirectCode(string $from): int
* Example:
* // Creates route: admin/users
* $route->group('admin', function() {
* $route->resources('users');
* $route->resource('users');
* });
*
* @param string $name The name to group/prefix the routes with.
Expand Down Expand Up @@ -777,7 +777,7 @@ public function group($name, ...$params)
* 'placeholder' - The regex used by the Router. Defaults to '(:any)'
*
* Example:
* $route->resources('photos');
* $route->resource('photos');
*
* // Generates the following routes:
* HTTP Verb | Path | Action | Used for...
Expand Down Expand Up @@ -864,8 +864,8 @@ public function resource(string $name, array $options = null): RouteCollectionIn
if (in_array('update', $methods))
{
$this->put($name . '/' . $id, $new_name . '::update/$1', $options);
$this->patch($name . '/' . $id, $new_name . '::update/$1', $options);
}
$this->patch($name . '/' . $id, $new_name . '::update/$1', $options);
if (in_array('delete', $methods))
{
$this->delete($name . '/' . $id, $new_name . '::delete/$1', $options);
Expand Down
18 changes: 18 additions & 0 deletions tests/system/Router/RouteCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,24 @@ public function testResourcesWithExcept()

//--------------------------------------------------------------------

public function testResourcesWithWebsafe()
{
$_SERVER['REQUEST_METHOD'] = 'POST';
$routes = $this->getCollector();

$routes->resource('photos', ['websafe' => true]);

$expected = [
'photos' => '\Photos::create',
'photos/(.*)' => '\Photos::update/$1',
'photos/(.*)/delete' => '\Photos::delete/$1',
];

$this->assertEquals($expected, $routes->getRoutes());
}

//--------------------------------------------------------------------

public function testMatchSupportsMultipleMethods()
{
$_SERVER['REQUEST_METHOD'] = 'GET';
Expand Down

0 comments on commit 90f6f37

Please sign in to comment.