summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/GlobalFunctions/GlobalTest.php
blob: 6154df1d5e382a73a6d5db088a54ea78fd07edb6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
<?php

class GlobalTest extends MediaWikiTestCase {
	protected function setUp() {
		parent::setUp();

		$readOnlyFile = tempnam( wfTempDir(), "mwtest_readonly" );
		unlink( $readOnlyFile );

		$this->setMwGlobals( array(
			'wgReadOnlyFile' => $readOnlyFile,
			'wgUrlProtocols' => array(
				'http://',
				'https://',
				'mailto:',
				'//',
				'file://', # Non-default
			),
		) );
	}

	protected function tearDown() {
		global $wgReadOnlyFile;

		if ( file_exists( $wgReadOnlyFile ) ) {
			unlink( $wgReadOnlyFile );
		}

		parent::tearDown();
	}

	/**
	 * @dataProvider provideForWfArrayDiff2
	 * @covers ::wfArrayDiff2
	 */
	public function testWfArrayDiff2( $a, $b, $expected ) {
		$this->assertEquals(
			wfArrayDiff2( $a, $b ), $expected
		);
	}

	// @todo Provide more tests
	public static function provideForWfArrayDiff2() {
		// $a $b $expected
		return array(
			array(
				array( 'a', 'b' ),
				array( 'a', 'b' ),
				array(),
			),
			array(
				array( array( 'a' ), array( 'a', 'b', 'c' ) ),
				array( array( 'a' ), array( 'a', 'b' ) ),
				array( 1 => array( 'a', 'b', 'c' ) ),
			),
		);
	}

	/**
	 * @covers ::wfRandom
	 */
	public function testRandom() {
		# This could hypothetically fail, but it shouldn't ;)
		$this->assertFalse(
			wfRandom() == wfRandom() );
	}

