Skip to content
Permalink
Browse files

Add tests for match().

  • Loading branch information...
markstory committed Jun 24, 2014
1 parent 66314da commit 655bbe9b6e473b28e6853dacb1b1f205678c36d5
Showing with 35 additions and 7 deletions.
  1. +8 −7 src/Routing/ScopedRouteCollection.php
  2. +27 −0 tests/TestCase/Routing/ScopedRouteCollectionTest.php
@@ -497,16 +497,17 @@ public function parse($url) {
list($url, $queryParameters) = explode('?', $url, 2);
parse_str($queryParameters, $queryParameters);
}
$out = array();
$out = [];
for ($i = 0, $len = count($this->_routes); $i < $len; $i++) {
$r = $this->_routes[$i]->parse($url);
if ($r !== false && $queryParameters) {
$r['?'] = $queryParameters;
return $r;
if ($r === false) {
continue;
}
if ($r !== false) {
if ($queryParameters) {
$r['?'] = $queryParameters;
return $r;
}
return $r;
}
return $out;
}
@@ -518,7 +519,7 @@ public function parse($url) {
* @param array $url The url to match.
* @param array $context The request context to use. Contains _base, _port,
* _host, and _scheme keys.
* @return void
* @return string|false Either a string on match, or false on failure.
*/
public function match($url, $context) {
foreach ($this->_getNames($url) as $name) {
@@ -532,7 +533,7 @@ public function match($url, $context) {
}
}
}
return '/';
return false;
}
/**
@@ -261,4 +261,31 @@ public function testParse() {
$this->assertEquals($expected, $result);
}
/**
* Test matching routes.
*
* @return void
*/
public function testMatch() {
$context = [
'_base' => '/',
'_scheme' => 'http',
'_host' => 'example.org',
];
$routes = new ScopedRouteCollection('/b');
$routes->connect('/', ['controller' => 'Articles']);
$routes->connect('/:id', ['controller' => 'Articles', 'action' => 'view']);
$result = $routes->match(['plugin' => null, 'controller' => 'Articles', 'action' => 'index'], $context);
$this->assertEquals('b', $result);
$result = $routes->match(
['id' => 'thing', 'plugin' => null, 'controller' => 'Articles', 'action' => 'view'],
$context);
$this->assertEquals('b/thing', $result);
$result = $routes->match(['plugin' => null, 'controller' => 'Articles', 'action' => 'add'], $context);
$this->assertFalse($result, 'No matches');
}
}

0 comments on commit 655bbe9

Please sign in to comment.
You can’t perform that action at this time.