Browse Source

test with querystring

Adnan0703 11 years ago
parent
commit
c228082600
2 changed files with 33 additions and 4 deletions
  1. 21 4
      Lib/Routing/UrlCacheManager.php
  2. 12 0
      Test/Case/View/Helper/MyHelperUrlCacheTest.php

+ 21 - 4
Lib/Routing/UrlCacheManager.php

@@ -115,11 +115,8 @@ class UrlCacheManager {
 		if (is_array($keyUrl)) {
 			$keyUrl += static::$extras;
 			// prevent different hashs on different orders
-			ksort($keyUrl, SORT_STRING);
 			// prevent different hashs on different types (int/string/bool)
-			foreach ($keyUrl as $key => $val) {
-				$keyUrl[$key] = (string) $val;
-			}
+			$keyUrl = static::prepareForSerialize($keyUrl);
 		}
 		static::$key = md5(serialize($keyUrl) . $full);
 
@@ -152,5 +149,25 @@ class UrlCacheManager {
 			static::$cache[static::$key] = $data;
 		}
 	}
+	
+	/**
+	*
+	*/
+	public static function prepareForSerialize($array) {
+		if (!is_array($array)) {
+			return $array;
+		}
+		// prevent different hashs on different orders
+		ksort($array, SORT_STRING);
+		// prevent different hashs on different types (int/string/bool)
+		foreach ($array as $key => $val) {
+			if (is_array($val)) {
+				$array[$key] = static::prepareForSerialize($val);
+			} else {
+				$array[$key] = (string) $val;
+			}
+		}
+		return $array;
+	}
 
 }

+ 12 - 0
Test/Case/View/Helper/MyHelperUrlCacheTest.php

@@ -167,5 +167,17 @@ class MyHelperUrlCacheTest extends CakeTestCase {
 		$this->HtmlHelper->afterLayout('foo');
 	}
 
+/**
+*
+*/
+	public function testPaginationUrlsWithQueryString() {
+		$urlArray = array('controller' => 'posts', 'action' => 'list_posts', '?' => ['page' => 2]);
+		$this->HtmlHelper->beforeRender('foo');
+		$url = $this->HtmlHelper->url($urlArray);
+		$this->assertEquals(array('e8383c43f33fcf11621240f22814603b'), array_keys(UrlCacheManager::$cachePage));
+		$this->assertEquals('/posts/list_posts?page=2', $url);
+		
+		$this->HtmlHelper->afterLayout('foo');
+	}
 }