Merge "Drop cache interwiki"
[mediawiki.git] / tests / phpunit / includes / api / format / ApiFormatPhpTest.php
bloba1791d0bb08f062086ec8e4bedf1c4b485b086fb
1 <?php
3 namespace MediaWiki\Tests\Api\Format;
5 use MediaWiki\Api\ApiResult;
7 /**
8 * @group API
9 * @covers MediaWiki\Api\ApiFormatPhp
11 class ApiFormatPhpTest extends ApiFormatTestBase {
13 /** @inheritDoc */
14 protected $printerName = 'php';
16 private static function addFormatVersion( $format, $arr ) {
17 foreach ( $arr as &$p ) {
18 if ( !isset( $p[2] ) ) {
19 $p[2] = [ 'formatversion' => $format ];
20 } else {
21 $p[2]['formatversion'] = $format;
24 return $arr;
27 public static function provideGeneralEncoding() {
28 return array_merge(
29 self::addFormatVersion( 1, [
30 // Basic types
31 [ [ null ], 'a:1:{i:0;N;}' ],
32 [ [ true ], 'a:1:{i:0;s:0:"";}' ],
33 [ [ false ], 'a:0:{}' ],
34 [ [ true, ApiResult::META_BC_BOOLS => [ 0 ] ],
35 'a:1:{i:0;b:1;}' ],
36 [ [ false, ApiResult::META_BC_BOOLS => [ 0 ] ],
37 'a:1:{i:0;b:0;}' ],
38 [ [ 42 ], 'a:1:{i:0;i:42;}' ],
39 [ [ 42.5 ], 'a:1:{i:0;d:42.5;}' ],
40 [ [ 1e42 ], 'a:1:{i:0;d:1.0E+42;}' ],
41 [ [ 'foo' ], 'a:1:{i:0;s:3:"foo";}' ],
42 [ [ 'fóo' ], 'a:1:{i:0;s:4:"fóo";}' ],
44 // Arrays and objects
45 [ [ [] ], 'a:1:{i:0;a:0:{}}' ],
46 [ [ [ 1 ] ], 'a:1:{i:0;a:1:{i:0;i:1;}}' ],
47 [ [ [ 'x' => 1 ] ], 'a:1:{i:0;a:1:{s:1:"x";i:1;}}' ],
48 [ [ [ 2 => 1 ] ], 'a:1:{i:0;a:1:{i:2;i:1;}}' ],
49 [ [ (object)[] ], 'a:1:{i:0;a:0:{}}' ],
50 [ [ [ 1, ApiResult::META_TYPE => 'assoc' ] ], 'a:1:{i:0;a:1:{i:0;i:1;}}' ],
51 [ [ [ 'x' => 1, ApiResult::META_TYPE => 'array' ] ], 'a:1:{i:0;a:1:{i:0;i:1;}}' ],
52 [ [ [ 'x' => 1, ApiResult::META_TYPE => 'kvp' ] ], 'a:1:{i:0;a:1:{s:1:"x";i:1;}}' ],
53 [ [ [ 'x' => 1, ApiResult::META_TYPE => 'BCkvp', ApiResult::META_KVP_KEY_NAME => 'key' ] ],
54 'a:1:{i:0;a:1:{i:0;a:2:{s:3:"key";s:1:"x";s:1:"*";i:1;}}}' ],
55 [ [ [ 'x' => 1, ApiResult::META_TYPE => 'BCarray' ] ], 'a:1:{i:0;a:1:{s:1:"x";i:1;}}' ],
56 [ [ [ 'a', 'b', ApiResult::META_TYPE => 'BCassoc' ] ], 'a:1:{i:0;a:2:{i:0;s:1:"a";i:1;s:1:"b";}}' ],
58 // Content
59 [ [ 'content' => 'foo', ApiResult::META_CONTENT => 'content' ],
60 'a:1:{s:1:"*";s:3:"foo";}' ],
62 // BC Subelements
63 [ [ 'foo' => 'foo', ApiResult::META_BC_SUBELEMENTS => [ 'foo' ] ],
64 'a:1:{s:3:"foo";a:1:{s:1:"*";s:3:"foo";}}' ],
65 ] ),
66 self::addFormatVersion( 2, [
67 // Basic types
68 [ [ null ], 'a:1:{i:0;N;}' ],
69 [ [ true ], 'a:1:{i:0;b:1;}' ],
70 [ [ false ], 'a:1:{i:0;b:0;}' ],
71 [ [ true, ApiResult::META_BC_BOOLS => [ 0 ] ],
72 'a:1:{i:0;b:1;}' ],
73 [ [ false, ApiResult::META_BC_BOOLS => [ 0 ] ],
74 'a:1:{i:0;b:0;}' ],
75 [ [ 42 ], 'a:1:{i:0;i:42;}' ],
76 [ [ 42.5 ], 'a:1:{i:0;d:42.5;}' ],
77 [ [ 1e42 ], 'a:1:{i:0;d:1.0E+42;}' ],
78 [ [ 'foo' ], 'a:1:{i:0;s:3:"foo";}' ],
79 [ [ 'fóo' ], 'a:1:{i:0;s:4:"fóo";}' ],
81 // Arrays and objects
82 [ [ [] ], 'a:1:{i:0;a:0:{}}' ],
83 [ [ [ 1 ] ], 'a:1:{i:0;a:1:{i:0;i:1;}}' ],
84 [ [ [ 'x' => 1 ] ], 'a:1:{i:0;a:1:{s:1:"x";i:1;}}' ],
85 [ [ [ 2 => 1 ] ], 'a:1:{i:0;a:1:{i:2;i:1;}}' ],
86 [ [ (object)[] ], 'a:1:{i:0;a:0:{}}' ],
87 [ [ [ 1, ApiResult::META_TYPE => 'assoc' ] ], 'a:1:{i:0;a:1:{i:0;i:1;}}' ],
88 [ [ [ 'x' => 1, ApiResult::META_TYPE => 'array' ] ], 'a:1:{i:0;a:1:{i:0;i:1;}}' ],
89 [ [ [ 'x' => 1, ApiResult::META_TYPE => 'kvp' ] ], 'a:1:{i:0;a:1:{s:1:"x";i:1;}}' ],
90 [ [ [ 'x' => 1, ApiResult::META_TYPE => 'BCkvp', ApiResult::META_KVP_KEY_NAME => 'key' ] ],
91 'a:1:{i:0;a:1:{s:1:"x";i:1;}}' ],
92 [ [ [ 'x' => 1, ApiResult::META_TYPE => 'BCarray' ] ], 'a:1:{i:0;a:1:{i:0;i:1;}}' ],
93 [ [ [ 'a', 'b', ApiResult::META_TYPE => 'BCassoc' ] ], 'a:1:{i:0;a:2:{i:0;s:1:"a";i:1;s:1:"b";}}' ],
95 // Content
96 [ [ 'content' => 'foo', ApiResult::META_CONTENT => 'content' ],
97 'a:1:{s:7:"content";s:3:"foo";}' ],
99 // BC Subelements
100 [ [ 'foo' => 'foo', ApiResult::META_BC_SUBELEMENTS => [ 'foo' ] ],
101 'a:1:{s:3:"foo";s:3:"foo";}' ],
104 // phpcs:enable