Skip to content
Permalink
Browse files

Adding test cases from Javascript Helper. Preparing for refactor of

JsHelper::object().
  • Loading branch information...
markstory committed Jul 11, 2009
1 parent 9c51f72 commit b90b7438535418170a2bc8cc3b07ceb1bf2460db
Showing with 54 additions and 0 deletions.
  1. +54 −0 cake/tests/cases/libs/view/helpers/js.test.php
@@ -387,6 +387,60 @@ function testObject() {
$this->assertEqual($result, $expected);
}
}
/**
* 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.
*

0 comments on commit b90b743

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