| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Api\Format; |
| 4 |
|
| 5 |
use MediaWiki\Api\ApiResult; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class ApiFormatPhpTest extends ApiFormatTestBase { |
| 12 |
|
| 13 |
|
| 14 |
protected $printerName = 'php'; |
| 15 |
|
| 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; |
| 22 |
} |
| 23 |
} |
| 24 |
return $arr; |
| 25 |
} |
| 26 |
|
| 27 |
public static function provideGeneralEncoding() { |
| 28 |
return array_merge( |
| 29 |
self::addFormatVersion( 1, [ |
| 30 |
|
| 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";}' ], |
| 43 |
|
| 44 |
|
| 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";}}' ], |
| 57 |
|
| 58 |
|
| 59 |
[ [ 'content' => 'foo', ApiResult::META_CONTENT => 'content' ], |
| 60 |
'a:1:{s:1:"*";s:3:"foo";}' ], |
| 61 |
|
| 62 |
|
| 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 |
|
| 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";}' ], |
| 80 |
|
| 81 |
|
| 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";}}' ], |
| 94 |
|
| 95 |
|
| 96 |
[ [ 'content' => 'foo', ApiResult::META_CONTENT => 'content' ], |
| 97 |
'a:1:{s:7:"content";s:3:"foo";}' ], |
| 98 |
|
| 99 |
|
| 100 |
[ [ 'foo' => 'foo', ApiResult::META_BC_SUBELEMENTS => [ 'foo' ] ], |
| 101 |
'a:1:{s:3:"foo";s:3:"foo";}' ], |
| 102 |
] ) |
| 103 |
); |
| 104 |
|
| 105 |
} |
| 106 |
|
| 107 |
} |