3 require_once( 'PHPUnit.php' );
4 require_once( '../includes/Defines.php' );
5 require_once( '../includes/GlobalFunctions.php' );
7 class GlobalTest
extends PHPUnit_TestCase
{
8 function GlobalTest( $name ) {
9 $this->PHPUnit_TestCase( $name );
13 $this->save
= array();
14 $saveVars = array( 'wgReadOnlyFile' );
15 foreach( $saveVars as $var ) {
16 if( isset( $GLOBALS[$var] ) ) {
17 $this->save
[$var] = $GLOBALS[$var];
20 $GLOBALS['wgReadOnlyFile'] = '/tmp/testReadOnly-' . mt_rand();
24 foreach( $this->save
as $var => $data ) {
25 $GLOBALS[$var] = $data;
29 function testDecodeLatin() {
32 do_html_entity_decode( 'école', ENT_COMPAT
, 'iso-8859-1' ) );
35 function testDecodeUnicode() {
38 do_html_entity_decode( 'école', ENT_COMPAT
, 'utf-8' ) );
41 function testRandom() {
42 # This could hypothetically fail, but it shouldn't ;)
44 wfRandom() == wfRandom() );
47 function testUrlencode() {
49 "%E7%89%B9%E5%88%A5:Contributions/Foobar",
50 wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
53 function testUtf8Sequence1() {
56 wfUtf8Sequence( 65 ) );
59 function testUtf8Sequence2() {
62 wfUtf8Sequence( 0x108 ) );
65 function testUtf8Sequence3() {
68 wfUtf8Sequence( 0x304b ) );
71 function testUtf8Sequence4() {
74 wfUtf8Sequence( 0x10450 ) );
77 function testMungeToUtf8() {
79 "\xc4\x88io bonas dans l'\xc3\xa9cole!",
80 wfMungeToUtf8( "Ĉio bonas dans l'école!" ) );
83 function testUtf8ToHTML() {
85 "Ĉio bonas dans l'école!",
86 wfUtf8ToHTML( "\xc4\x88io bonas dans l'\xc3\xa9cole!" ) );
89 function testReadOnlyEmpty() {
90 $this->assertFalse( wfReadOnly() );
93 function testReadOnlySet() {
94 $f = fopen( $GLOBALS['wgReadOnlyFile'], "wt" );
95 fwrite( $f, 'Message' );
97 $this->assertTrue( wfReadOnly() );
99 unlink( $GLOBALS['wgReadOnlyFile'] );
100 $this->assertFalse( wfReadOnly() );
103 function testQuotedPrintable() {
105 "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
106 wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
109 function testTime() {
111 $this->assertType( 'double', $start );
113 $this->assertTrue( $end > $start, "Time is running backwards!" );
116 function testArrayToCGI() {
118 "baz=AT%26T&foo=bar",
120 array( 'baz' => 'AT&T', 'ignore' => '' ),
121 array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
124 function testMimeTypeMatch() {
127 mimeTypeMatch( 'text/html',
128 array( 'application/xhtml+xml' => 1.0,
130 'text/plain' => 0.3 ) ) );
133 mimeTypeMatch( 'text/html',
134 array( 'image/*' => 1.0,
135 'text/*' => 0.5 ) ) );
138 mimeTypeMatch( 'text/html',
139 array( '*/*' => 1.0 ) ) );
141 mimeTypeMatch( 'text/html',
142 array( 'image/png' => 1.0,
143 'image/svg+xml' => 0.5 ) ) );
146 function testNegotiateType() {
150 array( 'application/xhtml+xml' => 1.0,
154 array( 'text/html' => 1.0 ) ) );
156 'application/xhtml+xml',
158 array( 'application/xhtml+xml' => 1.0,
162 array( 'application/xhtml+xml' => 1.0,
163 'text/html' => 0.5 ) ) );
167 array( 'text/html' => 1.0,
170 'application/xhtml+xml' => 0.2 ),
171 array( 'application/xhtml+xml' => 1.0,
172 'text/html' => 0.5 ) ) );
176 array( 'text/*' => 1.0,
179 array( 'application/xhtml+xml' => 1.0,
180 'text/html' => 0.5 ) ) );
183 array( 'text/*' => 1.0 ),
184 array( 'application/xhtml+xml' => 1.0 ) ) );
187 function testTimestamp() {
188 $t = gmmktime( 12, 34, 56, 1, 15, 2001 );
191 wfTimestamp( TS_MW
, $t ),
192 'TS_UNIX to TS_MW' );
195 wfTimestamp( TS_UNIX
, $t ),
196 'TS_UNIX to TS_UNIX' );
198 '2001-01-15 12:34:56',
199 wfTimestamp( TS_DB
, $t ),
200 'TS_UNIX to TS_DB' );
204 wfTimestamp( TS_MW
, '20010115123456' ),
208 wfTimestamp( TS_UNIX
, '20010115123456' ),
209 'TS_MW to TS_UNIX' );
211 '2001-01-15 12:34:56',
212 wfTimestamp( TS_DB
, '20010115123456' ),
217 wfTimestamp( TS_MW
, '2001-01-15 12:34:56' ),
221 wfTimestamp( TS_UNIX
, '2001-01-15 12:34:56' ),
222 'TS_DB to TS_UNIX' );
224 '2001-01-15 12:34:56',
225 wfTimestamp( TS_DB
, '2001-01-15 12:34:56' ),
229 /* TODO: many more! */