	/**
	 * @covers ::wfUrlencode
	 */
	public function testUrlencode() {
		$this->assertEquals(
			"%E7%89%B9%E5%88%A5:Contributions/Foobar",
			wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
	}

	/**
	 * @covers ::wfExpandIRI
	 */
	public function testExpandIRI() {
		$this->assertEquals(
			"https://te.wikibooks.org/wiki/ఉబుంటు_వాడుకరి_మార్గదర్శని",
			wfExpandIRI( "https://te.wikibooks.org/wiki/%E0%B0%89%E0%B0%AC%E0%B1%81%E0%B0%82%E0%B0%9F%E0%B1%81_%E0%B0%B5%E0%B0%BE%E0%B0%A1%E0%B1%81%E0%B0%95%E0%B0%B0%E0%B0%BF_%E0%B0%AE%E0%B0%BE%E0%B0%B0%E0%B1%8D%E0%B0%97%E0%B0%A6%E0%B0%B0%E0%B1%8D%E0%B0%B6%E0%B0%A8%E0%B0%BF" ) );
	}

	/**
	 * @covers ::wfReadOnly
	 */
	public function testReadOnlyEmpty() {
		global $wgReadOnly;
		$wgReadOnly = null;

		$this->assertFalse( wfReadOnly() );
		$this->assertFalse( wfReadOnly() );
	}

	/**
	 * @covers ::wfReadOnly
	 */
	public function testReadOnlySet() {
		global $wgReadOnly, $wgReadOnlyFile;

		$f = fopen( $wgReadOnlyFile, "wt" );
		fwrite( $f, 'Message' );
		fclose( $f );
		$wgReadOnly = null; # Check on $wgReadOnlyFile

		$this->assertTrue( wfReadOnly() );
		$this->assertTrue( wfReadOnly() ); # Check cached

		unlink( $wgReadOnlyFile );
		$wgReadOnly = null; # Clean cache

		$this->assertFalse( wfReadOnly() );
		$this->assertFalse( wfReadOnly() );
	}

	public static function provideArrayToCGI() {
		return array(
			array( array(), '' ), // empty
			array( array( 'foo' => 'bar' ), 'foo=bar' ), // string test
			array( array( 'foo' => '' ), 'foo=' ), // empty string test
			array( array( 'foo' => 1 ), 'foo=1' ), // number test
			array( array( 'foo' => true ), 'foo=1' ), // true test
			array( array( 'foo' => false ), '' ), // false test
			array( array( 'foo' => null ), '' ), // null test
			array( array( 'foo' => 'A&B=5+6@!"\'' ), 'foo=A%26B%3D5%2B6%40%21%22%27' ), // urlencoding test
			array( array( 'foo' => 'bar', 'baz' => 'is', 'asdf' => 'qwerty' ), 'foo=bar&baz=is&asdf=qwerty' ), // multi-item test
			array( array( 'foo' => array( 'bar' => 'baz' ) ), 'foo%5Bbar%5D=baz' ),
			array( array( 'foo' => array( 'bar' => 'baz', 'qwerty' => 'asdf' ) ), 'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf' ),
			array( array( 'foo' => array( 'bar', 'baz' ) ), 'foo%5B0%5D=bar&foo%5B1%5D=baz' ),
			array( array( 'foo' => array( 'bar' => array( 'bar' => 'baz' ) ) ), 'foo%5Bbar%5D%5Bbar%5D=baz' ),
		);
	}

	/**
	 * @dataProvider provideArrayToCGI
	 * @covers ::wfArrayToCgi
	 */
	public function testArrayToCGI( $array, $result ) {
		$this->assertEquals( $result, wfArrayToCgi( $array ) );
	}


	/**
	 * @covers ::testWfArrayDiff2
	 */
	public function testArrayToCGI2() {
		$this->assertEquals(
			"baz=bar&foo=bar",
			wfArrayToCgi(
				array( 'baz' => 'bar' ),
				array( 'foo' => 'bar', 'baz' => 'overridden value' ) ) );
	}

	public static function provideCgiToArray() {
		return array(
			array( '', array() ), // empty
			array( 'foo=bar', array( 'foo' => 'bar' ) ), // string
			array( 'foo=', array( 'foo' => '' ) ), // empty string
			array( 'foo', array( 'foo' => '' ) ), // missing =
			array( 'foo=bar&qwerty=asdf', array( 'foo' => 'bar', 'qwerty' => 'asdf' ) ), // multiple value
			array( 'foo=A%26B%3D5%2B6%40%21%22%27', array( 'foo' => 'A&B=5+6@!"\'' ) ), // urldecoding test
			array( 'foo%5Bbar%5D=baz', array( 'foo' => array( 'bar' => 'baz' ) ) ),
			array( 'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf', array( 'foo' => array( 'bar' => 'baz', 'qwerty' => 'asdf' ) ) ),
			array( 'foo%5B0%5D=bar&foo%5B1%5D=baz', array( 'foo' => array( 0 => 'bar', 1 => 'baz' ) ) ),
			array( 'foo%5Bbar%5D%5Bbar%5D=baz', array( 'foo' => array( 'bar' => array( 'bar' => 'baz' ) ) ) ),
		);
	}

	/**
	 * @dataProvider provideCgiToArray
	 * @covers ::wfCgiToArray
	 */
	public function testCgiToArray( $cgi, $result ) {
		$this->assertEquals( $result, wfCgiToArray( $cgi ) );
	}

	public static function provideCgiRoundTrip() {
		return array(
			array( '' ),
			array( 'foo=bar' ),
			array( 'foo=' ),
			array( 'foo=bar&baz=biz' ),
			array( 'foo=A%26B%3D5%2B6%40%21%22%27' ),
			array( 'foo%5Bbar%5D=baz' ),
			array( 'foo%5B0%5D=bar&foo%5B1%5D=baz' ),
			array( 'foo%5Bbar%5D%5Bbar%5D=baz' ),
		);
	}

	/**
	 * @dataProvider provideCgiRoundTrip
	 * @covers ::wfArrayToCgi
	 */
	public function testCgiRoundTrip( $cgi ) {
		$this->assertEquals( $cgi, wfArrayToCgi( wfCgiToArray( $cgi ) ) );
	}

	/**
	 * @covers ::mimeTypeMatch
	 */
	public function testMimeTypeMatch() {
		$this->assertEquals(
			'text/html',
			mimeTypeMatch( 'text/html',
				array( 'application/xhtml+xml' => 1.0,
					'text/html' => 0.7,
					'text/plain' => 0.3 ) ) );
		$this->assertEquals(
			'text/*',
			mimeTypeMatch( 'text/html',
				array( 'image/*' => 1.0,
					'text/*' => 0.5 ) ) );
		$this->assertEquals(
			'*/*',
			mimeTypeMatch( 'text/html',
				array( '*/*' => 1.0 ) ) );
		$this->assertNull(
			mimeTypeMatch( 'text/html',
				array( 'image/png' => 1.0,
					'image/svg+xml' => 0.5 ) ) );
	}

	/**
	 * @covers ::wfNegotiateType
	 */
	public function testNegotiateType() {
		$this->assertEquals(
			'text/html',
			wfNegotiateType(
				array( 'application/xhtml+xml' => 1.0,
					'text/html' => 0.7,
					'text/plain' => 0.5,
					'text/*' => 0.2 ),
				array( 'text/html' => 1.0 ) ) );
		$this->assertEquals(
			'application/xhtml+xml',
			wfNegotiateType(
				array( 'application/xhtml+xml' => 1.0,
					'text/html' => 0.7,
					'text/plain' => 0.5,
					'text/*' => 0.2 ),
				array( 'application/xhtml+xml' => 1.0,
					'text/html' => 0.5 ) ) );
		$this->assertEquals(
			'text/html',
			wfNegotiateType(
				array( 'text/html' => 1.0,
					'text/plain' => 0.5,
					'text/*' => 0.5,
					'application/xhtml+xml' => 0.2 ),
				array( 'application/xhtml+xml' => 1.0,
					'text/html' => 0.5 ) ) );
		$this->assertEquals(
			'text/html',
			wfNegotiateType(
				array( 'text/*' => 1.0,
					'image/*' => 0.7,
					'*/*' => 0.3 ),
				array( 'application/xhtml+xml' => 1.0,
					'text/html' => 0.5 ) ) );
		$this->assertNull(
			wfNegotiateType(
				array( 'text/*' => 1.0 ),
				array( 'application/xhtml+xml' => 1.0 ) ) );
	}

	/**
	 * @covers ::wfDebug
	 * @covers ::wfDebugMem
	 */
	public function testDebugFunctionTest() {

		global $wgDebugLogFile, $wgDebugTimestamps;

		$old_log_file = $wgDebugLogFile;
		$wgDebugLogFile = tempnam( wfTempDir(), 'mw-' );
		# @todo FIXME: $wgDebugTimestamps should be tested
		$old_wgDebugTimestamps = $wgDebugTimestamps;
		$wgDebugTimestamps = false;

		wfDebug( "This is a normal string" );
		$this->assertEquals( "This is a normal string", file_get_contents( $wgDebugLogFile ) );
		unlink( $wgDebugLogFile );

		wfDebug( "This is nöt an ASCII string" );
		$this->assertEquals( "This is nöt an ASCII string", file_get_contents( $wgDebugLogFile ) );
		unlink( $wgDebugLogFile );

		wfDebug( "\00305This has böth UTF and control chars\003" );
		$this->assertEquals( " 05This has böth UTF and control chars ", file_get_contents( $wgDebugLogFile ) );
		unlink( $wgDebugLogFile );

		wfDebugMem();
		$this->assertGreaterThan( 5000, preg_replace( '/\D/', '', file_get_contents( $wgDebugLogFile ) ) );
		unlink( $wgDebugLogFile );

		wfDebugMem( true );
		$this->assertGreaterThan( 5000000, preg_replace( '/\D/', '', file_get_contents( $wgDebugLogFile ) ) );
		unlink( $wgDebugLogFile );

		$wgDebugLogFile = $old_log_file;
		$wgDebugTimestamps = $old_wgDebugTimestamps;
	}

	/**
	 * @covers ::wfClientAcceptsGzip
	 */
	public function testClientAcceptsGzipTest() {

		$settings = array(
			'gzip' => true,
			'bzip' => false,
			'*' => false,
			'compress, gzip' => true,
			'gzip;q=1.0' => true,
			'foozip' => false,
			'foo*zip' => false,
			'gzip;q=abcde' => true, //is this REALLY valid?
			'gzip;q=12345678.9' => true,
			' gzip' => true,
		);

		if ( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
			$old_server_setting = $_SERVER['HTTP_ACCEPT_ENCODING'];
		}

		foreach ( $settings as $encoding => $expect ) {
			$_SERVER['HTTP_ACCEPT_ENCODING'] = $encoding;

			$this->assertEquals( $expect, wfClientAcceptsGzip( true ),
				"'$encoding' => " . wfBoolToStr( $expect ) );
		}

		if ( isset( $old_server_setting ) ) {
			$_SERVER['HTTP_ACCEPT_ENCODING'] = $old_server_setting;
		}
	}

	/**
	 * @covers ::swap
	 */
	public function testSwapVarsTest() {
		$var1 = 1;
		$var2 = 2;

		$this->assertEquals( $var1, 1, 'var1 is set originally' );
		$this->assertEquals( $var2, 2, 'var1 is set originally' );

		swap( $var1, $var2 );

		$this->assertEquals( $var1, 2, 'var1 is swapped' );
		$this->assertEquals( $var2, 1, 'var2 is swapped' );
	}

	/**
	 * @covers ::wfPercent
	 */
	public function testWfPercentTest() {

		$pcts = array(
			array( 6 / 7, '0.86%', 2, false ),
			array( 3 / 3, '1%' ),
			array( 22 / 7, '3.14286%', 5 ),
			array( 3 / 6, '0.5%' ),
			array( 1 / 3, '0%', 0 ),
			array( 10 / 3, '0%', -1 ),
			array( 3 / 4 / 5, '0.1%', 1 ),
			array( 6 / 7 * 8, '6.8571428571%', 10 ),
		);

		foreach ( $pcts as $pct ) {
			if ( !isset( $pct[2] ) ) {
				$pct[2] = 2;
			}
			if ( !isset( $pct[3] ) ) {
				$pct[3] = true;
			}

			$this->assertEquals( wfPercent( $pct[0], $pct[2], $pct[3] ), $pct[1], $pct[1] );
		}
	}

	/**
	 * test @see wfShorthandToInteger()
	 * @dataProvider provideShorthand
	 * @covers ::wfShorthandToInteger
	 */
	public function testWfShorthandToInteger( $shorthand, $expected ) {
		$this->assertEquals( $expected,
			wfShorthandToInteger( $shorthand )
		);
	}

	/** array( shorthand, expected integer ) */
	public static function provideShorthand() {
		return array(
			# Null, empty ...
			array( '', -1 ),
			array( '  ', -1 ),
			array( null, -1 ),

			# Failures returns 0 :(
			array( 'ABCDEFG', 0 ),
			array( 'Ak', 0 ),

			# Int, strings with spaces
			array( 1, 1 ),
			array( ' 1 ', 1 ),
			array( 1023, 1023 ),
			array( ' 1023 ', 1023 ),

			# kilo, Mega, Giga
			array( '1k', 1024 ),
			array( '1K', 1024 ),
			array( '1m', 1024 * 1024 ),
			array( '1M', 1024 * 1024 ),
			array( '1g', 1024 * 1024 * 1024 ),
			array( '1G', 1024 * 1024 * 1024 ),

			# Negatives
			array( -1, -1 ),
			array( -500, -500 ),
			array( '-500', -500 ),
			array( '-1k', -1024 ),

			# Zeroes
			array( '0', 0 ),
			array( '0k', 0 ),
			array( '0M', 0 ),
			array( '0G', 0 ),
			array( '-0', 0 ),
			array( '-0k', 0 ),
			array( '-0M', 0 ),
			array( '-0G', 0 ),
		);
	}

	/**
	 * @param String $old: Text as it was in the database
	 * @param String $mine: Text submitted while user was editing
	 * @param String $yours: Text submitted by the user
	 * @param Boolean $expectedMergeResult Whether the merge should be a success
	 * @param String $expectedText: Text after merge has been completed
	 *
	 * @dataProvider provideMerge()
	 * @group medium
	 * @covers ::wfMerge
	 */
	public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText ) {
		$this->checkHasDiff3();

		$mergedText = null;
		$isMerged = wfMerge( $old, $mine, $yours, $mergedText );

		$msg = 'Merge should be a ';
		$msg .= $expectedMergeResult ? 'success' : 'failure';
		$this->assertEquals( $expectedMergeResult, $isMerged, $msg );

		if ( $isMerged ) {
			// Verify the merged text
			$this->assertEquals( $expectedText, $mergedText,
				'is merged text as expected?' );
		}
	}

