Skip to content

Commit

Permalink
fixed JSON test cases
Browse files Browse the repository at this point in the history
seems like phpunit will not run all test classes inside a file when
giving it as an argument :-/

I removed the error supression tests as these test a feature we do not
have in our JSON class version (and shouldn't implement to keep as
compatible as possible to the native JSON functions)
  • Loading branch information
splitbrain committed May 2, 2012
1 parent 132fb7d commit 68fd957
Showing 1 changed file with 8 additions and 48 deletions.
56 changes: 8 additions & 48 deletions _test/tests/inc/json.test.php
Expand Up @@ -144,7 +144,7 @@ class JSON_AssocArray_TestCase extends DokuWikiTest {
function setUp() {
parent::setUp();

$this->json_l = new JSON(SERVICES_JSON_LOOSE_TYPE);
$this->json_l = new JSON(JSON_LOOSE_TYPE);
$this->json_l->skipnative = true;
$this->json_s = new JSON();
$this->json_s->skipnative = true;
Expand Down Expand Up @@ -196,7 +196,7 @@ class JSON_NestedArray_TestCase extends DokuWikiTest {
function setUp() {
parent::setUp();

$this->json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$this->json = new JSON(JSON_LOOSE_TYPE);
$this->json->skipnative = true;

$this->str1 = '[{"this":"that"}]';
Expand Down Expand Up @@ -269,9 +269,9 @@ class JSON_Object_TestCase extends DokuWikiTest {
function setUp() {
parent::setUp();

$this->json_l = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$this->json_l = new JSON(JSON_LOOSE_TYPE);
$this->json_l->skipnative = true;
$this->json_s = new Services_JSON();
$this->json_s = new JSON();
$this->json_s->skipnative = true;

$this->obj_j = '{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"obj":{"a_number":123}}';
Expand Down Expand Up @@ -305,7 +305,7 @@ class JSON_Spaces_Comments_TestCase extends DokuWikiTest {
function setUp() {
parent::setUp();

$this->json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$this->json = new JSON(JSON_LOOSE_TYPE);
$this->json->skipnative = true;

$this->obj_j = '{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"obj":{"a_number":123}}';
Expand Down Expand Up @@ -350,10 +350,10 @@ class JSON_Empties_TestCase extends DokuWikiTest {
function setUp() {
parent::setUp();

$this->json_l = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$this->json_l = new JSON(JSON_LOOSE_TYPE);
$this->json_l->skipnative = true;
$this->json_l->skipnative = true;
$this->json_s = new Services_JSON();
$this->json_s = new JSON();
$this->json_s->skipnative = true;

$this->obj0_j = '{}';
Expand Down Expand Up @@ -392,7 +392,7 @@ class JSON_UnquotedKeys_TestCase extends DokuWikiTest {
function setUp() {
parent::setUp();

$this->json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$this->json = new JSON(JSON_LOOSE_TYPE);
$this->json->skipnative = true;

$this->arn = array(0=> array(0=> 'tan', 'model' => 'sedan'), 1 => array(0 => 'red', 'model' => 'sports'));
Expand All @@ -413,43 +413,3 @@ function test_from_JSON() {
}
}

class JSON_ErrorSuppression_TestCase extends DokuWikiTest {

function setUp() {
parent::setUp();

$this->json = new Services_JSON();
$this->json->skipnative = true;
$this->json_ = new Services_JSON(SERVICES_JSON_SUPPRESS_ERRORS);
$this->json_->skipnative = true;

$this->res = tmpfile();
$this->res_j_ = 'null';
$this->res_d = 'naked resource';

$this->arr = array('a', 1, tmpfile());
$this->arr_j_ = '["a",1,null]';
$this->arr_d = 'array with string, number and resource';

$obj = new stdClass();
$obj->a_string = '"he":llo}:{world';
$obj->an_array = array(1, 2, 3);
$obj->resource = tmpfile();

$this->obj = $obj;
$this->obj_j_ = '{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"resource":null}';
$this->obj_d = 'object with properties, array, and nested resource';
}

function test_to_JSON() {
$this->assertTrue(Services_JSON::isError($this->json->encode($this->res)), "resource case: {$this->res_d}");
$this->assertTrue(Services_JSON::isError($this->json->encode($this->arr)), "array case: {$this->arr_d}");
$this->assertTrue(Services_JSON::isError($this->json->encode($this->obj)), "object case: {$this->obj_d}");
}

function test_to_JSON_suppressed() {
$this->assertEquals($this->res_j_, $this->json_->encode($this->res), "resource case: {$this->res_d}");
$this->assertEquals($this->arr_j_, $this->json_->encode($this->arr), "array case: {$this->arr_d}");
$this->assertEquals($this->obj_j_, $this->json_->encode($this->obj), "object case: {$this->obj_d}");
}
}

0 comments on commit 68fd957

Please sign in to comment.