diff options
author | diosmosis <benakamoorthi@fastmail.fm> | 2014-08-24 22:16:00 +0400 |
---|---|---|
committer | diosmosis <benakamoorthi@fastmail.fm> | 2014-08-24 22:16:11 +0400 |
commit | fb52fd827ebb2fc804c3da764acebbe3a844c248 (patch) | |
tree | 988635a609ef56c8b0e16b922250155875ab2b6d /plugins | |
parent | fed85ff6a0de28983ccc9eb5c58b2a623c8480fe (diff) |
Fixing build for Json array rendering bug.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/API/Renderer/Json.php | 4 | ||||
-rw-r--r-- | plugins/API/tests/JsonRendererTest.php | 6 |
2 files changed, 7 insertions, 3 deletions
diff --git a/plugins/API/Renderer/Json.php b/plugins/API/Renderer/Json.php index 401a4e1a5a..9604859757 100644 --- a/plugins/API/Renderer/Json.php +++ b/plugins/API/Renderer/Json.php @@ -52,7 +52,9 @@ class Json extends ApiRenderer $result = $this->renderDataTable($array); // if $array is a simple associative array, remove the JSON root array that is added by renderDataTable - if (Piwik::isAssociativeArray($array)) { + if (!empty($array) + && Piwik::isAssociativeArray($array) + ) { $result = substr($result, 1, strlen($result) - 2); } diff --git a/plugins/API/tests/JsonRendererTest.php b/plugins/API/tests/JsonRendererTest.php index 366c22efe2..a840305c70 100644 --- a/plugins/API/tests/JsonRendererTest.php +++ b/plugins/API/tests/JsonRendererTest.php @@ -249,8 +249,9 @@ class JsonRendererTest extends \PHPUnit_Framework_TestCase $input = array('nb_visits' => 6, 'nb_random' => 8); $response = $this->jsonBuilder->renderArray($input); + $expected = json_encode($input); - $this->assertEquals('[{"nb_visits":6,"nb_random":8}]', $response); + $this->assertEquals($expected, $response); $this->assertNoJsonError($response); } @@ -262,8 +263,9 @@ class JsonRendererTest extends \PHPUnit_Framework_TestCase ); $response = $this->jsonBuilder->renderArray($input); + $expected = json_encode($input); - $this->assertEquals('[{"nb_visits":6,"nb_random":8},{"nb_visits":3,"nb_random":4}]', $response); + $this->assertEquals($expected, $response); $this->assertNoJsonError($response); } |