	public static function provideMerge() {
		$EXPECT_MERGE_SUCCESS = true;
		$EXPECT_MERGE_FAILURE = false;

		return array(
			// #0: clean merge
			array(
				// old:
				"one one one\n" . // trimmed
					"\n" .
					"two two two",

				// mine:
				"one one one ONE ONE\n" .
					"\n" .
					"two two two\n", // with tailing whitespace

				// yours:
				"one one one\n" .
					"\n" .
					"two two TWO TWO", // trimmed

				// ok:
				$EXPECT_MERGE_SUCCESS,

				// result:
				"one one one ONE ONE\n" .
					"\n" .
					"two two TWO TWO\n", // note: will always end in a newline
			),

			// #1: conflict, fail
			array(
				// old:
				"one one one", // trimmed

				// mine:
				"one one one ONE ONE\n" .
					"\n" .
					"bla bla\n" .
					"\n", // with tailing whitespace

				// yours:
				"one one one\n" .
					"\n" .
					"two two", // trimmed

				$EXPECT_MERGE_FAILURE,

				// result:
				null,
			),
		);
	}

	/**
	 * @dataProvider provideMakeUrlIndexes()
	 * @covers ::wfMakeUrlIndexes
	 */
	public function testMakeUrlIndexes( $url, $expected ) {
		$index = wfMakeUrlIndexes( $url );
		$this->assertEquals( $expected, $index, "wfMakeUrlIndexes(\"$url\")" );
	}

