Merge "Soft deprecate Title::getUserCaseDBKey()"
[lhc/web/wiklou.git] / tests / phpunit / includes / GlobalFunctions / GlobalTest.php
1 <?php
2
3 use MediaWiki\Logger\LegacyLogger;
4
5 /**
6 * @group Database
7 * @group GlobalFunctions
8 */
9 class GlobalTest extends MediaWikiTestCase {
10 protected function setUp() {
11 parent::setUp();
12
13 $readOnlyFile = $this->getNewTempFile();
14 unlink( $readOnlyFile );
15
16 $this->setMwGlobals( [
17 'wgReadOnlyFile' => $readOnlyFile,
18 'wgUrlProtocols' => [
19 'http://',
20 'https://',
21 'mailto:',
22 '//',
23 'file://', # Non-default
24 ],
25 ] );
26 }
27
28 /**
29 * @dataProvider provideForWfArrayDiff2
30 * @covers ::wfArrayDiff2
31 */
32 public function testWfArrayDiff2( $a, $b, $expected ) {
33 $this->assertEquals(
34 wfArrayDiff2( $a, $b ), $expected
35 );
36 }
37
38 // @todo Provide more tests
39 public static function provideForWfArrayDiff2() {
40 // $a $b $expected
41 return [
42 [
43 [ 'a', 'b' ],
44 [ 'a', 'b' ],
45 [],
46 ],
47 [
48 [ [ 'a' ], [ 'a', 'b', 'c' ] ],
49 [ [ 'a' ], [ 'a', 'b' ] ],
50 [ 1 => [ 'a', 'b', 'c' ] ],
51 ],
52 ];
53 }
54
55 /*
56 * Test cases for random functions could hypothetically fail,
57 * even though they shouldn't.
58 */
59
60 /**
61 * @covers ::wfRandom
62 */
63 public function testRandom() {
64 $this->assertFalse(
65 wfRandom() == wfRandom()
66 );
67 }
68
69 /**
70 * @covers ::wfRandomString
71 */
72 public function testRandomString() {
73 $this->assertFalse(
74 wfRandomString() == wfRandomString()
75 );
76 $this->assertEquals(
77 strlen( wfRandomString( 10 ) ), 10
78 );
79 $this->assertTrue(
80 preg_match( '/^[0-9a-f]+$/i', wfRandomString() ) === 1
81 );
82 }
83
84 /**
85 * @covers ::wfUrlencode
86 */
87 public function testUrlencode() {
88 $this->assertEquals(
89 "%E7%89%B9%E5%88%A5:Contributions/Foobar",
90 wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) );
91 }
92
93 /**
94 * @covers ::wfExpandIRI
95 */
96 public function testExpandIRI() {
97 $this->assertEquals(
98 "https://te.wikibooks.org/wiki/ఉబుంటు_వాడుకరి_మార్గదర్శని",
99 wfExpandIRI( "https://te.wikibooks.org/wiki/"
100 . "%E0%B0%89%E0%B0%AC%E0%B1%81%E0%B0%82%E0%B0%9F%E0%B1%81_"
101 . "%E0%B0%B5%E0%B0%BE%E0%B0%A1%E0%B1%81%E0%B0%95%E0%B0%B0%E0%B0%BF_"
102 . "%E0%B0%AE%E0%B0%BE%E0%B0%B0%E0%B1%8D%E0%B0%97%E0%B0%A6%E0%B0%B0"
103 . "%E0%B1%8D%E0%B0%B6%E0%B0%A8%E0%B0%BF" ) );
104 }
105
106 /**
107 * Intended to cover the relevant bits of ServiceWiring.php, as well as GlobalFunctions.php
108 * @covers ::wfReadOnly
109 */
110 public function testReadOnlyEmpty() {
111 global $wgReadOnly;
112 $wgReadOnly = null;
113
114 MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode()->clearCache();
115 $this->assertFalse( wfReadOnly() );
116 $this->assertFalse( wfReadOnly() );
117 }
118
119 /**
120 * Intended to cover the relevant bits of ServiceWiring.php, as well as GlobalFunctions.php
121 * @covers ::wfReadOnly
122 */
123 public function testReadOnlySet() {
124 global $wgReadOnly, $wgReadOnlyFile;
125
126 $readOnlyMode = MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode();
127 $readOnlyMode->clearCache();
128
129 $f = fopen( $wgReadOnlyFile, "wt" );
130 fwrite( $f, 'Message' );
131 fclose( $f );
132 $wgReadOnly = null; # Check on $wgReadOnlyFile
133
134 $this->assertTrue( wfReadOnly() );
135 $this->assertTrue( wfReadOnly() ); # Check cached
136
137 unlink( $wgReadOnlyFile );
138 $readOnlyMode->clearCache();
139 $this->assertFalse( wfReadOnly() );
140 $this->assertFalse( wfReadOnly() );
141 }
142
143 /**
144 * This behaviour could probably be deprecated. Several extensions rely on it as of 1.29.
145 * @covers ::wfReadOnlyReason
146 */
147 public function testReadOnlyGlobalChange() {
148 $this->assertFalse( wfReadOnlyReason() );
149 $this->setMwGlobals( [
150 'wgReadOnly' => 'reason'
151 ] );
152 $this->assertSame( 'reason', wfReadOnlyReason() );
153 }
154
155 public static function provideArrayToCGI() {
156 return [
157 [ [], '' ], // empty
158 [ [ 'foo' => 'bar' ], 'foo=bar' ], // string test
159 [ [ 'foo' => '' ], 'foo=' ], // empty string test
160 [ [ 'foo' => 1 ], 'foo=1' ], // number test
161 [ [ 'foo' => true ], 'foo=1' ], // true test
162 [ [ 'foo' => false ], '' ], // false test
163 [ [ 'foo' => null ], '' ], // null test
164 [ [ 'foo' => 'A&B=5+6@!"\'' ], 'foo=A%26B%3D5%2B6%40%21%22%27' ], // urlencoding test
165 [
166 [ 'foo' => 'bar', 'baz' => 'is', 'asdf' => 'qwerty' ],
167 'foo=bar&baz=is&asdf=qwerty'
168 ], // multi-item test
169 [ [ 'foo' => [ 'bar' => 'baz' ] ], 'foo%5Bbar%5D=baz' ],
170 [
171 [ 'foo' => [ 'bar' => 'baz', 'qwerty' => 'asdf' ] ],
172 'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf'
173 ],
174 [ [ 'foo' => [ 'bar', 'baz' ] ], 'foo%5B0%5D=bar&foo%5B1%5D=baz' ],
175 [
176 [ 'foo' => [ 'bar' => [ 'bar' => 'baz' ] ] ],
177 'foo%5Bbar%5D%5Bbar%5D=baz'
178 ],
179 ];
180 }
181
182 /**
183 * @dataProvider provideArrayToCGI
184 * @covers ::wfArrayToCgi
185 */
186 public function testArrayToCGI( $array, $result ) {
187 $this->assertEquals( $result, wfArrayToCgi( $array ) );
188 }
189
190 /**
191 * @covers ::wfArrayToCgi
192 */
193 public function testArrayToCGI2() {
194 $this->assertEquals(
195 "baz=bar&foo=bar",
196 wfArrayToCgi(
197 [ 'baz' => 'bar' ],
198 [ 'foo' => 'bar', 'baz' => 'overridden value' ] ) );
199 }
200
201 public static function provideCgiToArray() {
202 return [
203 [ '', [] ], // empty
204 [ 'foo=bar', [ 'foo' => 'bar' ] ], // string
205 [ 'foo=', [ 'foo' => '' ] ], // empty string
206 [ 'foo', [ 'foo' => '' ] ], // missing =
207 [ 'foo=bar&qwerty=asdf', [ 'foo' => 'bar', 'qwerty' => 'asdf' ] ], // multiple value
208 [ 'foo=A%26B%3D5%2B6%40%21%22%27', [ 'foo' => 'A&B=5+6@!"\'' ] ], // urldecoding test
209 [ 'foo%5Bbar%5D=baz', [ 'foo' => [ 'bar' => 'baz' ] ] ],
210 [
211 'foo%5Bbar%5D=baz&foo%5Bqwerty%5D=asdf',
212 [ 'foo' => [ 'bar' => 'baz', 'qwerty' => 'asdf' ] ]
213 ],
214 [ 'foo%5B0%5D=bar&foo%5B1%5D=baz', [ 'foo' => [ 0 => 'bar', 1 => 'baz' ] ] ],
215 [
216 'foo%5Bbar%5D%5Bbar%5D=baz',
217 [ 'foo' => [ 'bar' => [ 'bar' => 'baz' ] ] ]
218 ],
219 ];
220 }
221
222 /**
223 * @dataProvider provideCgiToArray
224 * @covers ::wfCgiToArray
225 */
226 public function testCgiToArray( $cgi, $result ) {
227 $this->assertEquals( $result, wfCgiToArray( $cgi ) );
228 }
229
230 public static function provideCgiRoundTrip() {
231 return [
232 [ '' ],
233 [ 'foo=bar' ],
234 [ 'foo=' ],
235 [ 'foo=bar&baz=biz' ],
236 [ 'foo=A%26B%3D5%2B6%40%21%22%27' ],
237 [ 'foo%5Bbar%5D=baz' ],
238 [ 'foo%5B0%5D=bar&foo%5B1%5D=baz' ],
239 [ 'foo%5Bbar%5D%5Bbar%5D=baz' ],
240 ];
241 }
242
243 /**
244 * @dataProvider provideCgiRoundTrip
245 * @covers ::wfArrayToCgi
246 */
247 public function testCgiRoundTrip( $cgi ) {
248 $this->assertEquals( $cgi, wfArrayToCgi( wfCgiToArray( $cgi ) ) );
249 }
250
251 /**
252 * @covers ::mimeTypeMatch
253 */
254 public function testMimeTypeMatch() {
255 $this->assertEquals(
256 'text/html',
257 mimeTypeMatch( 'text/html',
258 [ 'application/xhtml+xml' => 1.0,
259 'text/html' => 0.7,
260 'text/plain' => 0.3 ] ) );
261 $this->assertEquals(
262 'text/*',
263 mimeTypeMatch( 'text/html',
264 [ 'image/*' => 1.0,
265 'text/*' => 0.5 ] ) );
266 $this->assertEquals(
267 '*/*',
268 mimeTypeMatch( 'text/html',
269 [ '*/*' => 1.0 ] ) );
270 $this->assertNull(
271 mimeTypeMatch( 'text/html',
272 [ 'image/png' => 1.0,
273 'image/svg+xml' => 0.5 ] ) );
274 }
275
276 /**
277 * @covers ::wfNegotiateType
278 */
279 public function testNegotiateType() {
280 $this->assertEquals(
281 'text/html',
282 wfNegotiateType(
283 [ 'application/xhtml+xml' => 1.0,
284 'text/html' => 0.7,
285 'text/plain' => 0.5,
286 'text/*' => 0.2 ],
287 [ 'text/html' => 1.0 ] ) );
288 $this->assertEquals(
289 'application/xhtml+xml',
290 wfNegotiateType(
291 [ 'application/xhtml+xml' => 1.0,
292 'text/html' => 0.7,
293 'text/plain' => 0.5,
294 'text/*' => 0.2 ],
295 [ 'application/xhtml+xml' => 1.0,
296 'text/html' => 0.5 ] ) );
297 $this->assertEquals(
298 'text/html',
299 wfNegotiateType(
300 [ 'text/html' => 1.0,
301 'text/plain' => 0.5,
302 'text/*' => 0.5,
303 'application/xhtml+xml' => 0.2 ],
304 [ 'application/xhtml+xml' => 1.0,
305 'text/html' => 0.5 ] ) );
306 $this->assertEquals(
307 'text/html',
308 wfNegotiateType(
309 [ 'text/*' => 1.0,
310 'image/*' => 0.7,
311 '*/*' => 0.3 ],
312 [ 'application/xhtml+xml' => 1.0,
313 'text/html' => 0.5 ] ) );
314 $this->assertNull(
315 wfNegotiateType(
316 [ 'text/*' => 1.0 ],
317 [ 'application/xhtml+xml' => 1.0 ] ) );
318 }
319
320 /**
321 * @covers ::wfDebug
322 * @covers ::wfDebugMem
323 */
324 public function testDebugFunctionTest() {
325 $debugLogFile = $this->getNewTempFile();
326
327 $this->setMwGlobals( [
328 'wgDebugLogFile' => $debugLogFile,
329 #  @todo FIXME: $wgDebugTimestamps should be tested
330 'wgDebugTimestamps' => false,
331 ] );
332 $this->setLogger( 'wfDebug', new LegacyLogger( 'wfDebug' ) );
333
334 wfDebug( "This is a normal string" );
335 $this->assertEquals( "This is a normal string\n", file_get_contents( $debugLogFile ) );
336 unlink( $debugLogFile );
337
338 wfDebug( "This is nöt an ASCII string" );
339 $this->assertEquals( "This is nöt an ASCII string\n", file_get_contents( $debugLogFile ) );
340 unlink( $debugLogFile );
341
342 wfDebug( "\00305This has böth UTF and control chars\003" );
343 $this->assertEquals(
344 " 05This has böth UTF and control chars \n",
345 file_get_contents( $debugLogFile )
346 );
347 unlink( $debugLogFile );
348
349 wfDebugMem();
350 $this->assertGreaterThan(
351 1000,
352 preg_replace( '/\D/', '', file_get_contents( $debugLogFile ) )
353 );
354 unlink( $debugLogFile );
355
356 wfDebugMem( true );
357 $this->assertGreaterThan(
358 1000000,
359 preg_replace( '/\D/', '', file_get_contents( $debugLogFile ) )
360 );
361 unlink( $debugLogFile );
362 }
363
364 /**
365 * @covers ::wfClientAcceptsGzip
366 */
367 public function testClientAcceptsGzipTest() {
368 $settings = [
369 'gzip' => true,
370 'bzip' => false,
371 '*' => false,
372 'compress, gzip' => true,
373 'gzip;q=1.0' => true,
374 'foozip' => false,
375 'foo*zip' => false,
376 'gzip;q=abcde' => true, // is this REALLY valid?
377 'gzip;q=12345678.9' => true,
378 ' gzip' => true,
379 ];
380
381 if ( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
382 $old_server_setting = $_SERVER['HTTP_ACCEPT_ENCODING'];
383 }
384
385 foreach ( $settings as $encoding => $expect ) {
386 $_SERVER['HTTP_ACCEPT_ENCODING'] = $encoding;
387
388 $this->assertEquals( $expect, wfClientAcceptsGzip( true ),
389 "'$encoding' => " . wfBoolToStr( $expect ) );
390 }
391
392 if ( isset( $old_server_setting ) ) {
393 $_SERVER['HTTP_ACCEPT_ENCODING'] = $old_server_setting;
394 }
395 }
396
397 /**
398 * @covers ::wfPercent
399 */
400 public function testWfPercentTest() {
401 $pcts = [
402 [ 6 / 7, '0.86%', 2, false ],
403 [ 3 / 3, '1%' ],
404 [ 22 / 7, '3.14286%', 5 ],
405 [ 3 / 6, '0.5%' ],
406 [ 1 / 3, '0%', 0 ],
407 [ 10 / 3, '0%', -1 ],
408 [ 3 / 4 / 5, '0.1%', 1 ],
409 [ 6 / 7 * 8, '6.8571428571%', 10 ],
410 ];
411
412 foreach ( $pcts as $pct ) {
413 if ( !isset( $pct[2] ) ) {
414 $pct[2] = 2;
415 }
416 if ( !isset( $pct[3] ) ) {
417 $pct[3] = true;
418 }
419
420 $this->assertEquals( wfPercent( $pct[0], $pct[2], $pct[3] ), $pct[1], $pct[1] );
421 }
422 }
423
424 /**
425 * test @see wfShorthandToInteger()
426 * @dataProvider provideShorthand
427 * @covers ::wfShorthandToInteger
428 */
429 public function testWfShorthandToInteger( $shorthand, $expected ) {
430 $this->assertEquals( $expected,
431 wfShorthandToInteger( $shorthand )
432 );
433 }
434
435 public static function provideShorthand() {
436 // Syntax: [ shorthand, expected integer ]
437 return [
438 # Null, empty ...
439 [ '', -1 ],
440 [ ' ', -1 ],
441 [ null, -1 ],
442
443 # Failures returns 0 :(
444 [ 'ABCDEFG', 0 ],
445 [ 'Ak', 0 ],
446
447 # Int, strings with spaces
448 [ 1, 1 ],
449 [ ' 1 ', 1 ],
450 [ 1023, 1023 ],
451 [ ' 1023 ', 1023 ],
452
453 # kilo, Mega, Giga
454 [ '1k', 1024 ],
455 [ '1K', 1024 ],
456 [ '1m', 1024 * 1024 ],
457 [ '1M', 1024 * 1024 ],
458 [ '1g', 1024 * 1024 * 1024 ],
459 [ '1G', 1024 * 1024 * 1024 ],
460
461 # Negatives
462 [ -1, -1 ],
463 [ -500, -500 ],
464 [ '-500', -500 ],
465 [ '-1k', -1024 ],
466
467 # Zeroes
468 [ '0', 0 ],
469 [ '0k', 0 ],
470 [ '0M', 0 ],
471 [ '0G', 0 ],
472 [ '-0', 0 ],
473 [ '-0k', 0 ],
474 [ '-0M', 0 ],
475 [ '-0G', 0 ],
476 ];
477 }
478
479 /**
480 * @covers ::wfMerge
481 */
482 public function testMerge_worksWithLessParameters() {
483 $this->markTestSkippedIfNoDiff3();
484
485 $mergedText = null;
486 $successfulMerge = wfMerge( "old1\n\nold2", "old1\n\nnew2", "new1\n\nold2", $mergedText );
487
488 $mergedText = null;
489 $conflictingMerge = wfMerge( 'old', 'old and mine', 'old and yours', $mergedText );
490
491 $this->assertEquals( true, $successfulMerge );
492 $this->assertEquals( false, $conflictingMerge );
493 }
494
495 /**
496 * @param string $old Text as it was in the database
497 * @param string $mine Text submitted while user was editing
498 * @param string $yours Text submitted by the user
499 * @param bool $expectedMergeResult Whether the merge should be a success
500 * @param string $expectedText Text after merge has been completed
501 * @param string $expectedMergeAttemptResult Diff3 output if conflicts occur
502 *
503 * @dataProvider provideMerge()
504 * @group medium
505 * @covers ::wfMerge
506 */
507 public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText,
508 $expectedMergeAttemptResult ) {
509 $this->markTestSkippedIfNoDiff3();
510
511 $mergedText = null;
512 $attemptMergeResult = null;
513 $isMerged = wfMerge( $old, $mine, $yours, $mergedText, $mergeAttemptResult );
514
515 $msg = 'Merge should be a ';
516 $msg .= $expectedMergeResult ? 'success' : 'failure';
517 $this->assertEquals( $expectedMergeResult, $isMerged, $msg );
518 $this->assertEquals( $expectedMergeAttemptResult, $mergeAttemptResult );
519
520 if ( $isMerged ) {
521 // Verify the merged text
522 $this->assertEquals( $expectedText, $mergedText,
523 'is merged text as expected?' );
524 }
525 }
526
527 public static function provideMerge() {
528 $EXPECT_MERGE_SUCCESS = true;
529 $EXPECT_MERGE_FAILURE = false;
530
531 return [
532 // #0: clean merge
533 [
534 // old:
535 "one one one\n" . // trimmed
536 "\n" .
537 "two two two",
538
539 // mine:
540 "one one one ONE ONE\n" .
541 "\n" .
542 "two two two\n", // with tailing whitespace
543
544 // yours:
545 "one one one\n" .
546 "\n" .
547 "two two TWO TWO", // trimmed
548
549 // ok:
550 $EXPECT_MERGE_SUCCESS,
551
552 // result:
553 "one one one ONE ONE\n" .
554 "\n" .
555 "two two TWO TWO\n", // note: will always end in a newline
556
557 // mergeAttemptResult:
558 "",
559 ],
560
561 // #1: conflict, fail
562 [
563 // old:
564 "one one one", // trimmed
565
566 // mine:
567 "one one one ONE ONE\n" .
568 "\n" .
569 "bla bla\n" .
570 "\n", // with tailing whitespace
571
572 // yours:
573 "one one one\n" .
574 "\n" .
575 "two two", // trimmed
576
577 $EXPECT_MERGE_FAILURE,
578
579 // result:
580 null,
581
582 // mergeAttemptResult:
583 "1,3c\n" .
584 "one one one\n" .
585 "\n" .
586 "two two\n" .
587 ".\n",
588 ],
589 ];
590 }
591
592 /**
593 * @dataProvider provideWfMatchesDomainList
594 * @covers ::wfMatchesDomainList
595 */
596 public function testWfMatchesDomainList( $url, $domains, $expected, $description ) {
597 $actual = wfMatchesDomainList( $url, $domains );
598 $this->assertEquals( $expected, $actual, $description );
599 }
600
601 public static function provideWfMatchesDomainList() {
602 $a = [];
603 $protocols = [ 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' ];
604 foreach ( $protocols as $pDesc => $p ) {
605 $a = array_merge( $a, [
606 [
607 "$p//www.example.com",
608 [],
609 false,
610 "No matches for empty domains array, $pDesc URL"
611 ],
612 [
613 "$p//www.example.com",
614 [ 'www.example.com' ],
615 true,
616 "Exact match in domains array, $pDesc URL"
617 ],
618 [
619 "$p//www.example.com",
620 [ 'example.com' ],
621 true,
622 "Match without subdomain in domains array, $pDesc URL"
623 ],
624 [
625 "$p//www.example2.com",
626 [ 'www.example.com', 'www.example2.com', 'www.example3.com' ],
627 true,
628 "Exact match with other domains in array, $pDesc URL"
629 ],
630 [
631 "$p//www.example2.com",
632 [ 'example.com', 'example2.com', 'example3,com' ],
633 true,
634 "Match without subdomain with other domains in array, $pDesc URL"
635 ],
636 [
637 "$p//www.example4.com",
638 [ 'example.com', 'example2.com', 'example3,com' ],
639 false,
640 "Domain not in array, $pDesc URL"
641 ],
642 [
643 "$p//nds-nl.wikipedia.org",
644 [ 'nl.wikipedia.org' ],
645 false,
646 "Non-matching substring of domain, $pDesc URL"
647 ],
648 ] );
649 }
650
651 return $a;
652 }
653
654 /**
655 * @covers ::wfMkdirParents
656 */
657 public function testWfMkdirParents() {
658 // Should not return true if file exists instead of directory
659 $fname = $this->getNewTempFile();
660 Wikimedia\suppressWarnings();
661 $ok = wfMkdirParents( $fname );
662 Wikimedia\restoreWarnings();
663 $this->assertFalse( $ok );
664 }
665
666 /**
667 * @dataProvider provideWfShellWikiCmdList
668 * @covers ::wfShellWikiCmd
669 */
670 public function testWfShellWikiCmd( $script, $parameters, $options,
671 $expected, $description
672 ) {
673 if ( wfIsWindows() ) {
674 // Approximation that's good enough for our purposes just now
675 $expected = str_replace( "'", '"', $expected );
676 }
677 $actual = wfShellWikiCmd( $script, $parameters, $options );
678 $this->assertEquals( $expected, $actual, $description );
679 }
680
681 public function wfWikiID() {
682 $this->setMwGlobals( [
683 'wgDBname' => 'example',
684 'wgDBprefix' => '',
685 ] );
686 $this->assertEquals(
687 wfWikiID(),
688 'example'
689 );
690
691 $this->setMwGlobals( [
692 'wgDBname' => 'example',
693 'wgDBprefix' => 'mw_',
694 ] );
695 $this->assertEquals(
696 wfWikiID(),
697 'example-mw_'
698 );
699 }
700
701 /**
702 * @covers ::wfMemcKey
703 */
704 public function testWfMemcKey() {
705 $cache = ObjectCache::getLocalClusterInstance();
706 $this->assertEquals(
707 $cache->makeKey( 'foo', 123, 'bar' ),
708 wfMemcKey( 'foo', 123, 'bar' )
709 );
710 }
711
712 /**
713 * @covers ::wfForeignMemcKey
714 */
715 public function testWfForeignMemcKey() {
716 $cache = ObjectCache::getLocalClusterInstance();
717 $keyspace = $this->readAttribute( $cache, 'keyspace' );
718 $this->assertEquals(
719 wfForeignMemcKey( $keyspace, '', 'foo', 'bar' ),
720 $cache->makeKey( 'foo', 'bar' )
721 );
722 }
723
724 /**
725 * @covers ::wfGlobalCacheKey
726 */
727 public function testWfGlobalCacheKey() {
728 $cache = ObjectCache::getLocalClusterInstance();
729 $this->assertEquals(
730 $cache->makeGlobalKey( 'foo', 123, 'bar' ),
731 wfGlobalCacheKey( 'foo', 123, 'bar' )
732 );
733 }
734
735 public static function provideWfShellWikiCmdList() {
736 global $wgPhpCli;
737
738 return [
739 [ 'eval.php', [ '--help', '--test' ], [],
740 "'$wgPhpCli' 'eval.php' '--help' '--test'",
741 "Called eval.php --help --test" ],
742 [ 'eval.php', [ '--help', '--test space' ], [ 'php' => 'php5' ],
743 "'php5' 'eval.php' '--help' '--test space'",
744 "Called eval.php --help --test with php option" ],
745 [ 'eval.php', [ '--help', '--test', 'X' ], [ 'wrapper' => 'MWScript.php' ],
746 "'$wgPhpCli' 'MWScript.php' 'eval.php' '--help' '--test' 'X'",
747 "Called eval.php --help --test with wrapper option" ],
748 [
749 'eval.php',
750 [ '--help', '--test', 'y' ],
751 [ 'php' => 'php5', 'wrapper' => 'MWScript.php' ],
752 "'php5' 'MWScript.php' 'eval.php' '--help' '--test' 'y'",
753 "Called eval.php --help --test with wrapper and php option"
754 ],
755 ];
756 }
757 /* @todo many more! */
758 }