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