	public static function provideMakeUrlIndexes() {
		return array(
			array(
				// just a regular :)
				'https://bugzilla.wikimedia.org/show_bug.cgi?id=28627',
				array( 'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627' )
			),
			array(
				// mailtos are handled special
				// is this really right though? that final . probably belongs earlier?
				'mailto:wiki@wikimedia.org',
				array( 'mailto:org.wikimedia@wiki.' )
			),

			// file URL cases per bug 28627...
			array(
				// three slashes: local filesystem path Unix-style
				'file:///whatever/you/like.txt',
				array( 'file://./whatever/you/like.txt' )
			),
			array(
				// three slashes: local filesystem path Windows-style
				'file:///c:/whatever/you/like.txt',
				array( 'file://./c:/whatever/you/like.txt' )
			),
			array(
				// two slashes: UNC filesystem path Windows-style
				'file://intranet/whatever/you/like.txt',
				array( 'file://intranet./whatever/you/like.txt' )
			),
			// Multiple-slash cases that can sorta work on Mozilla
			// if you hack it just right are kinda pathological,
			// and unreliable cross-platform or on IE which means they're
			// unlikely to appear on intranets.
			//
			// Those will survive the algorithm but with results that
			// are less consistent.

			// protocol-relative URL cases per bug 29854...
			array(
				'//bugzilla.wikimedia.org/show_bug.cgi?id=28627',
				array(
					'http://org.wikimedia.bugzilla./show_bug.cgi?id=28627',
					'https://org.wikimedia.bugzilla./show_bug.cgi?id=28627'
				)
			),
		);
	}

