00001 <?php
00002
00003 class RevisionTest extends PHPUnit_Framework_TestCase {
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 'wgInputEncoding' => 'utf-8',
00013 'wgOutputEncoding' => 'utf-8' );
00014 foreach( $globalSet as $var => $data ) {
00015 $this->saveGlobals[$var] = $GLOBALS[$var];
00016 $GLOBALS[$var] = $data;
00017 }
00018 }
00019
00020 function tearDown() {
00021 foreach( $this->saveGlobals as $var => $data ) {
00022 $GLOBALS[$var] = $data;
00023 }
00024 }
00025
00026 function testGetRevisionText() {
00027 $row = new stdClass;
00028 $row->old_flags = '';
00029 $row->old_text = 'This is a bunch of revision text.';
00030 $this->assertEquals(
00031 'This is a bunch of revision text.',
00032 Revision::getRevisionText( $row ) );
00033 }
00034
00035 function testGetRevisionTextGzip() {
00036 $row = new stdClass;
00037 $row->old_flags = 'gzip';
00038 $row->old_text = gzdeflate( 'This is a bunch of revision text.' );
00039 $this->assertEquals(
00040 'This is a bunch of revision text.',
00041 Revision::getRevisionText( $row ) );
00042 }
00043
00044 function testGetRevisionTextUtf8Native() {
00045 $row = new stdClass;
00046 $row->old_flags = 'utf-8';
00047 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
00048 $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
00049 $this->assertEquals(
00050 "Wiki est l'\xc3\xa9cole superieur !",
00051 Revision::getRevisionText( $row ) );
00052 }
00053
00054 function testGetRevisionTextUtf8Legacy() {
00055 $row = new stdClass;
00056 $row->old_flags = '';
00057 $row->old_text = "Wiki est l'\xe9cole superieur !";
00058 $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
00059 $this->assertEquals(
00060 "Wiki est l'\xc3\xa9cole superieur !",
00061 Revision::getRevisionText( $row ) );
00062 }
00063
00064 function testGetRevisionTextUtf8NativeGzip() {
00065 $row = new stdClass;
00066 $row->old_flags = 'gzip,utf-8';
00067 $row->old_text = gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" );
00068 $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
00069 $this->assertEquals(
00070 "Wiki est l'\xc3\xa9cole superieur !",
00071 Revision::getRevisionText( $row ) );
00072 }
00073
00074 function testGetRevisionTextUtf8LegacyGzip() {
00075 $row = new stdClass;
00076 $row->old_flags = 'gzip';
00077 $row->old_text = gzdeflate( "Wiki est l'\xe9cole superieur !" );
00078 $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
00079 $this->assertEquals(
00080 "Wiki est l'\xc3\xa9cole superieur !",
00081 Revision::getRevisionText( $row ) );
00082 }
00083
00084 function testCompressRevisionTextUtf8() {
00085 $row = new stdClass;
00086 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
00087 $row->old_flags = Revision::compressRevisionText( $row->old_text );
00088 $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
00089 "Flags should contain 'utf-8'" );
00090 $this->assertFalse( false !== strpos( $row->old_flags, 'gzip' ),
00091 "Flags should not contain 'gzip'" );
00092 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
00093 $row->old_text, "Direct check" );
00094 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
00095 Revision::getRevisionText( $row ), "getRevisionText" );
00096 }
00097
00098 function testCompressRevisionTextUtf8Gzip() {
00099 $GLOBALS['wgCompressRevisions'] = true;
00100 $row = new stdClass;
00101 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
00102 $row->old_flags = Revision::compressRevisionText( $row->old_text );
00103 $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
00104 "Flags should contain 'utf-8'" );
00105 $this->assertTrue( false !== strpos( $row->old_flags, 'gzip' ),
00106 "Flags should contain 'gzip'" );
00107 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
00108 gzinflate( $row->old_text ), "Direct check" );
00109 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
00110 Revision::getRevisionText( $row ), "getRevisionText" );
00111 }
00112 }
00113
00114