3 class GlobalTest
extends PHPUnit_Framework_TestCase
{
5 global $wgReadOnlyFile;
6 $this->originals
['wgReadOnlyFile'] = $wgReadOnlyFile;
7 $wgReadOnlyFile = tempnam(wfTempDir(), "mwtest_readonly");
8 unlink( $wgReadOnlyFile );
12 global $wgReadOnlyFile;
13 if( file_exists( $wgReadOnlyFile ) ) {
14 unlink( $wgReadOnlyFile );
16 $wgReadOnlyFile = $this->originals
['wgReadOnlyFile'];
19 function testRandom() {
20 # This could hypothetically fail, but it shouldn't ;)
22 wfRandom() == wfRandom() );
25 function testUrlencode() {
27 "%E7%89%B9%E5%88%A5:Contributions/Foobar",
28 wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
31 function testReadOnlyEmpty() {
35 $this->assertFalse( wfReadOnly() );
36 $this->assertFalse( wfReadOnly() );
39 function testReadOnlySet() {
40 global $wgReadOnly, $wgReadOnlyFile;
42 $f = fopen( $wgReadOnlyFile, "wt" );
43 fwrite( $f, 'Message' );
47 $this->assertTrue( wfReadOnly() );
48 $this->assertTrue( wfReadOnly() );
50 unlink( $wgReadOnlyFile );
53 $this->assertFalse( wfReadOnly() );
54 $this->assertFalse( wfReadOnly() );
57 function testQuotedPrintable() {
59 "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
60 wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
65 $this->assertType( 'float', $start );
67 $this->assertTrue( $end > $start, "Time is running backwards!" );
70 function testArrayToCGI() {
74 array( 'baz' => 'AT&T', 'ignore' => '' ),
75 array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
78 function testMimeTypeMatch() {
81 mimeTypeMatch( 'text/html',
82 array( 'application/xhtml+xml' => 1.0,
84 'text/plain' => 0.3 ) ) );
87 mimeTypeMatch( 'text/html',
88 array( 'image/*' => 1.0,
89 'text/*' => 0.5 ) ) );
92 mimeTypeMatch( 'text/html',
93 array( '*/*' => 1.0 ) ) );
95 mimeTypeMatch( 'text/html',
96 array( 'image/png' => 1.0,
97 'image/svg+xml' => 0.5 ) ) );
100 function testNegotiateType() {
104 array( 'application/xhtml+xml' => 1.0,
108 array( 'text/html' => 1.0 ) ) );
110 'application/xhtml+xml',
112 array( 'application/xhtml+xml' => 1.0,
116 array( 'application/xhtml+xml' => 1.0,
117 'text/html' => 0.5 ) ) );
121 array( 'text/html' => 1.0,
124 'application/xhtml+xml' => 0.2 ),
125 array( 'application/xhtml+xml' => 1.0,
126 'text/html' => 0.5 ) ) );
130 array( 'text/*' => 1.0,
133 array( 'application/xhtml+xml' => 1.0,
134 'text/html' => 0.5 ) ) );
137 array( 'text/*' => 1.0 ),
138 array( 'application/xhtml+xml' => 1.0 ) ) );
141 function testTimestamp() {
142 $t = gmmktime( 12, 34, 56, 1, 15, 2001 );
145 wfTimestamp( TS_MW
, $t ),
146 'TS_UNIX to TS_MW' );
149 wfTimestamp( TS_UNIX
, $t ),
150 'TS_UNIX to TS_UNIX' );
152 '2001-01-15 12:34:56',
153 wfTimestamp( TS_DB
, $t ),
154 'TS_UNIX to TS_DB' );
158 wfTimestamp( TS_MW
, '20010115123456' ),
162 wfTimestamp( TS_UNIX
, '20010115123456' ),
163 'TS_MW to TS_UNIX' );
165 '2001-01-15 12:34:56',
166 wfTimestamp( TS_DB
, '20010115123456' ),
171 wfTimestamp( TS_MW
, '2001-01-15 12:34:56' ),
175 wfTimestamp( TS_UNIX
, '2001-01-15 12:34:56' ),
176 'TS_DB to TS_UNIX' );
178 '2001-01-15 12:34:56',
179 wfTimestamp( TS_DB
, '2001-01-15 12:34:56' ),
183 function testBasename() {
197 '\\aaaa\\' => 'aaaa',
198 '\\aaaa\\' => 'aaaa',
199 '/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',
200 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
201 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
203 foreach( $sets as $from => $to ) {
204 $this->assertEquals( $to, wfBaseName( $from ),
205 "wfBaseName('$from') => '$to'");
209 /* TODO: many more! */