Skip to content
Browse files

Merge remote-tracking branch 'origin/2.5' into 3.0

Conflicts:
	lib/Cake/Model/Model.php
  • Loading branch information...
2 parents bba617a + c5b6dda commit eb6b7a440d7a4d05d219b8a081897d2857fcceef @markstory markstory committed
Showing with 43 additions and 20 deletions.
  1. +17 −10 src/Routing/Route/Route.php
  2. +2 −2 src/Utility/Set.php
  3. +1 −1 src/View/Helper/TimeHelper.php
  4. +23 −7 tests/TestCase/Routing/Route/RouteTest.php
View
27 src/Routing/Route/Route.php
@@ -211,6 +211,10 @@ protected function _writeRoute() {
foreach ($this->keys as $key) {
unset($this->defaults[$key]);
}
+
+ $keys = $this->keys;
+ sort($keys);
+ $this->keys = array_reverse($keys);
}
/**
@@ -506,18 +510,21 @@ protected function _writeUrl($params, $pass = array(), $query = array()) {
$pass = implode('/', array_map('rawurlencode', $pass));
$out = $this->template;
- $search = $replace = array();
- foreach ($this->keys as $key) {
- $string = null;
- if (isset($params[$key])) {
- $string = $params[$key];
- } elseif (strpos($out, $key) != strlen($out) - strlen($key)) {
- $key .= '/';
+ if (!empty($this->keys)) {
+ $search = $replace = array();
+
+ foreach ($this->keys as $key) {
+ $string = null;
+ if (isset($params[$key])) {
+ $string = $params[$key];
+ } elseif (strpos($out, $key) != strlen($out) - strlen($key)) {
+ $key .= '/';
+ }
+ $search[] = ':' . $key;
+ $replace[] = $string;
}
- $search[] = ':' . $key;
- $replace[] = $string;
+ $out = str_replace($search, $replace, $out);
}
- $out = str_replace($search, $replace, $out);
if (strpos($this->template, '*')) {
$out = str_replace('*', $pass, $out);
View
4 src/Utility/Set.php
@@ -306,7 +306,7 @@ public static function format($data, $format, $keys) {
* @param string $path An absolute XPath 2.0 path
* @param array $data An array of data to extract from
* @param array $options Currently only supports 'flatten' which can be disabled for higher XPath-ness
- * @return array An array of matched items
+ * @return mixed An array of matched items or the content of a single selected item or null in any of these cases: $path or $data are null, no items found.
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::extract
*/
public static function extract($path, $data = null, $options = array()) {
@@ -531,7 +531,7 @@ public static function matches($conditions, $data = array(), $i = null, $length
*
* @param array $data Array from where to extract
* @param string|array $path As an array, or as a dot-separated string.
- * @return array|null Extracted data or null when $data or $path are empty.
+ * @return mixed An array of matched items or the content of a single selected item or null in any of these cases: $path or $data are null, no items found.
* @link http://book.cakephp.org/2.0/en/core-utility-libraries/set.html#Set::classicExtract
*/
public static function classicExtract($data, $path = null) {
View
2 src/View/Helper/TimeHelper.php
@@ -127,7 +127,7 @@ public function fromString($dateString, $timezone = null) {
*
* @param integer|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object
* @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object
- * @param string $format The format to use. If null, `TimeHelper::$niceFormat` is used
+ * @param string $format The format to use. If null, `CakeTime::$niceFormat` is used
* @return string Formatted date string
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
*/
View
30 tests/TestCase/Routing/Route/RouteTest.php
@@ -1,7 +1,5 @@
<?php
/**
- * Route Test case file.
- *
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
@@ -149,7 +147,7 @@ public function testRouteCompilingWithParamPatterns() {
$this->assertRegExp($result, '/posts/view/518098');
$this->assertNotRegExp($result, '/posts/edit/name-of-post');
$this->assertNotRegExp($result, '/posts/edit/4/other:param');
- $this->assertEquals(array('controller', 'action', 'id'), $route->keys);
+ $this->assertEquals(array('id', 'controller', 'action'), $route->keys);
$route = new Route(
'/:lang/:controller/:action/:id',
@@ -161,7 +159,7 @@ public function testRouteCompilingWithParamPatterns() {
$this->assertRegExp($result, '/cze/articles/view/1');
$this->assertNotRegExp($result, '/language/articles/view/2');
$this->assertNotRegExp($result, '/eng/articles/view/name-of-article');
- $this->assertEquals(array('lang', 'controller', 'action', 'id'), $route->keys);
+ $this->assertEquals(array('lang', 'id', 'controller', 'action'), $route->keys);
foreach (array(':', '@', ';', '$', '-') as $delim) {
$route = new Route('/posts/:id' . $delim . ':title');
@@ -172,7 +170,7 @@ public function testRouteCompilingWithParamPatterns() {
$this->assertNotRegExp($result, '/posts/11!nameofarticle');
$this->assertNotRegExp($result, '/posts/11');
- $this->assertEquals(array('id', 'title'), $route->keys);
+ $this->assertEquals(array('title', 'id'), $route->keys);
}
$route = new Route(
@@ -186,7 +184,7 @@ public function testRouteCompilingWithParamPatterns() {
$this->assertNotRegExp($result, '/posts/hey_now:nameofarticle');
$this->assertNotRegExp($result, '/posts/:nameofarticle/2009');
$this->assertNotRegExp($result, '/posts/:nameofarticle/01');
- $this->assertEquals(array('id', 'title', 'year'), $route->keys);
+ $this->assertEquals(array('year', 'title', 'id'), $route->keys);
$route = new Route(
'/posts/:url_title-(uuid::id)',
@@ -235,7 +233,7 @@ public function testComplexRouteCompilingAndParsing() {
$this->assertRegExp($result, '/some_extra/page/this_is_the_slug');
$this->assertRegExp($result, '/page/this_is_the_slug');
- $this->assertEquals(array('extra', 'slug'), $route->keys);
+ $this->assertEquals(array('slug', 'extra'), $route->keys);
$this->assertEquals(array('extra' => '[a-z1-9_]*', 'slug' => '[a-z1-9_]+', 'action' => 'view'), $route->options);
$expected = array(
'controller' => 'pages',
@@ -742,6 +740,24 @@ public function testParsePassedArgument() {
}
/**
+ * Test matching of parameters where one parameter name starts with another parameter name
+ *
+ * @return void
+ */
+ public function testMatchSimilarParameters() {
+ $route = new Route('/:thisParam/:thisParamIsLonger');
+
+ $url = array(
+ 'thisParamIsLonger' => 'bar',
+ 'thisParam' => 'foo',
+ );
+
+ $result = $route->match($url);
+ $expected = '/foo/bar';
+ $this->assertEquals($expected, $result);
+ }
+
+/**
* test restructuring args with pass key
*
* @return void

0 comments on commit eb6b7a4

Please sign in to comment.
Something went wrong with that request. Please try again.