Merged filerepo-work branch:
[lhc/web/wiklou.git] / tests / ArticleTest.php
1 <?php
2
3 class ArticleTest extends PHPUnit_Framework_TestCase {
4 var $saveGlobals = array();
5
6 function setUp() {
7 $globalSet = array(
8 'wgLegacyEncoding' => false,
9 'wgUseLatin1' => false,
10 'wgCompressRevisions' => false,
11 'wgInputEncoding' => 'utf-8',
12 'wgOutputEncoding' => 'utf-8' );
13 foreach( $globalSet as $var => $data ) {
14 $this->saveGlobals[$var] = $GLOBALS[$var];
15 $GLOBALS[$var] = $data;
16 }
17 }
18
19 function tearDown() {
20 foreach( $this->saveGlobals as $var => $data ) {
21 $GLOBALS[$var] = $data;
22 }
23 }
24
25 function testGetRevisionText() {
26 $row = new stdClass;
27 $row->old_flags = '';
28 $row->old_text = 'This is a bunch of revision text.';
29 $this->assertEquals(
30 'This is a bunch of revision text.',
31 Revision::getRevisionText( $row ) );
32 }
33
34 function testGetRevisionTextGzip() {
35 $row = new stdClass;
36 $row->old_flags = 'gzip';
37 $row->old_text = gzdeflate( 'This is a bunch of revision text.' );
38 $this->assertEquals(
39 'This is a bunch of revision text.',
40 Revision::getRevisionText( $row ) );
41 }
42
43 function testGetRevisionTextUtf8Native() {
44 $row = new stdClass;
45 $row->old_flags = 'utf-8';
46 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
47 $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
48 $this->assertEquals(
49 "Wiki est l'\xc3\xa9cole superieur !",
50 Revision::getRevisionText( $row ) );
51 }
52
53 function testGetRevisionTextUtf8Legacy() {
54 $row = new stdClass;
55 $row->old_flags = '';
56 $row->old_text = "Wiki est l'\xe9cole superieur !";
57 $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
58 $this->assertEquals(
59 "Wiki est l'\xc3\xa9cole superieur !",
60 Revision::getRevisionText( $row ) );
61 }
62
63 function testGetRevisionTextUtf8NativeGzip() {
64 $row = new stdClass;
65 $row->old_flags = 'gzip,utf-8';
66 $row->old_text = gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" );
67 $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
68 $this->assertEquals(
69 "Wiki est l'\xc3\xa9cole superieur !",
70 Revision::getRevisionText( $row ) );
71 }
72
73 function testGetRevisionTextUtf8LegacyGzip() {
74 $row = new stdClass;
75 $row->old_flags = 'gzip';
76 $row->old_text = gzdeflate( "Wiki est l'\xe9cole superieur !" );
77 $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1';
78 $this->assertEquals(
79 "Wiki est l'\xc3\xa9cole superieur !",
80 Revision::getRevisionText( $row ) );
81 }
82
83 function testCompressRevisionTextUtf8() {
84 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
85 $row->old_flags = Revision::compressRevisionText( $row->old_text );
86 $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
87 "Flags should contain 'utf-8'" );
88 $this->assertFalse( false !== strpos( $row->old_flags, 'gzip' ),
89 "Flags should not contain 'gzip'" );
90 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
91 $row->old_text, "Direct check" );
92 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
93 Revision::getRevisionText( $row ), "getRevisionText" );
94 }
95
96 function testCompressRevisionTextUtf8Gzip() {
97 $GLOBALS['wgCompressRevisions'] = true;
98 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
99 $row->old_flags = Revision::compressRevisionText( $row->old_text );
100 $this->assertTrue( false !== strpos( $row->old_flags, 'utf-8' ),
101 "Flags should contain 'utf-8'" );
102 $this->assertTrue( false !== strpos( $row->old_flags, 'gzip' ),
103 "Flags should contain 'gzip'" );
104 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
105 gzinflate( $row->old_text ), "Direct check" );
106 $this->assertEquals( "Wiki est l'\xc3\xa9cole superieur !",
107 Revision::getRevisionText( $row ), "getRevisionText" );
108 }
109 }
110
111 ?>