From c97caafa2e0c7c82825a73820c5fe1a183086565 Mon Sep 17 00:00:00 2001 From: addshore Date: Fri, 10 Nov 2017 13:14:13 +0000 Subject: [PATCH] Tests for Revision::decompressRevisionText Bug: T180210 Change-Id: I21f6bb02757bcf59ce483e7d61685d372f134048 --- tests/phpunit/includes/RevisionTest.php | 71 +++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/tests/phpunit/includes/RevisionTest.php b/tests/phpunit/includes/RevisionTest.php index 57cd7f8b5f..953c795e46 100644 --- a/tests/phpunit/includes/RevisionTest.php +++ b/tests/phpunit/includes/RevisionTest.php @@ -395,4 +395,75 @@ class RevisionTest extends MediaWikiTestCase { $this->assertEquals( 'RETURNVALUE', $result ); } + + public function provideDecompressRevisionText() { + yield '(no legacy encoding), false in false out' => [ false, false, [], false ]; + yield '(no legacy encoding), empty in empty out' => [ false, '', [], '' ]; + yield '(no legacy encoding), empty in empty out' => [ false, 'A', [], 'A' ]; + yield '(no legacy encoding), string in with gzip flag returns string' => [ + // gzip string below generated with gzdeflate( 'AAAABBAAA' ) + false, "sttttr\002\022\000", [ 'gzip' ], 'AAAABBAAA', + ]; + yield '(no legacy encoding), string in with object flag returns false' => [ + // gzip string below generated with serialize( 'JOJO' ) + false, "s:4:\"JOJO\";", [ 'object' ], false, + ]; + yield '(no legacy encoding), serialized object in with object flag returns string' => [ + false, + // Using a TitleValue object as it has a getText method (which is needed) + serialize( new TitleValue( 0, 'HHJJDDFF' ) ), + [ 'object' ], + 'HHJJDDFF', + ]; + yield '(no legacy encoding), serialized object in with object & gzip flag returns string' => [ + false, + // Using a TitleValue object as it has a getText method (which is needed) + gzdeflate( serialize( new TitleValue( 0, '8219JJJ840' ) ) ), + [ 'object', 'gzip' ], + '8219JJJ840', + ]; + yield '(ISO-8859-1 encoding), string in string out' => [ + 'ISO-8859-1', + iconv( 'utf8', 'ISO-8859-1', "1®Àþ1" ), + [], + '1®Àþ1', + ]; + yield '(ISO-8859-1 encoding), serialized object in with gzip flags returns string' => [ + 'ISO-8859-1', + gzdeflate( iconv( 'utf8', 'ISO-8859-1', "4®Àþ4" ) ), + [ 'gzip' ], + '4®Àþ4', + ]; + yield '(ISO-8859-1 encoding), serialized object in with object flags returns string' => [ + 'ISO-8859-1', + serialize( new TitleValue( 0, iconv( 'utf8', 'ISO-8859-1', "3®Àþ3" ) ) ), + [ 'object' ], + '3®Àþ3', + ]; + yield '(ISO-8859-1 encoding), serialized object in with object & gzip flags returns string' => [ + 'ISO-8859-1', + gzdeflate( serialize( new TitleValue( 0, iconv( 'utf8', 'ISO-8859-1', "2®Àþ2" ) ) ) ), + [ 'gzip', 'object' ], + '2®Àþ2', + ]; + } + + /** + * @dataProvider provideDecompressRevisionText + * @covers Revision::decompressRevisionText + * + * @param bool $legacyEncoding + * @param mixed $text + * @param array $flags + * @param mixed $expected + */ + public function testDecompressRevisionText( $legacyEncoding, $text, $flags, $expected ) { + $this->setMwGlobals( 'wgLegacyEncoding', $legacyEncoding ); + $this->setMwGlobals( 'wgLanguageCode', 'en' ); + $this->assertSame( + $expected, + Revision::decompressRevisionText( $text, $flags ) + ); + } + } -- 2.20.1