diff options
Diffstat (limited to 'tests/phpunit/includes/json/FormatJsonTest.php')
-rw-r--r-- | tests/phpunit/includes/json/FormatJsonTest.php | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/tests/phpunit/includes/json/FormatJsonTest.php b/tests/phpunit/includes/json/FormatJsonTest.php index 8359f0d2e735..307b3551e9f6 100644 --- a/tests/phpunit/includes/json/FormatJsonTest.php +++ b/tests/phpunit/includes/json/FormatJsonTest.php @@ -5,7 +5,22 @@ */ class FormatJsonTest extends MediaWikiTestCase { - public function testEncoderPrettyPrinting() { + public static function provideEncoderPrettyPrinting() { + return array( + // Four spaces + array( true, ' ' ), + array( ' ', ' ' ), + // Two spaces + array( ' ', ' ' ), + // One tab + array( "\t", "\t" ), + ); + } + + /** + * @dataProvider provideEncoderPrettyPrinting + */ + public function testEncoderPrettyPrinting( $pretty, $expectedIndent ) { $obj = array( 'emptyObject' => new stdClass, 'emptyArray' => array(), @@ -22,23 +37,24 @@ class FormatJsonTest extends MediaWikiTestCase { ), ); - // 4 space indent, no trailing whitespace, no trailing linefeed + // No trailing whitespace, no trailing linefeed $json = '{ - "emptyObject": {}, - "emptyArray": [], - "string": "foobar\\\\", - "filledArray": [ - [ - 123, - 456 - ], - "\"7\":[\"8\",{\"9\":\"10\"}]", - "{\n\t\"emptyObject\": {\n\t},\n\t\"emptyArray\": [ ]\n}" - ] + "emptyObject": {}, + "emptyArray": [], + "string": "foobar\\\\", + "filledArray": [ + [ + 123, + 456 + ], + "\"7\":[\"8\",{\"9\":\"10\"}]", + "{\n\t\"emptyObject\": {\n\t},\n\t\"emptyArray\": [ ]\n}" + ] }'; $json = str_replace( "\r", '', $json ); // Windows compat - $this->assertSame( $json, FormatJson::encode( $obj, true ) ); + $json = str_replace( "\t", $expectedIndent, $json ); + $this->assertSame( $json, FormatJson::encode( $obj, $pretty ) ); } public static function provideEncodeDefault() { |