2010-12-14 16:26:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
2010-12-28 18:17:16 +00:00
|
|
|
class RevisionTest extends MediaWikiTestCase {
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
|
|
|
|
parent::setUp();
|
2010-12-14 16:26:35 +00:00
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
$this->setMwGlobals( array(
|
|
|
|
|
'wgContLang' => Language::factory( 'en' ),
|
2010-12-14 16:26:35 +00:00
|
|
|
'wgLegacyEncoding' => false,
|
|
|
|
|
'wgCompressRevisions' => false,
|
2012-10-08 10:56:20 +00:00
|
|
|
) );
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testGetRevisionText() {
|
|
|
|
|
$row = new stdClass;
|
|
|
|
|
$row->old_flags = '';
|
|
|
|
|
$row->old_text = 'This is a bunch of revision text.';
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'This is a bunch of revision text.',
|
|
|
|
|
Revision::getRevisionText( $row ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testGetRevisionTextGzip() {
|
2011-06-17 21:15:24 +00:00
|
|
|
if ( !function_exists( 'gzdeflate' ) ) {
|
|
|
|
|
$this->markTestSkipped( 'Gzip compression is not enabled (requires zlib).' );
|
|
|
|
|
} else {
|
|
|
|
|
$row = new stdClass;
|
|
|
|
|
$row->old_flags = 'gzip';
|
|
|
|
|
$row->old_text = gzdeflate( 'This is a bunch of revision text.' );
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
'This is a bunch of revision text.',
|
|
|
|
|
Revision::getRevisionText( $row ) );
|
|
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testGetRevisionTextUtf8Native() {
|
|
|
|
|
$row = new stdClass;
|
|
|
|
|
$row->old_flags = 'utf-8';
|
|
|
|
|
$row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
|
|
|
|
|
$GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"Wiki est l'\xc3\xa9cole superieur !",
|
|
|
|
|
Revision::getRevisionText( $row ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testGetRevisionTextUtf8Legacy() {
|
|
|
|
|
$row = new stdClass;
|
|
|
|
|
$row->old_flags = '';
|
|
|
|
|
$row->old_text = "Wiki est l'\xe9cole superieur !";
|
|
|
|
|
$GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"Wiki est l'\xc3\xa9cole superieur !",
|
|
|
|
|
Revision::getRevisionText( $row ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testGetRevisionTextUtf8NativeGzip() {
|
2011-06-17 21:15:24 +00:00
|
|
|
if ( !function_exists( 'gzdeflate' ) ) {
|
|
|
|
|
$this->markTestSkipped( 'Gzip compression is not enabled (requires zlib).' );
|
|
|
|
|
} else {
|
|
|
|
|
$row = new stdClass;
|
|
|
|
|
$row->old_flags = 'gzip,utf-8';
|
|
|
|
|
$row->old_text = gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" );
|
|
|
|
|
$GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"Wiki est l'\xc3\xa9cole superieur !",
|
|
|
|
|
Revision::getRevisionText( $row ) );
|
|
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testGetRevisionTextUtf8LegacyGzip() {
|
2011-06-17 21:15:24 +00:00
|
|
|
if ( !function_exists( 'gzdeflate' ) ) {
|
|
|
|
|
$this->markTestSkipped( 'Gzip compression is not enabled (requires zlib).' );
|
|
|
|
|
} else {
|
|
|
|
|
$row = new stdClass;
|
|
|
|
|
$row->old_flags = 'gzip';
|
|
|
|
|
$row->old_text = gzdeflate( "Wiki est l'\xe9cole superieur !" );
|
|
|
|
|
$GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
|
|
|
|
|
$this->assertEquals(
|
|
|
|
|
"Wiki est l'\xc3\xa9cole superieur !",
|
|
|
|
|
Revision::getRevisionText( $row ) );
|
|
|
|
|
}
|
2010-12-14 16:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testCompressRevisionTextUtf8() {
|
|
|
|
|
$row = new stdClass;
|
|
|
|
|
$row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
|
|
|
|
|
$row->old_flags = Revision::compressRevisionText( $row->old_text );
|
|
|
|
|
$this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
|
|
|
|
|
"Flags should contain 'utf-8'" );
|
|
|
|
|
$this->assertFalse( false !== strpos( $row->old_flags, 'gzip' ),
|
|
|
|
|
"Flags should not contain 'gzip'" );
|
|
|
|
|
$this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
|
|
|
|
|
$row->old_text, "Direct check" );
|
|
|
|
|
$this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
|
|
|
|
|
Revision::getRevisionText( $row ), "getRevisionText" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function testCompressRevisionTextUtf8Gzip() {
|
2012-10-08 10:56:20 +00:00
|
|
|
global $wgCompressRevisions;
|
|
|
|
|
|
|
|
|
|
$wgCompressRevisions = true;
|
|
|
|
|
|
2010-12-14 16:26:35 +00:00
|
|
|
$row = new stdClass;
|
|
|
|
|
$row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
|
|
|
|
|
$row->old_flags = Revision::compressRevisionText( $row->old_text );
|
|
|
|
|
$this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
|
|
|
|
|
"Flags should contain 'utf-8'" );
|
|
|
|
|
$this->assertTrue( false !== strpos( $row->old_flags, 'gzip' ),
|
|
|
|
|
"Flags should contain 'gzip'" );
|
|
|
|
|
$this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
|
|
|
|
|
gzinflate( $row->old_text ), "Direct check" );
|
|
|
|
|
$this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
|
|
|
|
|
Revision::getRevisionText( $row ), "getRevisionText" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|