3 class GlobalTest
extends PHPUnit_Framework_TestCase
{
5 global $wgReadOnlyFile, $wgContLang, $wgLang;
6 $this->originals
['wgReadOnlyFile'] = $wgReadOnlyFile;
7 $wgReadOnlyFile = tempnam( wfTempDir(), "mwtest_readonly" );
8 unlink( $wgReadOnlyFile );
9 $wgContLang = $wgLang = Language
::factory( 'en' );
13 global $wgReadOnlyFile;
14 if ( file_exists( $wgReadOnlyFile ) ) {
15 unlink( $wgReadOnlyFile );
17 $wgReadOnlyFile = $this->originals
['wgReadOnlyFile'];
20 function testRandom() {
21 # This could hypothetically fail, but it shouldn't ;)
23 wfRandom() == wfRandom() );
26 function testUrlencode() {
28 "%E7%89%B9%E5%88%A5:Contributions/Foobar",
29 wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
32 function testReadOnlyEmpty() {
36 $this->assertFalse( wfReadOnly() );
37 $this->assertFalse( wfReadOnly() );
40 function testReadOnlySet() {
41 global $wgReadOnly, $wgReadOnlyFile;
43 $f = fopen( $wgReadOnlyFile, "wt" );
44 fwrite( $f, 'Message' );
48 $this->assertTrue( wfReadOnly() );
49 $this->assertTrue( wfReadOnly() );
51 unlink( $wgReadOnlyFile );
54 $this->assertFalse( wfReadOnly() );
55 $this->assertFalse( wfReadOnly() );
58 function testQuotedPrintable() {
60 "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
61 wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
66 $this->assertType( 'float', $start );
68 $this->assertTrue( $end > $start, "Time is running backwards!" );
71 function testArrayToCGI() {
75 array( 'baz' => 'AT&T', 'ignore' => '' ),
76 array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
79 function testMimeTypeMatch() {
82 mimeTypeMatch( 'text/html',
83 array( 'application/xhtml+xml' => 1.0,
85 'text/plain' => 0.3 ) ) );
88 mimeTypeMatch( 'text/html',
89 array( 'image/*' => 1.0,
90 'text/*' => 0.5 ) ) );
93 mimeTypeMatch( 'text/html',
94 array( '*/*' => 1.0 ) ) );
96 mimeTypeMatch( 'text/html',
97 array( 'image/png' => 1.0,
98 'image/svg+xml' => 0.5 ) ) );
101 function testNegotiateType() {
105 array( 'application/xhtml+xml' => 1.0,
109 array( 'text/html' => 1.0 ) ) );
111 'application/xhtml+xml',
113 array( 'application/xhtml+xml' => 1.0,
117 array( 'application/xhtml+xml' => 1.0,
118 'text/html' => 0.5 ) ) );
122 array( 'text/html' => 1.0,
125 'application/xhtml+xml' => 0.2 ),
126 array( 'application/xhtml+xml' => 1.0,
127 'text/html' => 0.5 ) ) );
131 array( 'text/*' => 1.0,
134 array( 'application/xhtml+xml' => 1.0,
135 'text/html' => 0.5 ) ) );
138 array( 'text/*' => 1.0 ),
139 array( 'application/xhtml+xml' => 1.0 ) ) );
142 function testTimestamp() {
143 $t = gmmktime( 12, 34, 56, 1, 15, 2001 );
146 wfTimestamp( TS_MW
, $t ),
147 'TS_UNIX to TS_MW' );
150 wfTimestamp( TS_UNIX
, $t ),
151 'TS_UNIX to TS_UNIX' );
153 '2001-01-15 12:34:56',
154 wfTimestamp( TS_DB
, $t ),
155 'TS_UNIX to TS_DB' );
158 wfTimestamp( TS_ISO_8601_BASIC
, $t ),
159 'TS_ISO_8601_BASIC to TS_DB' );
163 wfTimestamp( TS_MW
, '20010115123456' ),
167 wfTimestamp( TS_UNIX
, '20010115123456' ),
168 'TS_MW to TS_UNIX' );
170 '2001-01-15 12:34:56',
171 wfTimestamp( TS_DB
, '20010115123456' ),
175 wfTimestamp( TS_ISO_8601_BASIC
, '20010115123456' ),
176 'TS_MW to TS_ISO_8601_BASIC' );
180 wfTimestamp( TS_MW
, '2001-01-15 12:34:56' ),
184 wfTimestamp( TS_UNIX
, '2001-01-15 12:34:56' ),
185 'TS_DB to TS_UNIX' );
187 '2001-01-15 12:34:56',
188 wfTimestamp( TS_DB
, '2001-01-15 12:34:56' ),
192 wfTimestamp( TS_ISO_8601_BASIC
, '2001-01-15 12:34:56' ),
193 'TS_DB to TS_ISO_8601_BASIC' );
196 function testBasename() {
210 '\\aaaa\\' => 'aaaa',
211 '\\aaaa\\' => 'aaaa',
212 '/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',
213 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
214 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
216 foreach ( $sets as $from => $to ) {
217 $this->assertEquals( $to, wfBaseName( $from ),
218 "wfBaseName('$from') => '$to'" );
222 /* TODO: many more! */