	/**
	 * @dataProvider provideWfMatchesDomainList
	 * @covers ::wfMatchesDomainList
	 */
	public function testWfMatchesDomainList( $url, $domains, $expected, $description ) {
		$actual = wfMatchesDomainList( $url, $domains );
		$this->assertEquals( $expected, $actual, $description );
	}

	public static function provideWfMatchesDomainList() {
		$a = array();
		$protocols = array( 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' );
		foreach ( $protocols as $pDesc => $p ) {
			$a = array_merge( $a, array(
				array( "$p//www.example.com", array(), false, "No matches for empty domains array, $pDesc URL" ),
				array( "$p//www.example.com", array( 'www.example.com' ), true, "Exact match in domains array, $pDesc URL" ),
				array( "$p//www.example.com", array( 'example.com' ), true, "Match without subdomain in domains array, $pDesc URL" ),
				array( "$p//www.example2.com", array( 'www.example.com', 'www.example2.com', 'www.example3.com' ), true, "Exact match with other domains in array, $pDesc URL" ),
				array( "$p//www.example2.com", array( 'example.com', 'example2.com', 'example3,com' ), true, "Match without subdomain with other domains in array, $pDesc URL" ),
				array( "$p//www.example4.com", array( 'example.com', 'example2.com', 'example3,com' ), false, "Domain not in array, $pDesc URL" ),
				array( "$p//nds-nl.wikipedia.org", array( 'nl.wikipedia.org' ), false, "Non-matching substring of domain, $pDesc URL" ),
			) );
		}

		return $a;
	}

	/**
	 * @covers ::wfMkdirParents
	 */
	public function testWfMkdirParents() {
		// Should not return true if file exists instead of directory
		$fname = $this->getNewTempFile();
		wfSuppressWarnings();
		$ok = wfMkdirParents( $fname );
		wfRestoreWarnings();
		$this->assertFalse( $ok );
	}

	/**
	 * @dataProvider provideWfShellMaintenanceCmdList
	 * @covers ::wfShellMaintenanceCmd
	 */
	public function testWfShellMaintenanceCmd( $script, $parameters, $options, $expected, $description ) {
		if ( wfIsWindows() ) {
			// Approximation that's good enough for our purposes just now
			$expected = str_replace( "'", '"', $expected );
		}
		$actual = wfShellMaintenanceCmd( $script, $parameters, $options );
		$this->assertEquals( $expected, $actual, $description );
	}

	public static function provideWfShellMaintenanceCmdList() {
		global $wgPhpCli;

		return array(
			array( 'eval.php', array( '--help', '--test' ), array(),
				"'$wgPhpCli' 'eval.php' '--help' '--test'",
				"Called eval.php --help --test" ),
			array( 'eval.php', array( '--help', '--test space' ), array( 'php' => 'php5' ),
				"'php5' 'eval.php' '--help' '--test space'",
				"Called eval.php --help --test with php option" ),
			array( 'eval.php', array( '--help', '--test', 'X' ), array( 'wrapper' => 'MWScript.php' ),
				"'$wgPhpCli' 'MWScript.php' 'eval.php' '--help' '--test' 'X'",
				"Called eval.php --help --test with wrapper option" ),
			array( 'eval.php', array( '--help', '--test', 'y' ), array( 'php' => 'php5', 'wrapper' => 'MWScript.php' ),
				"'php5' 'MWScript.php' 'eval.php' '--help' '--test' 'y'",
				"Called eval.php --help --test with wrapper and php option" ),
		);
	}
	/* @TODO many more! */
}