Skip to content

Commit

Permalink
add seperate test and unset _name in reverseToArray function
Browse files Browse the repository at this point in the history
  • Loading branch information
Elias De Vos committed Jan 10, 2018
1 parent 87c4af7 commit 8a9e82b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Routing/Router.php
Expand Up @@ -746,7 +746,8 @@ public static function reverseToArray($params)
$params['requested'],
$params['return'],
$params['_Token'],
$params['_matchedRoute']
$params['_matchedRoute'],
$params['_name']
);
$params = array_merge($params, $pass);
if (!empty($url)) {
Expand Down
59 changes: 59 additions & 0 deletions tests/TestCase/Routing/RouteCollectionTest.php
Expand Up @@ -74,6 +74,65 @@ public function testParseMissingRouteMethod()
* @return void
*/
public function testParse()
{
$routes = new RouteBuilder($this->collection, '/b', ['key' => 'value']);
$routes->connect('/', ['controller' => 'Articles']);
$routes->connect('/:id', ['controller' => 'Articles', 'action' => 'view']);
$routes->connect('/media/search/*', ['controller' => 'Media', 'action' => 'search']);

$result = $this->collection->parse('/b/');
$expected = [
'controller' => 'Articles',
'action' => 'index',
'pass' => [],
'plugin' => null,
'key' => 'value',
'_matchedRoute' => '/b',
];
$this->assertEquals($expected, $result);

$result = $this->collection->parse('/b/the-thing?one=two');
$expected = [
'controller' => 'Articles',
'action' => 'view',
'id' => 'the-thing',
'pass' => [],
'plugin' => null,
'key' => 'value',
'?' => ['one' => 'two'],
'_matchedRoute' => '/b/:id',
];
$this->assertEquals($expected, $result);

$result = $this->collection->parse('/b/media/search');
$expected = [
'key' => 'value',
'pass' => [],
'plugin' => null,
'controller' => 'Media',
'action' => 'search',
'_matchedRoute' => '/b/media/search/*',
];
$this->assertEquals($expected, $result);

$result = $this->collection->parse('/b/media/search/thing');
$expected = [
'key' => 'value',
'pass' => ['thing'],
'plugin' => null,
'controller' => 'Media',
'action' => 'search',
'_matchedRoute' => '/b/media/search/*',
];
$this->assertEquals($expected, $result);
}

/**
* Test parsing routes with and without _name.
*
* @return void
*/
public function testParseWithNameParameter()
{
$routes = new RouteBuilder($this->collection, '/b', ['key' => 'value']);
$routes->connect('/', ['controller' => 'Articles']);
Expand Down

0 comments on commit 8a9e82b

Please sign in to comment.