3 class GlobalTest
extends PHPUnit_Framework_TestCase
{
4 function testRandom() {
5 # This could hypothetically fail, but it shouldn't ;)
7 wfRandom() == wfRandom() );
10 function testUrlencode() {
12 "%E7%89%B9%E5%88%A5:Contributions/Foobar",
13 wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
16 function testReadOnlyEmpty() {
17 $this->assertFalse( wfReadOnly() );
20 function testReadOnlySet() {
21 $f = fopen( $GLOBALS['wgReadOnlyFile'], "wt" );
22 fwrite( $f, 'Message' );
24 $this->assertTrue( wfReadOnly() );
26 unlink( $GLOBALS['wgReadOnlyFile'] );
27 $this->assertFalse( wfReadOnly() );
30 function testQuotedPrintable() {
32 "=?UTF-8?Q?=C4=88u=20legebla=3F?=",
33 wfQuotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) );
38 $this->assertType( 'double', $start );
40 $this->assertTrue( $end > $start, "Time is running backwards!" );
43 function testArrayToCGI() {
47 array( 'baz' => 'AT&T', 'ignore' => '' ),
48 array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
51 function testMimeTypeMatch() {
54 mimeTypeMatch( 'text/html',
55 array( 'application/xhtml+xml' => 1.0,
57 'text/plain' => 0.3 ) ) );
60 mimeTypeMatch( 'text/html',
61 array( 'image/*' => 1.0,
62 'text/*' => 0.5 ) ) );
65 mimeTypeMatch( 'text/html',
66 array( '*/*' => 1.0 ) ) );
68 mimeTypeMatch( 'text/html',
69 array( 'image/png' => 1.0,
70 'image/svg+xml' => 0.5 ) ) );
73 function testNegotiateType() {
77 array( 'application/xhtml+xml' => 1.0,
81 array( 'text/html' => 1.0 ) ) );
83 'application/xhtml+xml',
85 array( 'application/xhtml+xml' => 1.0,
89 array( 'application/xhtml+xml' => 1.0,
90 'text/html' => 0.5 ) ) );
94 array( 'text/html' => 1.0,
97 'application/xhtml+xml' => 0.2 ),
98 array( 'application/xhtml+xml' => 1.0,
99 'text/html' => 0.5 ) ) );
103 array( 'text/*' => 1.0,
106 array( 'application/xhtml+xml' => 1.0,
107 'text/html' => 0.5 ) ) );
110 array( 'text/*' => 1.0 ),
111 array( 'application/xhtml+xml' => 1.0 ) ) );
114 function testTimestamp() {
115 $t = gmmktime( 12, 34, 56, 1, 15, 2001 );
118 wfTimestamp( TS_MW
, $t ),
119 'TS_UNIX to TS_MW' );
122 wfTimestamp( TS_UNIX
, $t ),
123 'TS_UNIX to TS_UNIX' );
125 '2001-01-15 12:34:56',
126 wfTimestamp( TS_DB
, $t ),
127 'TS_UNIX to TS_DB' );
131 wfTimestamp( TS_MW
, '20010115123456' ),
135 wfTimestamp( TS_UNIX
, '20010115123456' ),
136 'TS_MW to TS_UNIX' );
138 '2001-01-15 12:34:56',
139 wfTimestamp( TS_DB
, '20010115123456' ),
144 wfTimestamp( TS_MW
, '2001-01-15 12:34:56' ),
148 wfTimestamp( TS_UNIX
, '2001-01-15 12:34:56' ),
149 'TS_DB to TS_UNIX' );
151 '2001-01-15 12:34:56',
152 wfTimestamp( TS_DB
, '2001-01-15 12:34:56' ),
156 function testBasename() {
170 '\\aaaa\\' => 'aaaa',
171 '\\aaaa\\' => 'aaaa',
172 '/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',
173 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE',
174 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png',
176 foreach( $sets as $from => $to ) {
177 $this->assertEquals( $to, wfBaseName( $from ),
178 "wfBaseName('$from') => '$to'");
182 /* TODO: many more! */