MediaWiki  REL1_19
RevisionTest.php
Go to the documentation of this file.
00001 <?php
00002 
00003 class RevisionTest extends MediaWikiTestCase {
00004         var $saveGlobals = array();
00005 
00006         function setUp() {
00007                 global $wgContLang;
00008                 $wgContLang = Language::factory( 'en' );
00009                 $globalSet = array(
00010                         'wgLegacyEncoding' => false,
00011                         'wgCompressRevisions' => false,
00012                 );
00013                 foreach ( $globalSet as $var => $data ) {
00014                         $this->saveGlobals[$var] = $GLOBALS[$var];
00015                         $GLOBALS[$var] = $data;
00016                 }
00017         }
00018 
00019         function tearDown() {
00020                 foreach ( $this->saveGlobals as $var => $data ) {
00021                         $GLOBALS[$var] = $data;
00022                 }
00023         }
00024 
00025         function testGetRevisionText() {
00026                 $row = new stdClass;
00027                 $row->old_flags = '';
00028                 $row->old_text = 'This is a bunch of revision text.';
00029                 $this->assertEquals(
00030                         'This is a bunch of revision text.',
00031                         Revision::getRevisionText( $row ) );
00032         }
00033 
00034         function testGetRevisionTextGzip() {
00035                 if ( !function_exists( 'gzdeflate' ) ) {
00036                         $this->markTestSkipped( 'Gzip compression is not enabled (requires zlib).' );
00037                 } else {
00038                         $row = new stdClass;
00039                         $row->old_flags = 'gzip';
00040                         $row->old_text = gzdeflate( 'This is a bunch of revision text.' );
00041                         $this->assertEquals(
00042                                 'This is a bunch of revision text.',
00043                                 Revision::getRevisionText( $row ) );
00044                 }
00045         }
00046 
00047         function testGetRevisionTextUtf8Native() {
00048                 $row = new stdClass;
00049                 $row->old_flags = 'utf-8';
00050                 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
00051                 $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
00052                 $this->assertEquals(
00053                         "Wiki est l'\xc3\xa9cole superieur !",
00054                         Revision::getRevisionText( $row ) );
00055         }
00056 
00057         function testGetRevisionTextUtf8Legacy() {
00058                 $row = new stdClass;
00059                 $row->old_flags = '';
00060                 $row->old_text = "Wiki est l'\xe9cole superieur !";
00061                 $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
00062                 $this->assertEquals(
00063                         "Wiki est l'\xc3\xa9cole superieur !",
00064                         Revision::getRevisionText( $row ) );
00065         }
00066 
00067         function testGetRevisionTextUtf8NativeGzip() {
00068                 if ( !function_exists( 'gzdeflate' ) ) {
00069                         $this->markTestSkipped( 'Gzip compression is not enabled (requires zlib).' );
00070                 } else {
00071                         $row = new stdClass;
00072                         $row->old_flags = 'gzip,utf-8';
00073                         $row->old_text = gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" );
00074                         $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
00075                         $this->assertEquals(
00076                                 "Wiki est l'\xc3\xa9cole superieur !",
00077                                 Revision::getRevisionText( $row ) );
00078                 }
00079         }
00080 
00081         function testGetRevisionTextUtf8LegacyGzip() {
00082                 if ( !function_exists( 'gzdeflate' ) ) {
00083                         $this->markTestSkipped( 'Gzip compression is not enabled (requires zlib).' );
00084                 } else {
00085                         $row = new stdClass;
00086                         $row->old_flags = 'gzip';
00087                         $row->old_text = gzdeflate( "Wiki est l'\xe9cole superieur !" );
00088                         $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
00089                         $this->assertEquals(
00090                                 "Wiki est l'\xc3\xa9cole superieur !",
00091                                 Revision::getRevisionText( $row ) );
00092                 }
00093         }
00094 
00095         function testCompressRevisionTextUtf8() {
00096                 $row = new stdClass;
00097                 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
00098                 $row->old_flags = Revision::compressRevisionText( $row->old_text );
00099                 $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
00100                         "Flags should contain 'utf-8'" );
00101                 $this->assertFalse( false !== strpos( $row->old_flags, 'gzip' ),
00102                         "Flags should not contain 'gzip'" );
00103                 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
00104                         $row->old_text, "Direct check" );
00105                 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
00106                         Revision::getRevisionText( $row ), "getRevisionText" );
00107         }
00108 
00109         function testCompressRevisionTextUtf8Gzip() {
00110                 $GLOBALS['wgCompressRevisions'] = true;
00111                 $row = new stdClass;
00112                 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
00113                 $row->old_flags = Revision::compressRevisionText( $row->old_text );
00114                 $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
00115                         "Flags should contain 'utf-8'" );
00116                 $this->assertTrue( false !== strpos( $row->old_flags, 'gzip' ),
00117                         "Flags should contain 'gzip'" );
00118                 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
00119                         gzinflate( $row->old_text ), "Direct check" );
00120                 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
00121                         Revision::getRevisionText( $row ), "getRevisionText" );
00122         }
00123 }
00124 
00125