From 4362f7bf8b22baa568d8671f4c5ca3675d077003 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 2 Jun 2014 22:37:37 -0400 Subject: [PATCH] Add tests for CakeRoute::match() and trailing * routes. Add tests for /pages/** routes, and fix coding standards errors. Refs #3581 --- lib/Cake/Routing/Route/CakeRoute.php | 5 ++--- .../Test/Case/Routing/Route/CakeRouteTest.php | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/Cake/Routing/Route/CakeRoute.php b/lib/Cake/Routing/Route/CakeRoute.php index 332aa804cd4..c154871de95 100644 --- a/lib/Cake/Routing/Route/CakeRoute.php +++ b/lib/Cake/Routing/Route/CakeRoute.php @@ -536,11 +536,10 @@ protected function _writeUrl($params) { $out = str_replace($search, $replace, $out); } - if (strpos($this->template, '**')) { + if (strpos($this->template, '**') !== false) { $out = str_replace('**', $params['pass'], $out); $out = str_replace('%2F', '/', $out); - } - elseif (strpos($this->template, '*')) { + } elseif (strpos($this->template, '*') !== false) { $out = str_replace('*', $params['pass'], $out); } $out = str_replace('//', '/', $out); diff --git a/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php b/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php index 375cf4d5969..46c293d9534 100644 --- a/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php +++ b/lib/Cake/Test/Case/Routing/Route/CakeRouteTest.php @@ -873,6 +873,23 @@ public function testMatchSimilarParameters() { $this->assertEquals($expected, $result); } +/** + * Test match() with trailing ** style routes. + * + * @return void + */ + public function testMatchTrailing() { + $route = new CakeRoute('/pages/**', array('controller' => 'pages', 'action' => 'display')); + $id = 'test/ spaces/漢字/la†în'; + $result = $route->match(array( + 'controller' => 'pages', + 'action' => 'display', + $id + )); + $expected = '/pages/test/%20spaces/%E6%BC%A2%E5%AD%97/la%E2%80%A0%C3%AEn'; + $this->assertEquals($expected, $result); + } + /** * test restructuring args with pass key *