Skip to content
Permalink
Browse files

Adding a _matchedRoute request param for debugging purposes

  • Loading branch information...
lorenzo committed May 28, 2016
1 parent 4164c0f commit c04fa8d8b800fa1cf6b9ca798e385d85ad946ec5
@@ -325,6 +325,8 @@ public function parse($url)
}
}
}
$route['_matchedRoute'] = $this->template;
return $route;
}
@@ -701,7 +701,8 @@ public static function reverse($params, $full = false)
$params['bare'],
$params['requested'],
$params['return'],
$params['_Token']
$params['_Token'],
$params['_matchedRoute']
);
$params = array_merge($params, $pass);
if (!empty($url)) {
@@ -60,6 +60,9 @@ public function check($url)
break;
}
}
unset($route['_matchedRoute']);
$output = [
['Route name', 'URI template', 'Defaults'],
[$name, $url, json_encode($route)]
@@ -242,13 +242,14 @@ public function testComplexRouteCompilingAndParsing()
$this->assertRegExp($result, '/posts/08/01/2007/title-of-post');
$result = $route->parse('/posts/08/01/2007/title-of-post');
$this->assertEquals(count($result), 6);
$this->assertEquals(count($result), 7);
$this->assertEquals($result['controller'], 'posts');
$this->assertEquals($result['action'], 'view');
$this->assertEquals($result['year'], '2007');
$this->assertEquals($result['month'], '08');
$this->assertEquals($result['day'], '01');
$this->assertEquals($result['pass'][0], 'title-of-post');
$this->assertEquals($result['_matchedRoute'], '/posts/:month/:day/:year/*');
$route = new Route(
"/:extra/page/:slug/*",
@@ -780,6 +781,7 @@ public function testParseWithPassDefaults()
'controller' => 'posts',
'action' => 'display',
'pass' => ['home'],
'_matchedRoute' => '/:controller'
];
$this->assertEquals($expected, $result);
}
@@ -801,6 +803,7 @@ public function testParseWithHttpHeaderConditions()
'action' => 'index',
'pass' => [],
'_method' => 'POST',
'_matchedRoute' => '/sample'
];
$this->assertEquals($expected, $route->parse('/sample'));
}
@@ -826,6 +829,7 @@ public function testParseWithMultipleHttpMethodConditions()
'action' => 'index',
'pass' => [],
'_method' => ['PUT', 'POST'],
'_matchedRoute' => '/sample'
];
$this->assertEquals($expected, $route->parse('/sample'));
}
@@ -917,7 +921,12 @@ public function testPatternOnAction()
$this->assertNotEmpty($result);
$result = $route->parse('/blog/other');
$expected = ['controller' => 'blog_posts', 'action' => 'other', 'pass' => []];
$expected = [
'controller' => 'blog_posts',
'action' => 'other',
'pass' => [],
'_matchedRoute' => '/blog/:action/*'
];
$this->assertEquals($expected, $result);
$result = $route->parse('/blog/foobar');
@@ -937,6 +946,7 @@ public function testParsePassedArgument()
'controller' => 'posts',
'action' => 'edit',
'pass' => ['1', '2', '0'],
'_matchedRoute' => '/:controller/:action/*'
];
$this->assertEquals($expected, $result);
}
@@ -994,6 +1004,7 @@ public function testPassArgRestructure()
'action' => 'view',
'slug' => 'my-title',
'pass' => ['my-title'],
'_matchedRoute' => '/:controller/:action/:slug'
];
$this->assertEquals($expected, $result, 'Slug should have moved');
}
@@ -1011,6 +1022,7 @@ public function testParseTrailing()
'controller' => 'posts',
'action' => 'index',
'pass' => ['1/2/3/foo:bar'],
'_matchedRoute' => '/:controller/:action/**',
];
$this->assertEquals($expected, $result);
@@ -1019,6 +1031,7 @@ public function testParseTrailing()
'controller' => 'posts',
'action' => 'index',
'pass' => ['http://example.com'],
'_matchedRoute' => '/:controller/:action/**',
];
$this->assertEquals($expected, $result);
}
@@ -1036,6 +1049,7 @@ public function testParseTrailingUTF8()
'controller' => 'categories',
'action' => 'index',
'pass' => ['موبایل'],
'_matchedRoute' => '/category/**',
];
$this->assertEquals($expected, $result);
}
@@ -1138,11 +1152,25 @@ public function testUTF8PatternOnSection()
);
$result = $route->parse('/%D8%A2%D9%85%D9%88%D8%B2%D8%B4');
$expected = ['section' => 'آموزش', 'plugin' => 'blogs', 'controller' => 'posts', 'action' => 'index', 'pass' => []];
$expected = [
'section' => 'آموزش',
'plugin' => 'blogs',
'controller' => 'posts',
'action' => 'index',
'pass' => [],
'_matchedRoute' => '/:section',
];
$this->assertEquals($expected, $result);
$result = $route->parse('/weblog');
$expected = ['section' => 'weblog', 'plugin' => 'blogs', 'controller' => 'posts', 'action' => 'index', 'pass' => []];
$expected = [
'section' => 'weblog',
'plugin' => 'blogs',
'controller' => 'posts',
'action' => 'index',
'pass' => [],
'_matchedRoute' => '/:section',
];
$this->assertEquals($expected, $result);
}
@@ -1191,7 +1219,12 @@ public function testSetState()
$this->assertInstanceOf('Cake\Routing\Route\Route', $route);
$this->assertSame('/', $route->match(['controller' => 'pages', 'action' => 'display', 'home']));
$this->assertFalse($route->match(['controller' => 'pages', 'action' => 'display', 'about']));
$expected = ['controller' => 'pages', 'action' => 'display', 'pass' => ['home']];
$expected = [
'controller' => 'pages',
'action' => 'display',
'pass' => ['home'],
'_matchedRoute' => '/',
];
$this->assertEquals($expected, $route->parse('/'));
}
}
@@ -158,7 +158,13 @@ public function testConnectTrimTrailingSlash()
$routes = new RouteBuilder($this->collection, '/articles', ['controller' => 'Articles']);
$routes->connect('/', ['action' => 'index']);
$expected = ['plugin' => null, 'controller' => 'Articles', 'action' => 'index', 'pass' => []];
$expected = [
'plugin' => null,
'controller' => 'Articles',
'action' => 'index',
'pass' => [],
'_matchedRoute' => '/articles',
];
$this->assertEquals($expected, $this->collection->parse('/articles'));
$this->assertEquals($expected, $this->collection->parse('/articles/'));
}
@@ -68,6 +68,7 @@ public function testParse()
'pass' => [],
'plugin' => null,
'key' => 'value',
'_matchedRoute' => '/b',
];
$this->assertEquals($expected, $result);
@@ -80,6 +81,7 @@ public function testParse()
'plugin' => null,
'key' => 'value',
'?' => ['one' => 'two'],
'_matchedRoute' => '/b/:id',
];
$this->assertEquals($expected, $result);
@@ -89,7 +91,8 @@ public function testParse()
'pass' => [],
'plugin' => null,
'controller' => 'Media',
'action' => 'search'
'action' => 'search',
'_matchedRoute' => '/b/media/search/*',
];
$this->assertEquals($expected, $result);
@@ -99,7 +102,8 @@ public function testParse()
'pass' => ['thing'],
'plugin' => null,
'controller' => 'Media',
'action' => 'search'
'action' => 'search',
'_matchedRoute' => '/b/media/search/*',
];
$this->assertEquals($expected, $result);
}
@@ -121,9 +125,10 @@ public function testParseEncodedBytesInFixedSegment()
'plugin' => null,
'controller' => 'Events',
'action' => 'index',
'day' => 15,
'day' => '15',
'month' => 'октомври',
'?' => ['test' => 'foo'],
'_matchedRoute' => '/ден/:day-:month',
];
$this->assertEquals($expected, $result);
}
@@ -146,7 +151,9 @@ public function testParseFallback()
'controller' => 'Articles',
'action' => 'add',
'plugin' => null,
'pass' => []
'pass' => [],
'_matchedRoute' => '/:controller/:action',
];
$this->assertEquals($expected, $result);
}
Oops, something went wrong.

0 comments on commit c04fa8d

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