MediaWiki  1.28.0
ApiFormatJsonTest.php
Go to the documentation of this file.
1 <?php
2 
8 
9  protected $printerName = 'json';
10 
11  private static function addFormatVersion( $format, $arr ) {
12  foreach ( $arr as &$p ) {
13  if ( !isset( $p[2] ) ) {
14  $p[2] = [ 'formatversion' => $format ];
15  } else {
16  $p[2]['formatversion'] = $format;
17  }
18  }
19  return $arr;
20  }
21 
22  public static function provideGeneralEncoding() {
23  return array_merge(
24  self::addFormatVersion( 1, [
25  // Basic types
26  [ [ null ], '[null]' ],
27  [ [ true ], '[""]' ],
28  [ [ false ], '[]' ],
29  [ [ true, ApiResult::META_BC_BOOLS => [ 0 ] ], '[true]' ],
30  [ [ false, ApiResult::META_BC_BOOLS => [ 0 ] ], '[false]' ],
31  [ [ 42 ], '[42]' ],
32  [ [ 42.5 ], '[42.5]' ],
33  [ [ 1e42 ], '[1.0e+42]' ],
34  [ [ 'foo' ], '["foo"]' ],
35  [ [ 'fóo' ], '["f\u00f3o"]' ],
36  [ [ 'fóo' ], '["fóo"]', [ 'utf8' => 1 ] ],
37 
38  // Arrays and objects
39  [ [ [] ], '[[]]' ],
40  [ [ [ 1 ] ], '[[1]]' ],
41  [ [ [ 'x' => 1 ] ], '[{"x":1}]' ],
42  [ [ [ 2 => 1 ] ], '[{"2":1}]' ],
43  [ [ (object)[] ], '[{}]' ],
44  [ [ [ 1, ApiResult::META_TYPE => 'assoc' ] ], '[{"0":1}]' ],
45  [ [ [ 'x' => 1, ApiResult::META_TYPE => 'array' ] ], '[[1]]' ],
46  [ [ [ 'x' => 1, ApiResult::META_TYPE => 'kvp' ] ], '[{"x":1}]' ],
47  [
48  [ [
49  'x' => 1,
50  ApiResult::META_TYPE => 'BCkvp',
52  ] ],
53  '[[{"key":"x","*":1}]]'
54  ],
55  [ [ [ 'x' => 1, ApiResult::META_TYPE => 'BCarray' ] ], '[{"x":1}]' ],
56  [ [ [ 'a', 'b', ApiResult::META_TYPE => 'BCassoc' ] ], '[["a","b"]]' ],
57 
58  // Content
59  [ [ 'content' => 'foo', ApiResult::META_CONTENT => 'content' ],
60  '{"*":"foo"}' ],
61 
62  // BC Subelements
63  [ [ 'foo' => 'foo', ApiResult::META_BC_SUBELEMENTS => [ 'foo' ] ],
64  '{"foo":{"*":"foo"}}' ],
65 
66  // Callbacks
67  [ [ 1 ], '/**/myCallback([1])', [ 'callback' => 'myCallback' ] ],
68 
69  // Cross-domain mangling
70  [ [ '< Cross-Domain-Policy >' ], '["\u003C Cross-Domain-Policy >"]' ],
71  ] ),
72  self::addFormatVersion( 2, [
73  // Basic types
74  [ [ null ], '[null]' ],
75  [ [ true ], '[true]' ],
76  [ [ false ], '[false]' ],
77  [ [ true, ApiResult::META_BC_BOOLS => [ 0 ] ], '[true]' ],
78  [ [ false, ApiResult::META_BC_BOOLS => [ 0 ] ], '[false]' ],
79  [ [ 42 ], '[42]' ],
80  [ [ 42.5 ], '[42.5]' ],
81  [ [ 1e42 ], '[1.0e+42]' ],
82  [ [ 'foo' ], '["foo"]' ],
83  [ [ 'fóo' ], '["fóo"]' ],
84  [ [ 'fóo' ], '["f\u00f3o"]', [ 'ascii' => 1 ] ],
85 
86  // Arrays and objects
87  [ [ [] ], '[[]]' ],
88  [ [ [ 'x' => 1 ] ], '[{"x":1}]' ],
89  [ [ [ 2 => 1 ] ], '[{"2":1}]' ],
90  [ [ (object)[] ], '[{}]' ],
91  [ [ [ 1, ApiResult::META_TYPE => 'assoc' ] ], '[{"0":1}]' ],
92  [ [ [ 'x' => 1, ApiResult::META_TYPE => 'array' ] ], '[[1]]' ],
93  [ [ [ 'x' => 1, ApiResult::META_TYPE => 'kvp' ] ], '[{"x":1}]' ],
94  [
95  [ [
96  'x' => 1,
97  ApiResult::META_TYPE => 'BCkvp',
99  ] ],
100  '[{"x":1}]'
101  ],
102  [ [ [ 'x' => 1, ApiResult::META_TYPE => 'BCarray' ] ], '[[1]]' ],
103  [
104  [ [
105  'a',
106  'b',
107  ApiResult::META_TYPE => 'BCassoc'
108  ] ],
109  '[{"0":"a","1":"b"}]'
110  ],
111 
112  // Content
113  [ [ 'content' => 'foo', ApiResult::META_CONTENT => 'content' ],
114  '{"content":"foo"}' ],
115 
116  // BC Subelements
117  [ [ 'foo' => 'foo', ApiResult::META_BC_SUBELEMENTS => [ 'foo' ] ],
118  '{"foo":"foo"}' ],
119 
120  // Callbacks
121  [ [ 1 ], '/**/myCallback([1])', [ 'callback' => 'myCallback' ] ],
122 
123  // Cross-domain mangling
124  [ [ '< Cross-Domain-Policy >' ], '["\u003C Cross-Domain-Policy >"]' ],
125  ] )
126  );
127  }
128 
129 }
API ApiFormatJson.
static provideGeneralEncoding()
const META_TYPE
Key for the 'type' metadata item.
Definition: ApiResult.php:108
static addFormatVersion($format, $arr)
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
const META_BC_BOOLS
Key for the 'BC bools' metadata item.
Definition: ApiResult.php:134
const META_CONTENT
Key for the 'content' metadata item.
Definition: ApiResult.php:88
const META_BC_SUBELEMENTS
Key for the 'BC subelements' metadata item.
Definition: ApiResult.php:141
const META_KVP_KEY_NAME
Key for the metadata item whose value specifies the name used for the kvp key in the alternative outp...
Definition: ApiResult.php:117