3 require_once( 'PHPUnit.php' );
4 require_once( '../includes/Defines.php' );
5 require_once( '../includes/Profiling.php' );
6 require_once( '../includes/GlobalFunctions.php' );
8 class GlobalTest
extends PHPUnit_TestCase
{
9 function GlobalTest( $name ) {
10 $this->PHPUnit_TestCase( $name );
14 $this->save
= array();
15 $saveVars = array( 'wgReadOnlyFile' );
16 foreach( $saveVars as $var ) {
17 if( isset( $GLOBALS[$var] ) ) {
18 $this->save
[$var] = $GLOBALS[$var];
21 $GLOBALS['wgReadOnlyFile'] = '/tmp/testReadOnly-' . mt_rand();
25 foreach( $this->save
as $var => $data ) {
26 $GLOBALS[$var] = $data;
30 function testDecodeLatin() {
33 do_html_entity_decode( 'école', ENT_COMPAT
, 'iso-8859-1' ) );
36 function testDecodeUnicode() {
39 do_html_entity_decode( 'école', ENT_COMPAT
, 'utf-8' ) );
42 function testRandom() {
43 # This could hypothetically fail, but it shouldn't ;)
45 wfRandom() == wfRandom() );
48 function testUrlencode() {
50 "%E7%89%B9%E5%88%A5:Contributions/Foobar",
51 wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
54 function testUtf8Sequence1() {
57 wfUtf8Sequence( 65 ) );
60 function testUtf8Sequence2() {
63 wfUtf8Sequence( 0x108 ) );
66 function testUtf8Sequence3() {
69 wfUtf8Sequence( 0x304b ) );
72 function testUtf8Sequence4() {
75 wfUtf8Sequence( 0x10450 ) );
78 function testMungeToUtf8() {
80 "\xc4\x88io bonas dans l'\xc3\xa9cole!",
81 wfMungeToUtf8( "Ĉio bonas dans l'école!" ) );
84 function testUtf8ToHTML() {
86 "Ĉio bonas dans l'école!",
87 wfUtf8ToHTML( "\xc4\x88io bonas dans l'\xc3\xa9cole!" ) );
90 function testReadOnlyEmpty() {
91 $this->assertFalse( wfReadOnly() );
94 function testReadOnlySet() {
95 $f = fopen( $GLOBALS['wgReadOnlyFile'], "wt" );
96 fwrite( $f, 'Message' );
98 $this->assertTrue( wfReadOnly() );
100 unlink( $GLOBALS['wgReadOnlyFile'] );
101 $this->assertFalse( wfReadOnly() );
104 function testQuotedPrintable() {
106 "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
107 wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
110 function testTime() {
112 $this->assertType( 'double', $start );
114 $this->assertTrue( $end > $start, "Time is running backwards!" );
117 function testArrayToCGI() {
119 "baz=AT%26T&foo=bar",
121 array( 'baz' => 'AT&T', 'ignore' => '' ),
122 array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
125 function testMimeTypeMatch() {
128 mimeTypeMatch( 'text/html',
129 array( 'application/xhtml+xml' => 1.0,
131 'text/plain' => 0.3 ) ) );
134 mimeTypeMatch( 'text/html',
135 array( 'image/*' => 1.0,
136 'text/*' => 0.5 ) ) );
139 mimeTypeMatch( 'text/html',
140 array( '*/*' => 1.0 ) ) );
142 mimeTypeMatch( 'text/html',
143 array( 'image/png' => 1.0,
144 'image/svg+xml' => 0.5 ) ) );
147 function testNegotiateType() {
151 array( 'application/xhtml+xml' => 1.0,
155 array( 'text/html' => 1.0 ) ) );
157 'application/xhtml+xml',
159 array( 'application/xhtml+xml' => 1.0,
163 array( 'application/xhtml+xml' => 1.0,
164 'text/html' => 0.5 ) ) );
168 array( 'text/html' => 1.0,
171 'application/xhtml+xml' => 0.2 ),
172 array( 'application/xhtml+xml' => 1.0,
173 'text/html' => 0.5 ) ) );
177 array( 'text/*' => 1.0,
180 array( 'application/xhtml+xml' => 1.0,
181 'text/html' => 0.5 ) ) );
184 array( 'text/*' => 1.0 ),
185 array( 'application/xhtml+xml' => 1.0 ) ) );
188 function testTimestamp() {
189 $t = gmmktime( 12, 34, 56, 1, 15, 2001 );
192 wfTimestamp( TS_MW
, $t ),
193 'TS_UNIX to TS_MW' );
196 wfTimestamp( TS_UNIX
, $t ),
197 'TS_UNIX to TS_UNIX' );
199 '2001-01-15 12:34:56',
200 wfTimestamp( TS_DB
, $t ),
201 'TS_UNIX to TS_DB' );
205 wfTimestamp( TS_MW
, '20010115123456' ),
209 wfTimestamp( TS_UNIX
, '20010115123456' ),
210 'TS_MW to TS_UNIX' );
212 '2001-01-15 12:34:56',
213 wfTimestamp( TS_DB
, '20010115123456' ),
218 wfTimestamp( TS_MW
, '2001-01-15 12:34:56' ),
222 wfTimestamp( TS_UNIX
, '2001-01-15 12:34:56' ),
223 'TS_DB to TS_UNIX' );
225 '2001-01-15 12:34:56',
226 wfTimestamp( TS_DB
, '2001-01-15 12:34:56' ),
230 /* TODO: many more! */