Tests for Revision::decompressRevisionText
Bug: T180210 Change-Id: I21f6bb02757bcf59ce483e7d61685d372f134048
This commit is contained in:
parent
aab3e3be88
commit
c97caafa2e
1 changed files with 71 additions and 0 deletions
|
|
@ -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 )
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue