parse json

This commit is contained in:
John Bintz 2009-11-22 15:50:16 -05:00
parent 74183a9944
commit 1aca4598a8
2 changed files with 40 additions and 0 deletions

View File

@ -1 +1,12 @@
<?php <?php
class PostFixtures {
function parse_json($input) {
if (($data = json_decode($input)) !== false) {
if (is_array($data) || is_object($data)) {
return (array)$data;
}
}
return false;
}
}

View File

@ -1 +1,30 @@
<?php <?php
require_once('PHPUnit/Framework.php');
require_once('MockPress/mockpress.php');
require_once(dirname(__FILE__) . '/../classes/PostFixtures.inc');
class PostFixturesTest extends PHPUnit_Framework_TestCase {
function setUp() {
_reset_wp();
$this->pf = new PostFixtures();
}
function providerTestParseJSON() {
return array(
array(false, false),
array('', false),
array('{]', false),
array('{}', array()),
array('[]', array())
);
}
/**
* @dataProvider providerTestParseJSON
*/
function testParseJSON($input, $expected_output) {
$this->assertEquals($expected_output, $this->pf->parse_json($input));
}
}