X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=tests%2Fphpunit%2Fincludes%2Fcontent%2FJsonContentTest.php;h=7cddbad26d268d3f93ae1e552310b588402f96d1;hb=6b3e5511fb848890f174690885e748b90389c0b8;hp=8a9d2ab0850a9c0267af41f81fee2d78e8973a1e;hpb=f873b499650ef5d27570f9cb96d01d1477f9e089;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/content/JsonContentTest.php b/tests/phpunit/includes/content/JsonContentTest.php index 8a9d2ab085..7cddbad26d 100644 --- a/tests/phpunit/includes/content/JsonContentTest.php +++ b/tests/phpunit/includes/content/JsonContentTest.php @@ -1,28 +1,22 @@ 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' ] ], + ]; } /** @@ -35,35 +29,35 @@ class JsonContentTest extends MediaWikiLangTestCase { } 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}", - ), - ); + ], + ]; } /** @@ -88,62 +82,62 @@ class JsonContentTest extends MediaWikiLangTestCase { } private function getMockTitle() { - return $this->getMockBuilder( 'Title' ) + return $this->getMockBuilder( Title::class ) ->disableOriginalConstructor() ->getMock(); } private function getMockUser() { - return $this->getMockBuilder( 'User' ) + return $this->getMockBuilder( User::class ) ->disableOriginalConstructor() ->getMock(); } private function getMockParserOptions() { - return $this->getMockBuilder( 'ParserOptions' ) + return $this->getMockBuilder( ParserOptions::class ) ->disableOriginalConstructor() ->getMock(); } public static function provideDataAndParserText() { - return array( - array( - array(), + return [ + [ + [], '
' . '' . '
Empty array
' - ), - array( - (object)array(), + ], + [ + (object)[], '' . '
Empty object
' - ), - array( - (object)array( 'foo' ), + ], + [ + (object)[ 'foo' ], '' . '
0"foo"
' - ), - array( - (object)array( 'foo', 'bar' ), + ], + [ + (object)[ 'foo', 'bar' ], '' . '
0"foo"
1"bar"
' - ), - array( - (object)array( 'baz' => 'foo', 'bar' ), + ], + [ + (object)[ 'baz' => 'foo', 'bar' ], '' . '
baz"foo"
0"bar"
' - ), - array( - (object)array( 'baz' => 1000, 'bar' ), + ], + [ + (object)[ 'baz' => 1000, 'bar' ], '' . '
baz1000
0"bar"
' - ), - array( - (object)array( '' ), + ], + [ + (object)[ '' ], '
0"' . '<script>alert("evil!")</script>"' . '
', - ), - ); + ], + ]; } /** @@ -152,7 +146,7 @@ class JsonContentTest extends MediaWikiLangTestCase { public function testFillParserOutput( $data, $expected ) { $obj = new JsonContent( FormatJson::encode( $data ) ); $parserOutput = $obj->getParserOutput( $this->getMockTitle(), null, null, true ); - $this->assertInstanceOf( 'ParserOutput', $parserOutput ); + $this->assertInstanceOf( ParserOutput::class, $parserOutput ); $this->assertEquals( $expected, $parserOutput->getText() ); } }