* Unescape two entities when transforming. Motivation is to allow to use "Foo&nbsp...
[lhc/web/wiklou.git] / t / inc / Revision.t
1 #!/usr/bin/env php
2 <?php
3
4 define( 'MEDIAWIKI', true );
5 require 't/Test.php';
6
7 plan( 19 );
8
9 require_ok( 'includes/Defines.php' );
10 require_ok( 'includes/ProfilerStub.php' );
11 require_ok( 'includes/GlobalFunctions.php' );
12 require_ok( 'languages/Language.php' );
13 require_ok( 'includes/Revision.php' );
14
15 $wgContLang = Language::factory( 'en' );
16 $wgLegacyEncoding = false;
17 $wgCompressRevisions = false;
18 $wgInputEncoding = 'utf-8';
19 $wgOutputEncoding = 'utf-8';
20
21 $row = new stdClass;
22 $row->old_flags = '';
23 $row->old_text = 'This is a bunch of revision text.';
24 cmp_ok( Revision::getRevisionText( $row ), '==',
25 'This is a bunch of revision text.', 'Get revision text' );
26
27 $row = new stdClass;
28 $row->old_flags = 'gzip';
29 $row->old_text = gzdeflate( 'This is a bunch of revision text.' );
30 cmp_ok( Revision::getRevisionText( $row ), '==',
31 'This is a bunch of revision text.', 'Get revision text with gzip compression' );
32
33 $wgLegacyEncoding = 'iso-8859-1';
34
35 $row = new stdClass;
36 $row->old_flags = 'utf-8';
37 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
38 cmp_ok( Revision::getRevisionText( $row ), '==',
39 "Wiki est l'\xc3\xa9cole superieur !", 'Get revision text utf-8 native' );
40
41 $row = new stdClass;
42 $row->old_flags = '';
43 $row->old_text = "Wiki est l'\xe9cole superieur !";
44 cmp_ok( Revision::getRevisionText( $row ), '==',
45 "Wiki est l'\xc3\xa9cole superieur !", 'Get revision text utf-8 legacy' );
46
47 $row = new stdClass;
48 $row->old_flags = 'gzip,utf-8';
49 $row->old_text = gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" );
50 cmp_ok( Revision::getRevisionText( $row ), '==',
51 "Wiki est l'\xc3\xa9cole superieur !", 'Get revision text utf-8 native and gzip' );
52
53 $row = new stdClass;
54 $row->old_flags = 'gzip';
55 $row->old_text = gzdeflate( "Wiki est l'\xe9cole superieur !" );
56 cmp_ok( Revision::getRevisionText( $row ), '==',
57 "Wiki est l'\xc3\xa9cole superieur !", 'Get revision text utf-8 native and gzip' );
58
59 $row = new stdClass;
60 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
61 $row->old_flags = Revision::compressRevisionText( $row->old_text );
62 like( $row->old_flags, '/utf-8/', "Flags should contain 'utf-8'" );
63 unlike( $row->old_flags, '/gzip/', "Flags should not contain 'gzip'" );
64 cmp_ok( $row->old_text, '==',
65 "Wiki est l'\xc3\xa9cole superieur !", "Direct check" );
66 cmp_ok( Revision::getRevisionText( $row ), '==',
67 "Wiki est l'\xc3\xa9cole superieur !", "getRevisionText" );
68
69 $wgCompressRevisions = true;
70
71 $row = new stdClass;
72 $row->old_text = "Wiki est l'\xc3\xa9cole superieur !";
73 $row->old_flags = Revision::compressRevisionText( $row->old_text );
74 like( $row->old_flags, '/utf-8/', "Flags should contain 'utf-8'" );
75 like( $row->old_flags, '/gzip/', "Flags should contain 'gzip'" );
76 cmp_ok( gzinflate( $row->old_text ), '==',
77 "Wiki est l'\xc3\xa9cole superieur !", "Direct check" );
78 cmp_ok( Revision::getRevisionText( $row ), '==',
79 "Wiki est l'\xc3\xa9cole superieur !", "getRevisionText" );