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