*/
class JsonContentTest extends MediaWikiLangTestCase {
- protected function setUp() {
- parent::setUp();
-
- $this->setMwGlobals( 'wgWellFormedXml', true );
- }
-
public static function provideValidConstruction() {
- return array(
- array( 'foo', false, null ),
- array( '[]', true, array() ),
- array( '{}', true, (object)array() ),
- array( '""', true, '' ),
- array( '"0"', true, '0' ),
- array( '"bar"', true, 'bar' ),
- array( '0', true, '0' ),
- array( '{ "0": "bar" }', true, (object)array( 'bar' ) ),
- );
+ return [
+ [ 'foo', false, null ],
+ [ '[]', true, [] ],
+ [ '{}', true, (object)[] ],
+ [ '""', true, '' ],
+ [ '"0"', true, '0' ],
+ [ '"bar"', true, 'bar' ],
+ [ '0', true, '0' ],
+ [ '{ "0": "bar" }', true, (object)[ 'bar' ] ],
+ ];
}
/**
}
public static function provideDataToEncode() {
- return array(
- array(
+ return [
+ [
// Round-trip empty array
'[]',
'[]',
- ),
- array(
+ ],
+ [
// Round-trip empty object
'{}',
'{}',
- ),
- array(
+ ],
+ [
// Round-trip empty array/object (nested)
'{ "foo": {}, "bar": [] }',
"{\n \"foo\": {},\n \"bar\": []\n}",
- ),
- array(
+ ],
+ [
'{ "foo": "bar" }',
"{\n \"foo\": \"bar\"\n}",
- ),
- array(
+ ],
+ [
'{ "foo": 1000 }',
"{\n \"foo\": 1000\n}",
- ),
- array(
+ ],
+ [
'{ "foo": 1000, "0": "bar" }',
"{\n \"foo\": 1000,\n \"0\": \"bar\"\n}",
- ),
- );
+ ],
+ ];
}
/**
}
public static function provideDataAndParserText() {
- return array(
- array(
- array(),
+ return [
+ [
+ [],
'<table class="mw-json"><tbody><tr><td>' .
'<table class="mw-json"><tbody><tr><td class="mw-json-empty">Empty array</td></tr>'
. '</tbody></table></td></tr></tbody></table>'
- ),
- array(
- (object)array(),
+ ],
+ [
+ (object)[],
'<table class="mw-json"><tbody><tr><td class="mw-json-empty">Empty object</td></tr>' .
'</tbody></table>'
- ),
- array(
- (object)array( 'foo' ),
+ ],
+ [
+ (object)[ 'foo' ],
'<table class="mw-json"><tbody><tr><th>0</th><td class="value">"foo"</td></tr>' .
'</tbody></table>'
- ),
- array(
- (object)array( 'foo', 'bar' ),
+ ],
+ [
+ (object)[ 'foo', 'bar' ],
'<table class="mw-json"><tbody><tr><th>0</th><td class="value">"foo"</td></tr>' .
'<tr><th>1</th><td class="value">"bar"</td></tr></tbody></table>'
- ),
- array(
- (object)array( 'baz' => 'foo', 'bar' ),
+ ],
+ [
+ (object)[ 'baz' => 'foo', 'bar' ],
'<table class="mw-json"><tbody><tr><th>baz</th><td class="value">"foo"</td></tr>' .
'<tr><th>0</th><td class="value">"bar"</td></tr></tbody></table>'
- ),
- array(
- (object)array( 'baz' => 1000, 'bar' ),
+ ],
+ [
+ (object)[ 'baz' => 1000, 'bar' ],
'<table class="mw-json"><tbody><tr><th>baz</th><td class="value">1000</td></tr>' .
'<tr><th>0</th><td class="value">"bar"</td></tr></tbody></table>'
- ),
- array(
- (object)array( '<script>alert("evil!")</script>' ),
+ ],
+ [
+ (object)[ '<script>alert("evil!")</script>' ],
'<table class="mw-json"><tbody><tr><th>0</th><td class="value">"' .
'<script>alert("evil!")</script>"' .
'</td></tr></tbody></table>',
- ),
- );
+ ],
+ ];
}
/**