mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Adding test cases from Javascript Helper. Preparing for refactor of
JsHelper::object().
This commit is contained in:
parent
9c51f720ed
commit
b90b743853
1 changed files with 54 additions and 0 deletions
|
@ -387,6 +387,60 @@ class JsBaseEngineTestCase extends CakeTestCase {
|
||||||
$this->assertEqual($result, $expected);
|
$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.
|
* test Mapping of options.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue