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'] = wfTempDir() . '/testReadOnly-' . mt_rand();
25 foreach( $this->save
as $var => $data ) {
26 $GLOBALS[$var] = $data;
30 function testRandom() {
31 # This could hypothetically fail, but it shouldn't ;)
33 wfRandom() == wfRandom() );
36 function testUrlencode() {
38 "%E7%89%B9%E5%88%A5:Contributions/Foobar",
39 wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
42 function testReadOnlyEmpty() {
43 $this->assertFalse( wfReadOnly() );
46 function testReadOnlySet() {
47 $f = fopen( $GLOBALS['wgReadOnlyFile'], "wt" );
48 fwrite( $f, 'Message' );
50 $this->assertTrue( wfReadOnly() );
52 unlink( $GLOBALS['wgReadOnlyFile'] );
53 $this->assertFalse( wfReadOnly() );
56 function testQuotedPrintable() {
58 "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
59 wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
64 $this->assertType( 'double', $start );
66 $this->assertTrue( $end > $start, "Time is running backwards!" );
69 function testArrayToCGI() {
73 array( 'baz' => 'AT&T', 'ignore' => '' ),
74 array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
77 function testMimeTypeMatch() {
80 mimeTypeMatch( 'text/html',
81 array( 'application/xhtml+xml' => 1.0,
83 'text/plain' => 0.3 ) ) );
86 mimeTypeMatch( 'text/html',
87 array( 'image/*' => 1.0,
88 'text/*' => 0.5 ) ) );
91 mimeTypeMatch( 'text/html',
92 array( '*/*' => 1.0 ) ) );
94 mimeTypeMatch( 'text/html',
95 array( 'image/png' => 1.0,
96 'image/svg+xml' => 0.5 ) ) );
99 function testNegotiateType() {
103 array( 'application/xhtml+xml' => 1.0,
107 array( 'text/html' => 1.0 ) ) );
109 'application/xhtml+xml',
111 array( 'application/xhtml+xml' => 1.0,
115 array( 'application/xhtml+xml' => 1.0,
116 'text/html' => 0.5 ) ) );
120 array( 'text/html' => 1.0,
123 'application/xhtml+xml' => 0.2 ),
124 array( 'application/xhtml+xml' => 1.0,
125 'text/html' => 0.5 ) ) );
129 array( 'text/*' => 1.0,
132 array( 'application/xhtml+xml' => 1.0,
133 'text/html' => 0.5 ) ) );
136 array( 'text/*' => 1.0 ),
137 array( 'application/xhtml+xml' => 1.0 ) ) );
140 function testTimestamp() {
141 $t = gmmktime( 12, 34, 56, 1, 15, 2001 );
144 wfTimestamp( TS_MW
, $t ),
145 'TS_UNIX to TS_MW' );
148 wfTimestamp( TS_UNIX
, $t ),
149 'TS_UNIX to TS_UNIX' );
151 '2001-01-15 12:34:56',
152 wfTimestamp( TS_DB
, $t ),
153 'TS_UNIX to TS_DB' );
157 wfTimestamp( TS_MW
, '20010115123456' ),
161 wfTimestamp( TS_UNIX
, '20010115123456' ),
162 'TS_MW to TS_UNIX' );
164 '2001-01-15 12:34:56',
165 wfTimestamp( TS_DB
, '20010115123456' ),
170 wfTimestamp( TS_MW
, '2001-01-15 12:34:56' ),
174 wfTimestamp( TS_UNIX
, '2001-01-15 12:34:56' ),
175 'TS_DB to TS_UNIX' );
177 '2001-01-15 12:34:56',
178 wfTimestamp( TS_DB
, '2001-01-15 12:34:56' ),
182 function testBasename() {
196 '\\aaaa\\' => 'aaaa',
197 '\\aaaa\\' => 'aaaa',
198 '/mnt/upload3/wikipedia/en/thumb/8/8b/Zork_Grand_Inquisitor_box_cover.jpg/93px-Zork_Grand_Inquisitor_box_cover.jpg' => '93px-Zork_Grand_Inquisitor_box_cover.jpg',
199 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
200 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
202 foreach( $sets as $from => $to ) {
203 $this->assertEquals( $to, wfBaseName( $from ),
204 "wfBaseName('$from') => '$to'");
208 /* TODO: many more! */