Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding test cases from Javascript Helper. Preparing for refactor of

JsHelper::object().
  • Loading branch information...
commit b90b7438535418170a2bc8cc3b07ceb1bf2460db 1 parent 9c51f72
@markstory markstory authored
Showing with 54 additions and 0 deletions.
  1. +54 −0 cake/tests/cases/libs/view/helpers/js.test.php
View
54 cake/tests/cases/libs/view/helpers/js.test.php
@@ -388,6 +388,60 @@ function testObject() {
}
}
/**
+ * test compatibility of JsBaseEngineHelper::object() vs. json_encode()
+ *
+ * @return void
+ **/
+ function testObjectAgainstJsonEncode() {
+ $skip = $this->skipIf(!function_exists('json_encode'), 'json_encode() not found, comparison tests skipped. %s');
+ if ($skip) {
+ return;
+ }
+ $this->JsEngine->useNative = false;
+ $data = array();
+ $data['mystring'] = "simple string";
+ $this->assertEqual(json_encode($data), $this->JsEngine->object($data));
+
+ $data['mystring'] = "strïng with spécial chârs";
+ $this->assertEqual(json_encode($data), $this->JsEngine->object($data));
+
+ $data['mystring'] = "a two lines\nstring";
+ $this->assertEqual(json_encode($data), $this->JsEngine->object($data));
+
+ $data['mystring'] = "a \t tabbed \t string";
+ $this->assertEqual(json_encode($data), $this->JsEngine->object($data));
+
+ $data['mystring'] = "a \"double-quoted\" string";
+ $this->assertEqual(json_encode($data), $this->JsEngine->object($data));
+
+ $data['mystring'] = 'a \\"double-quoted\\" string';
+ $this->assertEqual(json_encode($data), $this->JsEngine->object($data));
+ }
+/**
+ * test that JSON made with JsBaseEngineHelper::object() against json_decode()
+ *
+ * @return void
+ **/
+ function testObjectAgainstJsonDecode() {
+ $skip = $this->skipIf(!function_exists('json_encode'), 'json_encode() not found, comparison tests skipped. %s');
+ if ($skip) {
+ return;
+ }
+ $this->JsEngine->useNative = false;
+
+ $data = array("simple string");
+ $result = $this->JsEngine->object($data);
+ $this->assertEqual(json_decode($result), $data);
+
+ $data = array('my \"string\"');
+ $result = $this->JsEngine->object($data);
+ $this->assertEqual(json_decode($result), $data);
+
+ $data = array('my \\"string\\"');
+ $result = $this->JsEngine->object($data);
+ $this->assertEqual(json_decode($result), $data);
+ }
+/**
* test Mapping of options.
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.