Merge pull request #1524 from natanfelles/test_routes

Test routes resource with 'websafe' option
This commit is contained in:
Instructor, BCIT 2018-11-21 22:41:32 -08:00 committed by GitHub
commit 90f6f37111
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View File

@ -436,7 +436,7 @@ class RouteCollection implements RouteCollectionInterface
/**
* 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
*
@ -722,7 +722,7 @@ class RouteCollection implements RouteCollectionInterface
* 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.
@ -777,7 +777,7 @@ class RouteCollection implements RouteCollectionInterface
* '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...
@ -864,8 +864,8 @@ class RouteCollection implements RouteCollectionInterface
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);

View File

@ -458,6 +458,24 @@ class RouteCollectionTest extends \CIUnitTestCase
//--------------------------------------------------------------------
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';