3 * Test cases for our Services_Json library. Requires PHP json support as well,
4 * so we can compare output
6 class ServicesJsonTest
extends MediaWikiTestCase
{
8 * Test to make sure core json_encode() and our Services_Json()->encode()
9 * produce the same output
11 * @dataProvider provideValuesToEncode
13 public function testJsonEncode( $input, $desc ) {
14 if ( !function_exists( 'json_encode' ) ) {
15 $this->markTestIncomplete( 'No PHP json support, unable to test' );
17 } elseif( strtolower( json_encode( "\xf0\xa0\x80\x80" ) ) != '"\ud840\udc00"' ) {
18 $this->markTestIncomplete( 'Have buggy PHP json support, unable to test' );
21 $jsonObj = new Services_JSON();
23 $jsonObj->encode( $input ),
24 json_encode( $input ),
31 * Test to make sure core json_decode() and our Services_Json()->decode()
32 * produce the same output
34 * @dataProvider provideValuesToDecode
36 public function testJsonDecode( $input, $desc ) {
37 if ( !function_exists( 'json_decode' ) ) {
38 $this->markTestIncomplete( 'No PHP json support, unable to test' );
41 $jsonObj = new Services_JSON();
43 $jsonObj->decode( $input ),
44 json_decode( $input ),
50 function provideValuesToEncode() {
51 $obj = new stdClass();
52 $obj->property
= 'value';
53 $obj->property2
= null;
54 $obj->property3
= 1.234;
56 array( 1, 'basic integer' ),
57 array( true, 'basic bool true' ),
58 array( false, 'basic bool false' ),
59 array( 'some string', 'basic string test' ),
60 array( array( 'some', 'string', 'values' ), 'basic array of strings' ),
61 array( array( 'key1' => 'val1', 'key2' => 'val2' ), 'array with string keys' ),
62 array( $obj, 'basic object test' ),
66 function provideValuesToDecode() {
68 array( '{"key":"value"}', 'Basic key => value test' ),