5 * @covers ApiFormatJson
7 class ApiFormatJsonTest
extends ApiFormatTestBase
{
9 protected $printerName = 'json';
11 private static function addFormatVersion( $format, $arr ) {
12 foreach ( $arr as &$p ) {
13 if ( !isset( $p[2] ) ) {
14 $p[2] = array( 'formatversion' => $format );
16 $p[2]['formatversion'] = $format;
22 public static function provideGeneralEncoding() {
24 self
::addFormatVersion( 1, array(
26 array( array( null ), '[null]' ),
27 array( array( true ), '[""]' ),
28 array( array( false ), '[]' ),
29 array( array( true, ApiResult
::META_BC_BOOLS
=> array( 0 ) ), '[true]' ),
30 array( array( false, ApiResult
::META_BC_BOOLS
=> array( 0 ) ), '[false]' ),
31 array( array( 42 ), '[42]' ),
32 array( array( 42.5 ), '[42.5]' ),
33 array( array( 1e42
), '[1.0e+42]' ),
34 array( array( 'foo' ), '["foo"]' ),
35 array( array( 'fóo' ), '["f\u00f3o"]' ),
36 array( array( 'fóo' ), '["fóo"]', array( 'utf8' => 1 ) ),
39 array( array( array() ), '[[]]' ),
40 array( array( array( 1 ) ), '[[1]]' ),
41 array( array( array( 'x' => 1 ) ), '[{"x":1}]' ),
42 array( array( array( 2 => 1 ) ), '[{"2":1}]' ),
43 array( array( (object)array() ), '[{}]' ),
44 array( array( array( 1, ApiResult
::META_TYPE
=> 'assoc' ) ), '[{"0":1}]' ),
45 array( array( array( 'x' => 1, ApiResult
::META_TYPE
=> 'array' ) ), '[[1]]' ),
46 array( array( array( 'x' => 1, ApiResult
::META_TYPE
=> 'kvp' ) ), '[{"x":1}]' ),
50 ApiResult
::META_TYPE
=> 'BCkvp',
51 ApiResult
::META_KVP_KEY_NAME
=> 'key'
53 '[[{"key":"x","*":1}]]'
55 array( array( array( 'x' => 1, ApiResult
::META_TYPE
=> 'BCarray' ) ), '[{"x":1}]' ),
56 array( array( array( 'a', 'b', ApiResult
::META_TYPE
=> 'BCassoc' ) ), '[["a","b"]]' ),
59 array( array( 'content' => 'foo', ApiResult
::META_CONTENT
=> 'content' ),
63 array( array( 'foo' => 'foo', ApiResult
::META_BC_SUBELEMENTS
=> array( 'foo' ) ),
64 '{"foo":{"*":"foo"}}' ),
67 array( array( 1 ), '/**/myCallback([1])', array( 'callback' => 'myCallback' ) ),
69 // Cross-domain mangling
70 array( array( '< Cross-Domain-Policy >' ), '["\u003C Cross-Domain-Policy \u003E"]' ),
72 self
::addFormatVersion( 2, array(
74 array( array( null ), '[null]' ),
75 array( array( true ), '[true]' ),
76 array( array( false ), '[false]' ),
77 array( array( true, ApiResult
::META_BC_BOOLS
=> array( 0 ) ), '[true]' ),
78 array( array( false, ApiResult
::META_BC_BOOLS
=> array( 0 ) ), '[false]' ),
79 array( array( 42 ), '[42]' ),
80 array( array( 42.5 ), '[42.5]' ),
81 array( array( 1e42
), '[1.0e+42]' ),
82 array( array( 'foo' ), '["foo"]' ),
83 array( array( 'fóo' ), '["fóo"]' ),
84 array( array( 'fóo' ), '["f\u00f3o"]', array( 'ascii' => 1 ) ),
87 array( array( array() ), '[[]]' ),
88 array( array( array( 'x' => 1 ) ), '[{"x":1}]' ),
89 array( array( array( 2 => 1 ) ), '[{"2":1}]' ),
90 array( array( (object)array() ), '[{}]' ),
91 array( array( array( 1, ApiResult
::META_TYPE
=> 'assoc' ) ), '[{"0":1}]' ),
92 array( array( array( 'x' => 1, ApiResult
::META_TYPE
=> 'array' ) ), '[[1]]' ),
93 array( array( array( 'x' => 1, ApiResult
::META_TYPE
=> 'kvp' ) ), '[{"x":1}]' ),
97 ApiResult
::META_TYPE
=> 'BCkvp',
98 ApiResult
::META_KVP_KEY_NAME
=> 'key'
102 array( array( array( 'x' => 1, ApiResult
::META_TYPE
=> 'BCarray' ) ), '[[1]]' ),
107 ApiResult
::META_TYPE
=> 'BCassoc'
109 '[{"0":"a","1":"b"}]'
113 array( array( 'content' => 'foo', ApiResult
::META_CONTENT
=> 'content' ),
114 '{"content":"foo"}' ),
117 array( array( 'foo' => 'foo', ApiResult
::META_BC_SUBELEMENTS
=> array( 'foo' ) ),
121 array( array( 1 ), '/**/myCallback([1])', array( 'callback' => 'myCallback' ) ),
123 // Cross-domain mangling
124 array( array( '< Cross-Domain-Policy >' ), '["\u003C Cross-Domain-Policy \u003E"]' ),