Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php |
— | — | @@ -0,0 +1,123 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Tests for includes/GlobalFunctions.php -> wfUrlencode() |
| 5 | + * |
| 6 | + * The function only need a string parameter and might react to IIS7.0 |
| 7 | + */ |
| 8 | + |
| 9 | +class wfUrlencodeTest extends MediaWikiTestCase { |
| 10 | + |
| 11 | + #### TESTS ############################################################## |
| 12 | + |
| 13 | + /** @dataProvider provideURLS */ |
| 14 | + public function testEncodingUrlWith( $input, $expected ) { |
| 15 | + $this->verifyEncodingFor( 'Apache', $input, $expected ); |
| 16 | + } |
| 17 | + |
| 18 | + /** @dataProvider provideURLS */ |
| 19 | + public function testEncodingUrlWithMicrosoftIis7( $input, $expected ) { |
| 20 | + $this->verifyEncodingFor( 'Microsoft-IIS/7', $input, $expected ); |
| 21 | + } |
| 22 | + |
| 23 | + #### HELPERS ############################################################# |
| 24 | + |
| 25 | + /** |
| 26 | + * Internal helper that actually run the test. |
| 27 | + * Called by the public methods testEncodingUrlWith...() |
| 28 | + * |
| 29 | + */ |
| 30 | + private function verifyEncodingFor( $server, $input, $expectations ) { |
| 31 | + $expected = $this->extractExpect( $server, $expectations ); |
| 32 | + |
| 33 | + // save up global |
| 34 | + $old = isset($_SERVER['SERVER_SOFTWARE']) |
| 35 | + ? $_SERVER['SERVER_SOFTWARE'] |
| 36 | + : null |
| 37 | + ; |
| 38 | + $_SERVER['SERVER_SOFTWARE'] = $server; |
| 39 | + |
| 40 | + // do the requested test |
| 41 | + $this->assertEquals( |
| 42 | + $expected, |
| 43 | + wfUrlencode( $input ), |
| 44 | + "Encoding '$input' for server '$server' should be '$expected'" |
| 45 | + ); |
| 46 | + |
| 47 | + // restore global |
| 48 | + if( $old === null ) { |
| 49 | + unset( $_SERVER['SERVER_SOFTWARE'] ); |
| 50 | + } else { |
| 51 | + $_SERVER['SERVER_SOFTWARE'] = $old; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Interprets the provider array. Return expected value depending |
| 57 | + * the HTTP server name. |
| 58 | + */ |
| 59 | + private function extractExpect( $server, $expectations ) { |
| 60 | + if( is_string( $expectations ) ) { |
| 61 | + return $expectations; |
| 62 | + } elseif( is_array( $expectations ) ) { |
| 63 | + |
| 64 | + /** |
| 65 | + * FIXME FIXME FIXME FIXME |
| 66 | + * wfUrlencode use a static variable so we can not just |
| 67 | + * change the $GLOBALS server name :( |
| 68 | + */ |
| 69 | + $this->markTestSkipped( 'FIXME: wfUrlencode() use a static, thus changing $GLOBALS[SERVER_SOFTWARE] is useless' ); |
| 70 | + |
| 71 | + if( !array_key_exists( $server, $expectations ) ) { |
| 72 | + throw new MWException( __METHOD__ . " expectation does not have any value for server name $server. Check the provider array.\n" ); |
| 73 | + } else { |
| 74 | + return $expectations[$server]; |
| 75 | + } |
| 76 | + } else { |
| 77 | + throw new MWException( __METHOD__ . " given invalid expectation for '$server'. Should be a string or an array( <http server name> => <string> ).\n" ); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + |
| 82 | + #### PROVIDERS ########################################################### |
| 83 | + |
| 84 | + /** |
| 85 | + * Format is either: |
| 86 | + * array( 'input', 'expected' ); |
| 87 | + * Or: |
| 88 | + * array( 'input', |
| 89 | + * array( 'Apache', 'expected' ), |
| 90 | + * array( 'Microsoft-IIS/7', 'expected' ), |
| 91 | + * ), |
| 92 | + * If you want to add other HTTP server name, you will have to add a new |
| 93 | + * testing method much like the testEncodingUrlWith() method above. |
| 94 | + */ |
| 95 | + public function provideURLS() { |
| 96 | + return array( |
| 97 | + ### RFC 1738 chars |
| 98 | + // + is not safe |
| 99 | + array( '+', '%2B' ), |
| 100 | + // & and = not safe in queries |
| 101 | + array( '&', '%26' ), |
| 102 | + array( '=', '%3D' ), |
| 103 | + |
| 104 | + array( ':', array( |
| 105 | + 'Apache' => ':', |
| 106 | + 'Microsoft-IIS/7' => '%3A', |
| 107 | + ) ), |
| 108 | + |
| 109 | + // remaining chars do not need encoding |
| 110 | + array( |
| 111 | + ';@$-_.!*', |
| 112 | + ';@$-_.!*', |
| 113 | + ), |
| 114 | + |
| 115 | + ### Other tests |
| 116 | + // slash remain unchanged. %2F seems to break things |
| 117 | + array( '/', '/' ), |
| 118 | + |
| 119 | + // Other 'funnies' chars |
| 120 | + array( '[]', '%5B%5D' ), |
| 121 | + array( '<>', '%3C%3E' ), |
| 122 | + ); |
| 123 | + } |
| 124 | +} |
Property changes on: trunk/phase3/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 125 | + native |
Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php |
— | — | @@ -0,0 +1,901 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +class GlobalTest extends MediaWikiTestCase { |
| 5 | + function setUp() { |
| 6 | + global $wgReadOnlyFile, $wgContLang, $wgLang, $wgUrlProtocols, $wgLanguageCode; |
| 7 | + $this->originals['wgReadOnlyFile'] = $wgReadOnlyFile; |
| 8 | + $this->originals['wgUrlProtocols'] = $wgUrlProtocols; |
| 9 | + $wgReadOnlyFile = tempnam( wfTempDir(), "mwtest_readonly" ); |
| 10 | + $wgUrlProtocols[] = 'file://'; |
| 11 | + unlink( $wgReadOnlyFile ); |
| 12 | + $wgLanguageCode = 'en'; |
| 13 | + $wgContLang = $wgLang = Language::factory( 'en' ); |
| 14 | + } |
| 15 | + |
| 16 | + function tearDown() { |
| 17 | + global $wgReadOnlyFile, $wgUrlProtocols; |
| 18 | + if ( file_exists( $wgReadOnlyFile ) ) { |
| 19 | + unlink( $wgReadOnlyFile ); |
| 20 | + } |
| 21 | + $wgReadOnlyFile = $this->originals['wgReadOnlyFile']; |
| 22 | + $wgUrlProtocols = $this->originals['wgUrlProtocols']; |
| 23 | + } |
| 24 | + |
| 25 | + /** @dataProvider provideForWfArrayDiff2 */ |
| 26 | + public function testWfArrayDiff2( $a, $b, $expected ) { |
| 27 | + $this->assertEquals( |
| 28 | + wfArrayDiff2( $a, $b), $expected |
| 29 | + ); |
| 30 | + } |
| 31 | + |
| 32 | + // @todo Provide more tests |
| 33 | + public function provideForWfArrayDiff2() { |
| 34 | + // $a $b $expected |
| 35 | + return array( |
| 36 | + array( |
| 37 | + array( 'a', 'b'), |
| 38 | + array( 'a', 'b'), |
| 39 | + array(), |
| 40 | + ), |
| 41 | + array( |
| 42 | + array( array( 'a'), array( 'a', 'b', 'c' )), |
| 43 | + array( array( 'a'), array( 'a', 'b' )), |
| 44 | + array( 1 => array( 'a', 'b', 'c' ) ), |
| 45 | + ), |
| 46 | + ); |
| 47 | + } |
| 48 | + |
| 49 | + function testRandom() { |
| 50 | + # This could hypothetically fail, but it shouldn't ;) |
| 51 | + $this->assertFalse( |
| 52 | + wfRandom() == wfRandom() ); |
| 53 | + } |
| 54 | + |
| 55 | + function testUrlencode() { |
| 56 | + $this->assertEquals( |
| 57 | + "%E7%89%B9%E5%88%A5:Contributions/Foobar", |
| 58 | + wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) ); |
| 59 | + } |
| 60 | + |
| 61 | + function testReadOnlyEmpty() { |
| 62 | + global $wgReadOnly; |
| 63 | + $wgReadOnly = null; |
| 64 | + |
| 65 | + $this->assertFalse( wfReadOnly() ); |
| 66 | + $this->assertFalse( wfReadOnly() ); |
| 67 | + } |
| 68 | + |
| 69 | + function testReadOnlySet() { |
| 70 | + global $wgReadOnly, $wgReadOnlyFile; |
| 71 | + |
| 72 | + $f = fopen( $wgReadOnlyFile, "wt" ); |
| 73 | + fwrite( $f, 'Message' ); |
| 74 | + fclose( $f ); |
| 75 | + $wgReadOnly = null; # Check on $wgReadOnlyFile |
| 76 | + |
| 77 | + $this->assertTrue( wfReadOnly() ); |
| 78 | + $this->assertTrue( wfReadOnly() ); # Check cached |
| 79 | + |
| 80 | + unlink( $wgReadOnlyFile ); |
| 81 | + $wgReadOnly = null; # Clean cache |
| 82 | + |
| 83 | + $this->assertFalse( wfReadOnly() ); |
| 84 | + $this->assertFalse( wfReadOnly() ); |
| 85 | + } |
| 86 | + |
| 87 | + function testQuotedPrintable() { |
| 88 | + $this->assertEquals( |
| 89 | + "=?UTF-8?Q?=C4=88u=20legebla=3F?=", |
| 90 | + UserMailer::quotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) ); |
| 91 | + } |
| 92 | + |
| 93 | + function testTime() { |
| 94 | + $start = wfTime(); |
| 95 | + $this->assertInternalType( 'float', $start ); |
| 96 | + $end = wfTime(); |
| 97 | + $this->assertTrue( $end > $start, "Time is running backwards!" ); |
| 98 | + } |
| 99 | + |
| 100 | + function testArrayToCGI() { |
| 101 | + $this->assertEquals( |
| 102 | + "baz=AT%26T&foo=bar", |
| 103 | + wfArrayToCGI( |
| 104 | + array( 'baz' => 'AT&T', 'ignore' => '' ), |
| 105 | + array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) ); |
| 106 | + $this->assertEquals( |
| 107 | + "path%5B0%5D=wiki&path%5B1%5D=test&cfg%5Bservers%5D%5Bhttp%5D=localhost", |
| 108 | + wfArrayToCGI( array( |
| 109 | + 'path' => array( 'wiki', 'test' ), |
| 110 | + 'cfg' => array( 'servers' => array( 'http' => 'localhost' ) ) ) ) ); |
| 111 | + } |
| 112 | + |
| 113 | + function testCgiToArray() { |
| 114 | + $this->assertEquals( |
| 115 | + array( 'path' => array( 'wiki', 'test' ), |
| 116 | + 'cfg' => array( 'servers' => array( 'http' => 'localhost' ) ) ), |
| 117 | + wfCgiToArray( 'path%5B0%5D=wiki&path%5B1%5D=test&cfg%5Bservers%5D%5Bhttp%5D=localhost' ) ); |
| 118 | + } |
| 119 | + |
| 120 | + function testMimeTypeMatch() { |
| 121 | + $this->assertEquals( |
| 122 | + 'text/html', |
| 123 | + mimeTypeMatch( 'text/html', |
| 124 | + array( 'application/xhtml+xml' => 1.0, |
| 125 | + 'text/html' => 0.7, |
| 126 | + 'text/plain' => 0.3 ) ) ); |
| 127 | + $this->assertEquals( |
| 128 | + 'text/*', |
| 129 | + mimeTypeMatch( 'text/html', |
| 130 | + array( 'image/*' => 1.0, |
| 131 | + 'text/*' => 0.5 ) ) ); |
| 132 | + $this->assertEquals( |
| 133 | + '*/*', |
| 134 | + mimeTypeMatch( 'text/html', |
| 135 | + array( '*/*' => 1.0 ) ) ); |
| 136 | + $this->assertNull( |
| 137 | + mimeTypeMatch( 'text/html', |
| 138 | + array( 'image/png' => 1.0, |
| 139 | + 'image/svg+xml' => 0.5 ) ) ); |
| 140 | + } |
| 141 | + |
| 142 | + function testNegotiateType() { |
| 143 | + $this->assertEquals( |
| 144 | + 'text/html', |
| 145 | + wfNegotiateType( |
| 146 | + array( 'application/xhtml+xml' => 1.0, |
| 147 | + 'text/html' => 0.7, |
| 148 | + 'text/plain' => 0.5, |
| 149 | + 'text/*' => 0.2 ), |
| 150 | + array( 'text/html' => 1.0 ) ) ); |
| 151 | + $this->assertEquals( |
| 152 | + 'application/xhtml+xml', |
| 153 | + wfNegotiateType( |
| 154 | + array( 'application/xhtml+xml' => 1.0, |
| 155 | + 'text/html' => 0.7, |
| 156 | + 'text/plain' => 0.5, |
| 157 | + 'text/*' => 0.2 ), |
| 158 | + array( 'application/xhtml+xml' => 1.0, |
| 159 | + 'text/html' => 0.5 ) ) ); |
| 160 | + $this->assertEquals( |
| 161 | + 'text/html', |
| 162 | + wfNegotiateType( |
| 163 | + array( 'text/html' => 1.0, |
| 164 | + 'text/plain' => 0.5, |
| 165 | + 'text/*' => 0.5, |
| 166 | + 'application/xhtml+xml' => 0.2 ), |
| 167 | + array( 'application/xhtml+xml' => 1.0, |
| 168 | + 'text/html' => 0.5 ) ) ); |
| 169 | + $this->assertEquals( |
| 170 | + 'text/html', |
| 171 | + wfNegotiateType( |
| 172 | + array( 'text/*' => 1.0, |
| 173 | + 'image/*' => 0.7, |
| 174 | + '*/*' => 0.3 ), |
| 175 | + array( 'application/xhtml+xml' => 1.0, |
| 176 | + 'text/html' => 0.5 ) ) ); |
| 177 | + $this->assertNull( |
| 178 | + wfNegotiateType( |
| 179 | + array( 'text/*' => 1.0 ), |
| 180 | + array( 'application/xhtml+xml' => 1.0 ) ) ); |
| 181 | + } |
| 182 | + |
| 183 | + function testTimestamp() { |
| 184 | + $t = gmmktime( 12, 34, 56, 1, 15, 2001 ); |
| 185 | + $this->assertEquals( |
| 186 | + '20010115123456', |
| 187 | + wfTimestamp( TS_MW, $t ), |
| 188 | + 'TS_UNIX to TS_MW' ); |
| 189 | + $this->assertEquals( |
| 190 | + '19690115123456', |
| 191 | + wfTimestamp( TS_MW, -30281104 ), |
| 192 | + 'Negative TS_UNIX to TS_MW' ); |
| 193 | + $this->assertEquals( |
| 194 | + 979562096, |
| 195 | + wfTimestamp( TS_UNIX, $t ), |
| 196 | + 'TS_UNIX to TS_UNIX' ); |
| 197 | + $this->assertEquals( |
| 198 | + '2001-01-15 12:34:56', |
| 199 | + wfTimestamp( TS_DB, $t ), |
| 200 | + 'TS_UNIX to TS_DB' ); |
| 201 | + $this->assertEquals( |
| 202 | + '20010115T123456Z', |
| 203 | + wfTimestamp( TS_ISO_8601_BASIC, $t ), |
| 204 | + 'TS_ISO_8601_BASIC to TS_DB' ); |
| 205 | + |
| 206 | + $this->assertEquals( |
| 207 | + '20010115123456', |
| 208 | + wfTimestamp( TS_MW, '20010115123456' ), |
| 209 | + 'TS_MW to TS_MW' ); |
| 210 | + $this->assertEquals( |
| 211 | + 979562096, |
| 212 | + wfTimestamp( TS_UNIX, '20010115123456' ), |
| 213 | + 'TS_MW to TS_UNIX' ); |
| 214 | + $this->assertEquals( |
| 215 | + '2001-01-15 12:34:56', |
| 216 | + wfTimestamp( TS_DB, '20010115123456' ), |
| 217 | + 'TS_MW to TS_DB' ); |
| 218 | + $this->assertEquals( |
| 219 | + '20010115T123456Z', |
| 220 | + wfTimestamp( TS_ISO_8601_BASIC, '20010115123456' ), |
| 221 | + 'TS_MW to TS_ISO_8601_BASIC' ); |
| 222 | + |
| 223 | + $this->assertEquals( |
| 224 | + '20010115123456', |
| 225 | + wfTimestamp( TS_MW, '2001-01-15 12:34:56' ), |
| 226 | + 'TS_DB to TS_MW' ); |
| 227 | + $this->assertEquals( |
| 228 | + 979562096, |
| 229 | + wfTimestamp( TS_UNIX, '2001-01-15 12:34:56' ), |
| 230 | + 'TS_DB to TS_UNIX' ); |
| 231 | + $this->assertEquals( |
| 232 | + '2001-01-15 12:34:56', |
| 233 | + wfTimestamp( TS_DB, '2001-01-15 12:34:56' ), |
| 234 | + 'TS_DB to TS_DB' ); |
| 235 | + $this->assertEquals( |
| 236 | + '20010115T123456Z', |
| 237 | + wfTimestamp( TS_ISO_8601_BASIC, '2001-01-15 12:34:56' ), |
| 238 | + 'TS_DB to TS_ISO_8601_BASIC' ); |
| 239 | + |
| 240 | + # rfc2822 section 3.3 |
| 241 | + |
| 242 | + $this->assertEquals( |
| 243 | + 'Mon, 15 Jan 2001 12:34:56 GMT', |
| 244 | + wfTimestamp( TS_RFC2822, '20010115123456' ), |
| 245 | + 'TS_MW to TS_RFC2822' ); |
| 246 | + |
| 247 | + $this->assertEquals( |
| 248 | + '20010115123456', |
| 249 | + wfTimestamp( TS_MW, 'Mon, 15 Jan 2001 12:34:56 GMT' ), |
| 250 | + 'TS_RFC2822 to TS_MW' ); |
| 251 | + |
| 252 | + $this->assertEquals( |
| 253 | + '20010115123456', |
| 254 | + wfTimestamp( TS_MW, ' Mon, 15 Jan 2001 12:34:56 GMT' ), |
| 255 | + 'TS_RFC2822 with leading space to TS_MW' ); |
| 256 | + |
| 257 | + $this->assertEquals( |
| 258 | + '20010115123456', |
| 259 | + wfTimestamp( TS_MW, '15 Jan 2001 12:34:56 GMT' ), |
| 260 | + 'TS_RFC2822 without optional day-of-week to TS_MW' ); |
| 261 | + |
| 262 | + # FWS = ([*WSP CRLF] 1*WSP) / obs-FWS ; Folding white space |
| 263 | + # obs-FWS = 1*WSP *(CRLF 1*WSP) ; Section 4.2 |
| 264 | + $this->assertEquals( |
| 265 | + '20010115123456', |
| 266 | + wfTimestamp( TS_MW, 'Mon, 15 Jan 2001 12:34:56 GMT' ), |
| 267 | + 'TS_RFC2822 to TS_MW' ); |
| 268 | + |
| 269 | + # WSP = SP / HTAB ; rfc2234 |
| 270 | + $this->assertEquals( |
| 271 | + '20010115123456', |
| 272 | + wfTimestamp( TS_MW, "Mon, 15 Jan\x092001 12:34:56 GMT" ), |
| 273 | + 'TS_RFC2822 with HTAB to TS_MW' ); |
| 274 | + |
| 275 | + $this->assertEquals( |
| 276 | + '20010115123456', |
| 277 | + wfTimestamp( TS_MW, "Mon, 15 Jan\x09 \x09 2001 12:34:56 GMT" ), |
| 278 | + 'TS_RFC2822 with HTAB and SP to TS_MW' ); |
| 279 | + |
| 280 | + $this->assertEquals( |
| 281 | + '19941106084937', |
| 282 | + wfTimestamp( TS_MW, "Sun, 6 Nov 94 08:49:37 GMT" ), |
| 283 | + 'TS_RFC2822 with obsolete year to TS_MW' ); |
| 284 | + } |
| 285 | + |
| 286 | + /** |
| 287 | + * This test checks wfTimestamp() with values outside. |
| 288 | + * It needs PHP 64 bits or PHP > 5.1. |
| 289 | + * See r74778 and bug 25451 |
| 290 | + */ |
| 291 | + function testOldTimestamps() { |
| 292 | + $this->assertEquals( 'Fri, 13 Dec 1901 20:45:54 GMT', |
| 293 | + wfTimestamp( TS_RFC2822, '19011213204554' ), |
| 294 | + 'Earliest time according to php documentation' ); |
| 295 | + |
| 296 | + $this->assertEquals( 'Tue, 19 Jan 2038 03:14:07 GMT', |
| 297 | + wfTimestamp( TS_RFC2822, '20380119031407' ), |
| 298 | + 'Latest 32 bit time' ); |
| 299 | + |
| 300 | + $this->assertEquals( '-2147483648', |
| 301 | + wfTimestamp( TS_UNIX, '19011213204552' ), |
| 302 | + 'Earliest 32 bit unix time' ); |
| 303 | + |
| 304 | + $this->assertEquals( '2147483647', |
| 305 | + wfTimestamp( TS_UNIX, '20380119031407' ), |
| 306 | + 'Latest 32 bit unix time' ); |
| 307 | + |
| 308 | + $this->assertEquals( 'Fri, 13 Dec 1901 20:45:52 GMT', |
| 309 | + wfTimestamp( TS_RFC2822, '19011213204552' ), |
| 310 | + 'Earliest 32 bit time' ); |
| 311 | + |
| 312 | + $this->assertEquals( 'Fri, 13 Dec 1901 20:45:51 GMT', |
| 313 | + wfTimestamp( TS_RFC2822, '19011213204551' ), |
| 314 | + 'Earliest 32 bit time - 1' ); |
| 315 | + |
| 316 | + $this->assertEquals( 'Tue, 19 Jan 2038 03:14:08 GMT', |
| 317 | + wfTimestamp( TS_RFC2822, '20380119031408' ), |
| 318 | + 'Latest 32 bit time + 1' ); |
| 319 | + |
| 320 | + $this->assertEquals( '19011212000000', |
| 321 | + wfTimestamp(TS_MW, '19011212000000'), |
| 322 | + 'Convert to itself r74778#c10645' ); |
| 323 | + |
| 324 | + $this->assertEquals( '-2147483649', |
| 325 | + wfTimestamp( TS_UNIX, '19011213204551' ), |
| 326 | + 'Earliest 32 bit unix time - 1' ); |
| 327 | + |
| 328 | + $this->assertEquals( '2147483648', |
| 329 | + wfTimestamp( TS_UNIX, '20380119031408' ), |
| 330 | + 'Latest 32 bit unix time + 1' ); |
| 331 | + |
| 332 | + $this->assertEquals( '19011213204551', |
| 333 | + wfTimestamp( TS_MW, '-2147483649' ), |
| 334 | + '1901 negative unix time to MediaWiki' ); |
| 335 | + |
| 336 | + $this->assertEquals( '18010115123456', |
| 337 | + wfTimestamp( TS_MW, '-5331871504' ), |
| 338 | + '1801 negative unix time to MediaWiki' ); |
| 339 | + |
| 340 | + $this->assertEquals( 'Tue, 09 Aug 0117 12:34:56 GMT', |
| 341 | + wfTimestamp( TS_RFC2822, '0117-08-09 12:34:56'), |
| 342 | + 'Death of Roman Emperor [[Trajan]]'); |
| 343 | + |
| 344 | + /* @todo FIXME: 00 to 101 years are taken as being in [1970-2069] */ |
| 345 | + |
| 346 | + $this->assertEquals( 'Sun, 01 Jan 0101 00:00:00 GMT', |
| 347 | + wfTimestamp( TS_RFC2822, '-58979923200'), |
| 348 | + '1/1/101'); |
| 349 | + |
| 350 | + $this->assertEquals( 'Mon, 01 Jan 0001 00:00:00 GMT', |
| 351 | + wfTimestamp( TS_RFC2822, '-62135596800'), |
| 352 | + 'Year 1'); |
| 353 | + |
| 354 | + /* It is not clear if we should generate a year 0 or not |
| 355 | + * We are completely off RFC2822 requirement of year being |
| 356 | + * 1900 or later. |
| 357 | + */ |
| 358 | + $this->assertEquals( 'Wed, 18 Oct 0000 00:00:00 GMT', |
| 359 | + wfTimestamp( TS_RFC2822, '-62142076800'), |
| 360 | + 'ISO 8601:2004 [[year 0]], also called [[1 BC]]'); |
| 361 | + } |
| 362 | + |
| 363 | + function testHttpDate() { |
| 364 | + # The Resource Loader uses wfTimestamp() to convert timestamps |
| 365 | + # from If-Modified-Since header. |
| 366 | + # Thus it must be able to parse all rfc2616 date formats |
| 367 | + # http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1 |
| 368 | + |
| 369 | + $this->assertEquals( |
| 370 | + '19941106084937', |
| 371 | + wfTimestamp( TS_MW, 'Sun, 06 Nov 1994 08:49:37 GMT' ), |
| 372 | + 'RFC 822 date' ); |
| 373 | + |
| 374 | + $this->assertEquals( |
| 375 | + '19941106084937', |
| 376 | + wfTimestamp( TS_MW, 'Sunday, 06-Nov-94 08:49:37 GMT' ), |
| 377 | + 'RFC 850 date' ); |
| 378 | + |
| 379 | + $this->assertEquals( |
| 380 | + '19941106084937', |
| 381 | + wfTimestamp( TS_MW, 'Sun Nov 6 08:49:37 1994' ), |
| 382 | + "ANSI C's asctime() format" ); |
| 383 | + |
| 384 | + // See http://www.squid-cache.org/mail-archive/squid-users/200307/0122.html and r77171 |
| 385 | + $this->assertEquals( |
| 386 | + '20101122141242', |
| 387 | + wfTimestamp( TS_MW, 'Mon, 22 Nov 2010 14:12:42 GMT; length=52626' ), |
| 388 | + "Netscape extension to HTTP/1.0" ); |
| 389 | + |
| 390 | + } |
| 391 | + |
| 392 | + function testTimestampParameter() { |
| 393 | + // There are a number of assumptions in our codebase where wfTimestamp() should give |
| 394 | + // the current date but it is not given a 0 there. See r71751 CR |
| 395 | + |
| 396 | + $now = wfTimestamp( TS_UNIX ); |
| 397 | + // We check that wfTimestamp doesn't return false (error) and use a LessThan assert |
| 398 | + // for the cases where the test is run in a second boundary. |
| 399 | + |
| 400 | + $zero = wfTimestamp( TS_UNIX, 0 ); |
| 401 | + $this->assertNotEquals( false, $zero ); |
| 402 | + $this->assertLessThan( 5, $zero - $now ); |
| 403 | + |
| 404 | + $empty = wfTimestamp( TS_UNIX, '' ); |
| 405 | + $this->assertNotEquals( false, $empty ); |
| 406 | + $this->assertLessThan( 5, $empty - $now ); |
| 407 | + |
| 408 | + $null = wfTimestamp( TS_UNIX, null ); |
| 409 | + $this->assertNotEquals( false, $null ); |
| 410 | + $this->assertLessThan( 5, $null - $now ); |
| 411 | + } |
| 412 | + |
| 413 | + function testBasename() { |
| 414 | + $sets = array( |
| 415 | + '' => '', |
| 416 | + '/' => '', |
| 417 | + '\\' => '', |
| 418 | + '//' => '', |
| 419 | + '\\\\' => '', |
| 420 | + 'a' => 'a', |
| 421 | + 'aaaa' => 'aaaa', |
| 422 | + '/a' => 'a', |
| 423 | + '\\a' => 'a', |
| 424 | + '/aaaa' => 'aaaa', |
| 425 | + '\\aaaa' => 'aaaa', |
| 426 | + '/aaaa/' => 'aaaa', |
| 427 | + '\\aaaa\\' => 'aaaa', |
| 428 | + '\\aaaa\\' => 'aaaa', |
| 429 | + '/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', |
| 430 | + 'C:\\Progra~1\\Wikime~1\\Wikipe~1\\VIEWER.EXE' => 'VIEWER.EXE', |
| 431 | + 'Östergötland_coat_of_arms.png' => 'Östergötland_coat_of_arms.png', |
| 432 | + ); |
| 433 | + foreach ( $sets as $from => $to ) { |
| 434 | + $this->assertEquals( $to, wfBaseName( $from ), |
| 435 | + "wfBaseName('$from') => '$to'" ); |
| 436 | + } |
| 437 | + } |
| 438 | + |
| 439 | + |
| 440 | + function testFallbackMbstringFunctions() { |
| 441 | + |
| 442 | + if( !extension_loaded( 'mbstring' ) ) { |
| 443 | + $this->markTestSkipped( "The mb_string functions must be installed to test the fallback functions" ); |
| 444 | + } |
| 445 | + |
| 446 | + $sampleUTF = "Östergötland_coat_of_arms.png"; |
| 447 | + |
| 448 | + |
| 449 | + //mb_substr |
| 450 | + $substr_params = array( |
| 451 | + array( 0, 0 ), |
| 452 | + array( 5, -4 ), |
| 453 | + array( 33 ), |
| 454 | + array( 100, -5 ), |
| 455 | + array( -8, 10 ), |
| 456 | + array( 1, 1 ), |
| 457 | + array( 2, -1 ) |
| 458 | + ); |
| 459 | + |
| 460 | + foreach( $substr_params as $param_set ) { |
| 461 | + $old_param_set = $param_set; |
| 462 | + array_unshift( $param_set, $sampleUTF ); |
| 463 | + |
| 464 | + $this->assertEquals( |
| 465 | + MWFunction::callArray( 'mb_substr', $param_set ), |
| 466 | + MWFunction::callArray( 'Fallback::mb_substr', $param_set ), |
| 467 | + 'Fallback mb_substr with params ' . implode( ', ', $old_param_set ) |
| 468 | + ); |
| 469 | + } |
| 470 | + |
| 471 | + |
| 472 | + //mb_strlen |
| 473 | + $this->assertEquals( |
| 474 | + mb_strlen( $sampleUTF ), |
| 475 | + Fallback::mb_strlen( $sampleUTF ), |
| 476 | + 'Fallback mb_strlen' |
| 477 | + ); |
| 478 | + |
| 479 | + |
| 480 | + //mb_str(r?)pos |
| 481 | + $strpos_params = array( |
| 482 | + //array( 'ter' ), |
| 483 | + //array( 'Ö' ), |
| 484 | + //array( 'Ö', 3 ), |
| 485 | + //array( 'oat_', 100 ), |
| 486 | + //array( 'c', -10 ), |
| 487 | + //Broken for now |
| 488 | + ); |
| 489 | + |
| 490 | + foreach( $strpos_params as $param_set ) { |
| 491 | + $old_param_set = $param_set; |
| 492 | + array_unshift( $param_set, $sampleUTF ); |
| 493 | + |
| 494 | + $this->assertEquals( |
| 495 | + MWFunction::callArray( 'mb_strpos', $param_set ), |
| 496 | + MWFunction::callArray( 'Fallback::mb_strpos', $param_set ), |
| 497 | + 'Fallback mb_strpos with params ' . implode( ', ', $old_param_set ) |
| 498 | + ); |
| 499 | + |
| 500 | + $this->assertEquals( |
| 501 | + MWFunction::callArray( 'mb_strrpos', $param_set ), |
| 502 | + MWFunction::callArray( 'Fallback::mb_strrpos', $param_set ), |
| 503 | + 'Fallback mb_strrpos with params ' . implode( ', ', $old_param_set ) |
| 504 | + ); |
| 505 | + } |
| 506 | + |
| 507 | + } |
| 508 | + |
| 509 | + |
| 510 | + function testDebugFunctionTest() { |
| 511 | + |
| 512 | + global $wgDebugLogFile, $wgOut, $wgShowDebug, $wgDebugTimestamps; |
| 513 | + |
| 514 | + $old_log_file = $wgDebugLogFile; |
| 515 | + $wgDebugLogFile = tempnam( wfTempDir(), 'mw-' ); |
| 516 | + # @todo FIXME: This setting should be tested |
| 517 | + $wgDebugTimestamps = false; |
| 518 | + |
| 519 | + |
| 520 | + |
| 521 | + wfDebug( "This is a normal string" ); |
| 522 | + $this->assertEquals( "This is a normal string", file_get_contents( $wgDebugLogFile ) ); |
| 523 | + unlink( $wgDebugLogFile ); |
| 524 | + |
| 525 | + |
| 526 | + wfDebug( "This is nöt an ASCII string" ); |
| 527 | + $this->assertEquals( "This is nöt an ASCII string", file_get_contents( $wgDebugLogFile ) ); |
| 528 | + unlink( $wgDebugLogFile ); |
| 529 | + |
| 530 | + |
| 531 | + wfDebug( "\00305This has böth UTF and control chars\003" ); |
| 532 | + $this->assertEquals( " 05This has böth UTF and control chars ", file_get_contents( $wgDebugLogFile ) ); |
| 533 | + unlink( $wgDebugLogFile ); |
| 534 | + |
| 535 | + |
| 536 | + |
| 537 | + $old_wgOut = $wgOut; |
| 538 | + $old_wgShowDebug = $wgShowDebug; |
| 539 | + |
| 540 | + $wgOut = new MockOutputPage; |
| 541 | + |
| 542 | + $wgShowDebug = true; |
| 543 | + |
| 544 | + $message = "\00305This has böth UTF and control chars\003"; |
| 545 | + |
| 546 | + wfDebug( $message ); |
| 547 | + |
| 548 | + if( $wgOut->message == "JAJA is a stupid error message. Anyway, here's your message: $message" ) { |
| 549 | + $this->assertTrue( true, 'MockOutputPage called, set the proper message.' ); |
| 550 | + } |
| 551 | + else { |
| 552 | + $this->assertTrue( false, 'MockOutputPage was not called.' ); |
| 553 | + } |
| 554 | + |
| 555 | + $wgOut = $old_wgOut; |
| 556 | + $wgShowDebug = $old_wgShowDebug; |
| 557 | + unlink( $wgDebugLogFile ); |
| 558 | + |
| 559 | + |
| 560 | + |
| 561 | + wfDebugMem(); |
| 562 | + $this->assertGreaterThan( 5000, preg_replace( '/\D/', '', file_get_contents( $wgDebugLogFile ) ) ); |
| 563 | + unlink( $wgDebugLogFile ); |
| 564 | + |
| 565 | + wfDebugMem(true); |
| 566 | + $this->assertGreaterThan( 5000000, preg_replace( '/\D/', '', file_get_contents( $wgDebugLogFile ) ) ); |
| 567 | + unlink( $wgDebugLogFile ); |
| 568 | + |
| 569 | + |
| 570 | + |
| 571 | + $wgDebugLogFile = $old_log_file; |
| 572 | + |
| 573 | + } |
| 574 | + |
| 575 | + function testClientAcceptsGzipTest() { |
| 576 | + |
| 577 | + $settings = array( |
| 578 | + 'gzip' => true, |
| 579 | + 'bzip' => false, |
| 580 | + '*' => false, |
| 581 | + 'compress, gzip' => true, |
| 582 | + 'gzip;q=1.0' => true, |
| 583 | + 'foozip' => false, |
| 584 | + 'foo*zip' => false, |
| 585 | + 'gzip;q=abcde' => true, //is this REALLY valid? |
| 586 | + 'gzip;q=12345678.9' => true, |
| 587 | + ' gzip' => true, |
| 588 | + ); |
| 589 | + |
| 590 | + if( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) $old_server_setting = $_SERVER['HTTP_ACCEPT_ENCODING']; |
| 591 | + |
| 592 | + foreach ( $settings as $encoding => $expect ) { |
| 593 | + $_SERVER['HTTP_ACCEPT_ENCODING'] = $encoding; |
| 594 | + |
| 595 | + $this->assertEquals( $expect, wfClientAcceptsGzip( true ), |
| 596 | + "'$encoding' => " . wfBoolToStr( $expect ) ); |
| 597 | + } |
| 598 | + |
| 599 | + if( isset( $old_server_setting ) ) $_SERVER['HTTP_ACCEPT_ENCODING'] = $old_server_setting; |
| 600 | + |
| 601 | + } |
| 602 | + |
| 603 | + |
| 604 | + |
| 605 | + function testSwapVarsTest() { |
| 606 | + |
| 607 | + |
| 608 | + $var1 = 1; |
| 609 | + $var2 = 2; |
| 610 | + |
| 611 | + $this->assertEquals( $var1, 1, 'var1 is set originally' ); |
| 612 | + $this->assertEquals( $var2, 2, 'var1 is set originally' ); |
| 613 | + |
| 614 | + swap( $var1, $var2 ); |
| 615 | + |
| 616 | + $this->assertEquals( $var1, 2, 'var1 is swapped' ); |
| 617 | + $this->assertEquals( $var2, 1, 'var2 is swapped' ); |
| 618 | + |
| 619 | + } |
| 620 | + |
| 621 | + |
| 622 | + function testWfPercentTest() { |
| 623 | + |
| 624 | + $pcts = array( |
| 625 | + array( 6/7, '0.86%', 2, false ), |
| 626 | + array( 3/3, '1%' ), |
| 627 | + array( 22/7, '3.14286%', 5 ), |
| 628 | + array( 3/6, '0.5%' ), |
| 629 | + array( 1/3, '0%', 0 ), |
| 630 | + array( 10/3, '0%', -1 ), |
| 631 | + array( 3/4/5, '0.1%', 1 ), |
| 632 | + array( 6/7*8, '6.8571428571%', 10 ), |
| 633 | + ); |
| 634 | + |
| 635 | + foreach( $pcts as $pct ) { |
| 636 | + if( !isset( $pct[2] ) ) $pct[2] = 2; |
| 637 | + if( !isset( $pct[3] ) ) $pct[3] = true; |
| 638 | + |
| 639 | + $this->assertEquals( wfPercent( $pct[0], $pct[2], $pct[3] ), $pct[1], $pct[1] ); |
| 640 | + } |
| 641 | + |
| 642 | + } |
| 643 | + |
| 644 | + |
| 645 | + function testInStringTest() { |
| 646 | + |
| 647 | + $this->assertTrue( in_string( 'foo', 'foobar' ), 'foo is in foobar' ); |
| 648 | + $this->assertFalse( in_string( 'Bar', 'foobar' ), 'Case-sensitive by default' ); |
| 649 | + $this->assertTrue( in_string( 'Foo', 'foobar', true ), 'Case-insensitive when asked' ); |
| 650 | + |
| 651 | + } |
| 652 | + |
| 653 | + /** |
| 654 | + * test @see wfShorthandToInteger() |
| 655 | + * @dataProvider provideShorthand |
| 656 | + */ |
| 657 | + public function testWfShorthandToInteger( $shorthand, $expected ) { |
| 658 | + $this->assertEquals( $expected, |
| 659 | + wfShorthandToInteger( $shorthand ) |
| 660 | + ); |
| 661 | + } |
| 662 | + |
| 663 | + /** array( shorthand, expected integer ) */ |
| 664 | + public function provideShorthand() { |
| 665 | + return array( |
| 666 | + # Null, empty ... |
| 667 | + array( '', -1), |
| 668 | + array( ' ', -1), |
| 669 | + array( null, -1), |
| 670 | + |
| 671 | + # Failures returns 0 :( |
| 672 | + array( 'ABCDEFG', 0 ), |
| 673 | + array( 'Ak', 0 ), |
| 674 | + |
| 675 | + # Int, strings with spaces |
| 676 | + array( 1, 1 ), |
| 677 | + array( ' 1 ', 1 ), |
| 678 | + array( 1023, 1023 ), |
| 679 | + array( ' 1023 ', 1023 ), |
| 680 | + |
| 681 | + # kilo, Mega, Giga |
| 682 | + array( '1k', 1024 ), |
| 683 | + array( '1K', 1024 ), |
| 684 | + array( '1m', 1024 * 1024 ), |
| 685 | + array( '1M', 1024 * 1024 ), |
| 686 | + array( '1g', 1024 * 1024 * 1024 ), |
| 687 | + array( '1G', 1024 * 1024 * 1024 ), |
| 688 | + |
| 689 | + # Negatives |
| 690 | + array( -1, -1 ), |
| 691 | + array( -500, -500 ), |
| 692 | + array( '-500', -500 ), |
| 693 | + array( '-1k', -1024 ), |
| 694 | + |
| 695 | + # Zeroes |
| 696 | + array( '0', 0 ), |
| 697 | + array( '0k', 0 ), |
| 698 | + array( '0M', 0 ), |
| 699 | + array( '0G', 0 ), |
| 700 | + array( '-0', 0 ), |
| 701 | + array( '-0k', 0 ), |
| 702 | + array( '-0M', 0 ), |
| 703 | + array( '-0G', 0 ), |
| 704 | + ); |
| 705 | + } |
| 706 | + |
| 707 | + |
| 708 | + /** |
| 709 | + * test @see wfBCP47(). |
| 710 | + * Please note the BCP explicitly state that language codes are case |
| 711 | + * insensitive, there are some exceptions to the rule :) |
| 712 | + * This test is used to verify our formatting against all lower and |
| 713 | + * all upper cases language code. |
| 714 | + * |
| 715 | + * @see http://tools.ietf.org/html/bcp47 |
| 716 | + * @dataProvider provideLanguageCodes() |
| 717 | + */ |
| 718 | + function testBCP47( $code, $expected ) { |
| 719 | + $code = strtolower( $code ); |
| 720 | + $this->assertEquals( $expected, wfBCP47($code), |
| 721 | + "Applying BCP47 standard to lower case '$code'" |
| 722 | + ); |
| 723 | + |
| 724 | + $code = strtoupper( $code ); |
| 725 | + $this->assertEquals( $expected, wfBCP47($code), |
| 726 | + "Applying BCP47 standard to upper case '$code'" |
| 727 | + ); |
| 728 | + } |
| 729 | + |
| 730 | + /** |
| 731 | + * Array format is ($code, $expected) |
| 732 | + */ |
| 733 | + function provideLanguageCodes() { |
| 734 | + return array( |
| 735 | + // Extracted from BCP47 (list not exhaustive) |
| 736 | + # 2.1.1 |
| 737 | + array( 'en-ca-x-ca' , 'en-CA-x-ca' ), |
| 738 | + array( 'sgn-be-fr' , 'sgn-BE-FR' ), |
| 739 | + array( 'az-latn-x-latn', 'az-Latn-x-latn' ), |
| 740 | + # 2.2 |
| 741 | + array( 'sr-Latn-RS', 'sr-Latn-RS' ), |
| 742 | + array( 'az-arab-ir', 'az-Arab-IR' ), |
| 743 | + |
| 744 | + # 2.2.5 |
| 745 | + array( 'sl-nedis' , 'sl-nedis' ), |
| 746 | + array( 'de-ch-1996', 'de-CH-1996' ), |
| 747 | + |
| 748 | + # 2.2.6 |
| 749 | + array( |
| 750 | + 'en-latn-gb-boont-r-extended-sequence-x-private', |
| 751 | + 'en-Latn-GB-boont-r-extended-sequence-x-private' |
| 752 | + ), |
| 753 | + |
| 754 | + // Examples from BCP47 Appendix A |
| 755 | + # Simple language subtag: |
| 756 | + array( 'DE', 'de' ), |
| 757 | + array( 'fR', 'fr' ), |
| 758 | + array( 'ja', 'ja' ), |
| 759 | + |
| 760 | + # Language subtag plus script subtag: |
| 761 | + array( 'zh-hans', 'zh-Hans'), |
| 762 | + array( 'sr-cyrl', 'sr-Cyrl'), |
| 763 | + array( 'sr-latn', 'sr-Latn'), |
| 764 | + |
| 765 | + # Extended language subtags and their primary language subtag |
| 766 | + # counterparts: |
| 767 | + array( 'zh-cmn-hans-cn', 'zh-cmn-Hans-CN' ), |
| 768 | + array( 'cmn-hans-cn' , 'cmn-Hans-CN' ), |
| 769 | + array( 'zh-yue-hk' , 'zh-yue-HK' ), |
| 770 | + array( 'yue-hk' , 'yue-HK' ), |
| 771 | + |
| 772 | + # Language-Script-Region: |
| 773 | + array( 'zh-hans-cn', 'zh-Hans-CN' ), |
| 774 | + array( 'sr-latn-RS', 'sr-Latn-RS' ), |
| 775 | + |
| 776 | + # Language-Variant: |
| 777 | + array( 'sl-rozaj' , 'sl-rozaj' ), |
| 778 | + array( 'sl-rozaj-biske', 'sl-rozaj-biske' ), |
| 779 | + array( 'sl-nedis' , 'sl-nedis' ), |
| 780 | + |
| 781 | + # Language-Region-Variant: |
| 782 | + array( 'de-ch-1901' , 'de-CH-1901' ), |
| 783 | + array( 'sl-it-nedis' , 'sl-IT-nedis' ), |
| 784 | + |
| 785 | + # Language-Script-Region-Variant: |
| 786 | + array( 'hy-latn-it-arevela', 'hy-Latn-IT-arevela' ), |
| 787 | + |
| 788 | + # Language-Region: |
| 789 | + array( 'de-de' , 'de-DE' ), |
| 790 | + array( 'en-us' , 'en-US' ), |
| 791 | + array( 'es-419', 'es-419'), |
| 792 | + |
| 793 | + # Private use subtags: |
| 794 | + array( 'de-ch-x-phonebk' , 'de-CH-x-phonebk' ), |
| 795 | + array( 'az-arab-x-aze-derbend', 'az-Arab-x-aze-derbend' ), |
| 796 | + /** |
| 797 | + * Previous test does not reflect the BCP which states: |
| 798 | + * az-Arab-x-AZE-derbend |
| 799 | + * AZE being private, it should be lower case, hence the test above |
| 800 | + * should probably be: |
| 801 | + #array( 'az-arab-x-aze-derbend', 'az-Arab-x-AZE-derbend' ), |
| 802 | + */ |
| 803 | + |
| 804 | + # Private use registry values: |
| 805 | + array( 'x-whatever', 'x-whatever' ), |
| 806 | + array( 'qaa-qaaa-qm-x-southern', 'qaa-Qaaa-QM-x-southern' ), |
| 807 | + array( 'de-qaaa' , 'de-Qaaa' ), |
| 808 | + array( 'sr-latn-qm', 'sr-Latn-QM' ), |
| 809 | + array( 'sr-qaaa-rs', 'sr-Qaaa-RS' ), |
| 810 | + |
| 811 | + # Tags that use extensions |
| 812 | + array( 'en-us-u-islamcal', 'en-US-u-islamcal' ), |
| 813 | + array( 'zh-cn-a-myext-x-private', 'zh-CN-a-myext-x-private' ), |
| 814 | + array( 'en-a-myext-b-another', 'en-a-myext-b-another' ), |
| 815 | + |
| 816 | + # Invalid: |
| 817 | + // de-419-DE |
| 818 | + // a-DE |
| 819 | + // ar-a-aaa-b-bbb-a-ccc |
| 820 | + |
| 821 | + /* |
| 822 | + // ISO 15924 : |
| 823 | + array( 'sr-Cyrl', 'sr-Cyrl' ), |
| 824 | + # @todo FIXME: Fix our function? |
| 825 | + array( 'SR-lATN', 'sr-Latn' ), |
| 826 | + array( 'fr-latn', 'fr-Latn' ), |
| 827 | + // Use lowercase for single segment |
| 828 | + // ISO 3166-1-alpha-2 code |
| 829 | + array( 'US', 'us' ), # USA |
| 830 | + array( 'uS', 'us' ), # USA |
| 831 | + array( 'Fr', 'fr' ), # France |
| 832 | + array( 'va', 'va' ), # Holy See (Vatican City State) |
| 833 | + */); |
| 834 | + } |
| 835 | + |
| 836 | + /** |
| 837 | + * @dataProvider provideMakeUrlIndex() |
| 838 | + */ |
| 839 | + function testMakeUrlIndex( $url, $expected ) { |
| 840 | + $index = wfMakeUrlIndex( $url ); |
| 841 | + $this->assertEquals( $expected, $index, "wfMakeUrlIndex(\"$url\")" ); |
| 842 | + } |
| 843 | + |
| 844 | + function provideMakeUrlIndex() { |
| 845 | + return array( |
| 846 | + array( |
| 847 | + // just a regular :) |
| 848 | + 'https://bugzilla.wikimedia.org/show_bug.cgi?id=28627', |
| 849 | + 'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627' |
| 850 | + ), |
| 851 | + array( |
| 852 | + // mailtos are handled special |
| 853 | + // is this really right though? that final . probably belongs earlier? |
| 854 | + 'mailto:wiki@wikimedia.org', |
| 855 | + 'mailto:org.wikimedia@wiki.', |
| 856 | + ), |
| 857 | + |
| 858 | + // file URL cases per bug 28627... |
| 859 | + array( |
| 860 | + // three slashes: local filesystem path Unix-style |
| 861 | + 'file:///whatever/you/like.txt', |
| 862 | + 'file://./whatever/you/like.txt' |
| 863 | + ), |
| 864 | + array( |
| 865 | + // three slashes: local filesystem path Windows-style |
| 866 | + 'file:///c:/whatever/you/like.txt', |
| 867 | + 'file://./c:/whatever/you/like.txt' |
| 868 | + ), |
| 869 | + array( |
| 870 | + // two slashes: UNC filesystem path Windows-style |
| 871 | + 'file://intranet/whatever/you/like.txt', |
| 872 | + 'file://intranet./whatever/you/like.txt' |
| 873 | + ), |
| 874 | + // Multiple-slash cases that can sorta work on Mozilla |
| 875 | + // if you hack it just right are kinda pathological, |
| 876 | + // and unreliable cross-platform or on IE which means they're |
| 877 | + // unlikely to appear on intranets. |
| 878 | + // |
| 879 | + // Those will survive the algorithm but with results that |
| 880 | + // are less consistent. |
| 881 | + ); |
| 882 | + } |
| 883 | + |
| 884 | + public function testUnserialize() { |
| 885 | + $this->assertEquals( '', wfUnserialize( 's:0:"";') ); |
| 886 | + $this->assertEquals( false, wfUnserialize( '0' ), |
| 887 | + 'Invalid input to unserialize()' ); |
| 888 | + } |
| 889 | + |
| 890 | + /* TODO: many more! */ |
| 891 | +} |
| 892 | + |
| 893 | + |
| 894 | +class MockOutputPage { |
| 895 | + |
| 896 | + public $message; |
| 897 | + |
| 898 | + function debug( $message ) { |
| 899 | + $this->message = "JAJA is a stupid error message. Anyway, here's your message: $message"; |
| 900 | + } |
| 901 | +} |
| 902 | + |
Property changes on: trunk/phase3/tests/phpunit/includes/GlobalFunctions/GlobalTest.php |
___________________________________________________________________ |
Added: svn:keywords |
1 | 903 | + Author Date Id Revision |
Added: svn:eol-style |
2 | 904 | + native |
Index: trunk/phase3/tests/phpunit/includes/GlobalFunctions/README |
— | — | @@ -0,0 +1,2 @@ |
| 2 | +This directory hold tests for includes/GlobalFunctions.php file |
| 3 | +which is a pile of functions. |
Property changes on: trunk/phase3/tests/phpunit/includes/GlobalFunctions/README |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 4 | + native |