Index: trunk/phase3/tests/phpunit/includes/MWNamespaceTest.php |
— | — | @@ -41,18 +41,18 @@ |
42 | 42 | */ |
43 | 43 | public function testIsSubject() { |
44 | 44 | // Special namespaces |
45 | | - $this->assertTrue( MWNamespace::isSubject( NS_MEDIA ) ); |
46 | | - $this->assertTrue( MWNamespace::isSubject( NS_SPECIAL ) ); |
| 45 | + $this->assertIsSubject( NS_MEDIA ); |
| 46 | + $this->assertIsSubject( NS_SPECIAL ); |
47 | 47 | |
48 | 48 | // Subject pages |
49 | | - $this->assertTrue( MWNamespace::isSubject( NS_MAIN ) ); |
50 | | - $this->assertTrue( MWNamespace::isSubject( NS_USER ) ); |
51 | | - $this->assertTrue( MWNamespace::isSubject( 100 ) ); # user defined |
| 49 | + $this->assertIsSubject( NS_MAIN ); |
| 50 | + $this->assertIsSubject( NS_USER ); |
| 51 | + $this->assertIsSubject( 100 ); # user defined |
52 | 52 | |
53 | 53 | // Talk pages |
54 | | - $this->assertFalse( MWNamespace::isSubject( NS_TALK ) ); |
55 | | - $this->assertFalse( MWNamespace::isSubject( NS_USER_TALK ) ); |
56 | | - $this->assertFalse( MWNamespace::isSubject( 101 ) ); # user defined |
| 54 | + $this->assertIsNotSubject( NS_TALK ); |
| 55 | + $this->assertIsNotSubject( NS_USER_TALK ); |
| 56 | + $this->assertIsNotSubject( 101 ); # user defined |
57 | 57 | |
58 | 58 | // Back compat |
59 | 59 | $this->assertTrue( MWNamespace::isMain( NS_MAIN ) == MWNamespace::isSubject( NS_MAIN ) ); |
— | — | @@ -65,18 +65,18 @@ |
66 | 66 | */ |
67 | 67 | public function testIsTalk() { |
68 | 68 | // Special namespaces |
69 | | - $this->assertFalse( MWNamespace::isTalk( NS_MEDIA ) ); |
70 | | - $this->assertFalse( MWNamespace::isTalk( NS_SPECIAL ) ); |
| 69 | + $this->assertIsNotTalk( NS_MEDIA ); |
| 70 | + $this->assertIsNotTalk( NS_SPECIAL ); |
71 | 71 | |
72 | 72 | // Subject pages |
73 | | - $this->assertFalse( MWNamespace::isTalk( NS_MAIN ) ); |
74 | | - $this->assertFalse( MWNamespace::isTalk( NS_USER ) ); |
75 | | - $this->assertFalse( MWNamespace::isTalk( 100 ) ); # user defined |
| 73 | + $this->assertIsNotTalk( NS_MAIN ); |
| 74 | + $this->assertIsNotTalk( NS_USER ); |
| 75 | + $this->assertIsNotTalk( 100 ); # user defined |
76 | 76 | |
77 | 77 | // Talk pages |
78 | | - $this->assertTrue( MWNamespace::isTalk( NS_TALK ) ); |
79 | | - $this->assertTrue( MWNamespace::isTalk( NS_USER_TALK ) ); |
80 | | - $this->assertTrue( MWNamespace::isTalk( 101 ) ); # user defined |
| 78 | + $this->assertIsTalk( NS_TALK ); |
| 79 | + $this->assertIsTalk( NS_USER_TALK ); |
| 80 | + $this->assertIsTalk( 101 ); # user defined |
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
— | — | @@ -111,7 +111,7 @@ |
112 | 112 | $this->assertNull( MWNamespace::getTalk( NS_MEDIA ) ); |
113 | 113 | } |
114 | 114 | |
115 | | - /** |
| 115 | + /** |
116 | 116 | * Exceptions with getTalk() |
117 | 117 | * NS_SPECIAL does not have talk pages. MediaWiki raise an exception for them. |
118 | 118 | * @expectedException MWException |
— | — | @@ -240,17 +240,17 @@ |
241 | 241 | /** |
242 | 242 | */ |
243 | 243 | public function testCanTalk() { |
244 | | - $this->assertFalse( MWNamespace::canTalk( NS_MEDIA ) ); |
245 | | - $this->assertFalse( MWNamespace::canTalk( NS_SPECIAL ) ); |
| 244 | + $this->assertCanNotTalk( NS_MEDIA ); |
| 245 | + $this->assertCanNotTalk( NS_SPECIAL ); |
246 | 246 | |
247 | | - $this->assertTrue( MWNamespace::canTalk( NS_MAIN ) ); |
248 | | - $this->assertTrue( MWNamespace::canTalk( NS_TALK ) ); |
249 | | - $this->assertTrue( MWNamespace::canTalk( NS_USER ) ); |
250 | | - $this->assertTrue( MWNamespace::canTalk( NS_USER_TALK ) ); |
| 247 | + $this->assertCanTalk( NS_MAIN ); |
| 248 | + $this->assertCanTalk( NS_TALK ); |
| 249 | + $this->assertCanTalk( NS_USER ); |
| 250 | + $this->assertCanTalk( NS_USER_TALK ); |
251 | 251 | |
252 | 252 | // User defined namespaces |
253 | | - $this->assertTrue( MWNamespace::canTalk( 100 ) ); |
254 | | - $this->assertTrue( MWNamespace::canTalk( 101 ) ); |
| 253 | + $this->assertCanTalk( 100 ); |
| 254 | + $this->assertCanTalk( 101 ); |
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
— | — | @@ -258,45 +258,45 @@ |
259 | 259 | public function testIsContent() { |
260 | 260 | // NS_MAIN is a content namespace per DefaultSettings.php |
261 | 261 | // and per function definition. |
262 | | - $this->assertTrue( MWNamespace::isContent( NS_MAIN ) ); |
| 262 | + $this->assertIsContent( NS_MAIN ); |
263 | 263 | |
264 | 264 | global $wgContentNamespaces; |
265 | 265 | |
266 | 266 | $saved = $wgContentNamespaces; |
267 | 267 | |
268 | 268 | $wgContentNamespaces[] = NS_MAIN; |
269 | | - $this->assertTrue( MWNamespace::isContent( NS_MAIN ) ); |
| 269 | + $this->assertIsContent( NS_MAIN ); |
270 | 270 | |
271 | 271 | // Other namespaces which are not expected to be content |
272 | 272 | if ( isset( $wgContentNamespaces[NS_MEDIA] ) ) { |
273 | 273 | unset( $wgContentNamespaces[NS_MEDIA] ); |
274 | 274 | } |
275 | | - $this->assertFalse( MWNamespace::isContent( NS_MEDIA ) ); |
| 275 | + $this->assertIsNotContent( NS_MEDIA ); |
276 | 276 | |
277 | 277 | if ( isset( $wgContentNamespaces[NS_SPECIAL] ) ) { |
278 | 278 | unset( $wgContentNamespaces[NS_SPECIAL] ); |
279 | 279 | } |
280 | | - $this->assertFalse( MWNamespace::isContent( NS_SPECIAL ) ); |
| 280 | + $this->assertIsNotContent( NS_SPECIAL ); |
281 | 281 | |
282 | 282 | if ( isset( $wgContentNamespaces[NS_TALK] ) ) { |
283 | 283 | unset( $wgContentNamespaces[NS_TALK] ); |
284 | 284 | } |
285 | | - $this->assertFalse( MWNamespace::isContent( NS_TALK ) ); |
| 285 | + $this->assertIsNotContent( NS_TALK ); |
286 | 286 | |
287 | 287 | if ( isset( $wgContentNamespaces[NS_USER] ) ) { |
288 | 288 | unset( $wgContentNamespaces[NS_USER] ); |
289 | 289 | } |
290 | | - $this->assertFalse( MWNamespace::isContent( NS_USER ) ); |
| 290 | + $this->assertIsNotContent( NS_USER ); |
291 | 291 | |
292 | 292 | if ( isset( $wgContentNamespaces[NS_CATEGORY] ) ) { |
293 | 293 | unset( $wgContentNamespaces[NS_CATEGORY] ); |
294 | 294 | } |
295 | | - $this->assertFalse( MWNamespace::isContent( NS_CATEGORY ) ); |
| 295 | + $this->assertIsNotContent( NS_CATEGORY ); |
296 | 296 | |
297 | 297 | if ( isset( $wgContentNamespaces[100] ) ) { |
298 | 298 | unset( $wgContentNamespaces[100] ); |
299 | 299 | } |
300 | | - $this->assertFalse( MWNamespace::isContent( 100 ) ); |
| 300 | + $this->assertIsNotContent( 100 ); |
301 | 301 | |
302 | 302 | $wgContentNamespaces = $saved; |
303 | 303 | } |
— | — | @@ -308,47 +308,47 @@ |
309 | 309 | public function testIsContentWithAdditionsInWgContentNamespaces() { |
310 | 310 | // NS_MAIN is a content namespace per DefaultSettings.php |
311 | 311 | // and per function definition. |
312 | | - $this->assertTrue( MWNamespace::isContent( NS_MAIN ) ); |
| 312 | + $this->assertIsContent( NS_MAIN ); |
313 | 313 | |
314 | 314 | // Tests that user defined namespace #252 is not content: |
315 | | - $this->assertFalse( MWNamespace::isContent( 252 ) ); |
| 315 | + $this->assertIsNotContent( 252 ); |
316 | 316 | |
317 | 317 | # @todo FIXME: Is global saving really required for PHPUnit? |
318 | 318 | // Bless namespace # 252 as a content namespace |
319 | 319 | global $wgContentNamespaces; |
320 | 320 | $savedGlobal = $wgContentNamespaces; |
321 | 321 | $wgContentNamespaces[] = 252; |
322 | | - $this->assertTrue( MWNamespace::isContent( 252 ) ); |
| 322 | + $this->assertIsContent( 252 ); |
323 | 323 | |
324 | 324 | // Makes sure NS_MAIN was not impacted |
325 | | - $this->assertTrue( MWNamespace::isContent( NS_MAIN ) ); |
| 325 | + $this->assertIsContent( NS_MAIN ); |
326 | 326 | |
327 | 327 | // Restore global |
328 | 328 | $wgContentNamespaces = $savedGlobal; |
329 | 329 | |
330 | 330 | // Verify namespaces after global restauration |
331 | | - $this->assertTrue( MWNamespace::isContent( NS_MAIN ) ); |
332 | | - $this->assertFalse( MWNamespace::isContent( 252 ) ); |
| 331 | + $this->assertIsContent( NS_MAIN ); |
| 332 | + $this->assertIsNotContent( 252 ); |
333 | 333 | } |
334 | 334 | |
335 | 335 | public function testIsWatchable() { |
336 | 336 | // Specials namespaces are not watchable |
337 | | - $this->assertFalse( MWNamespace::isWatchable( NS_MEDIA ) ); |
338 | | - $this->assertFalse( MWNamespace::isWatchable( NS_SPECIAL ) ); |
| 337 | + $this->assertIsNotWatchable( NS_MEDIA ); |
| 338 | + $this->assertIsNotWatchable( NS_SPECIAL ); |
339 | 339 | |
340 | 340 | // Core defined namespaces are watchables |
341 | | - $this->assertTrue( MWNamespace::isWatchable( NS_MAIN ) ); |
342 | | - $this->assertTrue( MWNamespace::isWatchable( NS_TALK ) ); |
| 341 | + $this->assertIsWatchable( NS_MAIN ); |
| 342 | + $this->assertIsWatchable( NS_TALK ); |
343 | 343 | |
344 | 344 | // Additional, user defined namespaces are watchables |
345 | | - $this->assertTrue( MWNamespace::isWatchable( 100 ) ); |
346 | | - $this->assertTrue( MWNamespace::isWatchable( 101 ) ); |
| 345 | + $this->assertIsWatchable( 100 ); |
| 346 | + $this->assertIsWatchable( 101 ); |
347 | 347 | } |
348 | 348 | |
349 | 349 | public function testHasSubpages() { |
350 | 350 | // Special namespaces: |
351 | | - $this->assertFalse( MWNamespace::hasSubpages( NS_MEDIA ) ); |
352 | | - $this->assertFalse( MWNamespace::hasSubpages( NS_SPECIAL ) ); |
| 351 | + $this->assertHasNotSubpages( NS_MEDIA ); |
| 352 | + $this->assertHasNotSubpages( NS_SPECIAL ); |
353 | 353 | |
354 | 354 | // namespaces without subpages |
355 | 355 | # save up global |
— | — | @@ -359,12 +359,12 @@ |
360 | 360 | unset( $wgNamespacesWithSubpages[NS_MAIN] ); |
361 | 361 | } |
362 | 362 | |
363 | | - $this->assertFalse( MWNamespace::hasSubpages( NS_MAIN ) ); |
| 363 | + $this->assertHasNotSubpages( NS_MAIN ); |
364 | 364 | |
365 | 365 | $wgNamespacesWithSubpages[NS_MAIN] = true; |
366 | | - $this->assertTrue( MWNamespace::hasSubpages( NS_MAIN ) ); |
| 366 | + $this->assertHasSubpages( NS_MAIN ); |
367 | 367 | $wgNamespacesWithSubpages[NS_MAIN] = false; |
368 | | - $this->assertFalse( MWNamespace::hasSubpages( NS_MAIN ) ); |
| 368 | + $this->assertHasNotSubpages( NS_MAIN ); |
369 | 369 | |
370 | 370 | # restore global |
371 | 371 | if( $saved !== null ) { |
— | — | @@ -372,9 +372,9 @@ |
373 | 373 | } |
374 | 374 | |
375 | 375 | // Some namespaces with subpages |
376 | | - $this->assertTrue( MWNamespace::hasSubpages( NS_TALK ) ); |
377 | | - $this->assertTrue( MWNamespace::hasSubpages( NS_USER ) ); |
378 | | - $this->assertTrue( MWNamespace::hasSubpages( NS_USER_TALK ) ); |
| 376 | + $this->assertHasSubpages( NS_TALK ); |
| 377 | + $this->assertHasSubpages( NS_USER ); |
| 378 | + $this->assertHasSubpages( NS_USER_TALK ); |
379 | 379 | } |
380 | 380 | |
381 | 381 | /** |
— | — | @@ -440,14 +440,14 @@ |
441 | 441 | ); |
442 | 442 | |
443 | 443 | // Boths are capitalized by default |
444 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_MEDIA ) ); |
445 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_FILE ) ); |
| 444 | + $this->assertIsCapitalized( NS_MEDIA ); |
| 445 | + $this->assertIsCapitalized( NS_FILE ); |
446 | 446 | |
447 | 447 | // Always capitalized namespaces |
448 | 448 | // @see MWNamespace::$alwaysCapitalizedNamespaces |
449 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_SPECIAL ) ); |
450 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_USER ) ); |
451 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_MEDIAWIKI ) ); |
| 449 | + $this->assertIsCapitalized( NS_SPECIAL ); |
| 450 | + $this->assertIsCapitalized( NS_USER ); |
| 451 | + $this->assertIsCapitalized( NS_MEDIAWIKI ); |
452 | 452 | } |
453 | 453 | |
454 | 454 | /** |
— | — | @@ -468,17 +468,17 @@ |
469 | 469 | $savedGlobal = $wgCapitalLinks; |
470 | 470 | |
471 | 471 | $wgCapitalLinks = true; |
472 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_PROJECT ) ); |
473 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_PROJECT_TALK ) ); |
| 472 | + $this->assertIsCapitalized( NS_PROJECT ); |
| 473 | + $this->assertIsCapitalized( NS_PROJECT_TALK ); |
474 | 474 | |
475 | 475 | $wgCapitalLinks = false; |
476 | 476 | // hardcoded namespaces (see above function) are still capitalized: |
477 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_SPECIAL ) ); |
478 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_USER ) ); |
479 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_MEDIAWIKI ) ); |
| 477 | + $this->assertIsCapitalized( NS_SPECIAL ); |
| 478 | + $this->assertIsCapitalized( NS_USER ); |
| 479 | + $this->assertIsCapitalized( NS_MEDIAWIKI ); |
480 | 480 | // setting is correctly applied |
481 | | - $this->assertFalse( MWNamespace::isCapitalized( NS_PROJECT ) ); |
482 | | - $this->assertFalse( MWNamespace::isCapitalized( NS_PROJECT_TALK ) ); |
| 481 | + $this->assertIsNotCapitalized( NS_PROJECT ); |
| 482 | + $this->assertIsNotCapitalized( NS_PROJECT_TALK ); |
483 | 483 | |
484 | 484 | // reset global state: |
485 | 485 | $wgCapitalLinks = $savedGlobal; |
— | — | @@ -496,28 +496,28 @@ |
497 | 497 | $savedGlobal = $wgCapitalLinkOverrides; |
498 | 498 | |
499 | 499 | // Test default settings |
500 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_PROJECT ) ); |
501 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_PROJECT_TALK ) ); |
| 500 | + $this->assertIsCapitalized( NS_PROJECT ); |
| 501 | + $this->assertIsCapitalized( NS_PROJECT_TALK ); |
502 | 502 | // hardcoded namespaces (see above function) are capitalized: |
503 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_SPECIAL ) ); |
504 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_USER ) ); |
505 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_MEDIAWIKI ) ); |
| 503 | + $this->assertIsCapitalized( NS_SPECIAL ); |
| 504 | + $this->assertIsCapitalized( NS_USER ); |
| 505 | + $this->assertIsCapitalized( NS_MEDIAWIKI ); |
506 | 506 | |
507 | 507 | // Hardcoded namespaces remains capitalized |
508 | 508 | $wgCapitalLinkOverrides[NS_SPECIAL] = false; |
509 | 509 | $wgCapitalLinkOverrides[NS_USER] = false; |
510 | 510 | $wgCapitalLinkOverrides[NS_MEDIAWIKI] = false; |
511 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_SPECIAL ) ); |
512 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_USER ) ); |
513 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_MEDIAWIKI ) ); |
| 511 | + $this->assertIsCapitalized( NS_SPECIAL ); |
| 512 | + $this->assertIsCapitalized( NS_USER ); |
| 513 | + $this->assertIsCapitalized( NS_MEDIAWIKI ); |
514 | 514 | |
515 | 515 | $wgCapitalLinkOverrides = $savedGlobal; |
516 | 516 | $wgCapitalLinkOverrides[NS_PROJECT] = false; |
517 | | - $this->assertFalse( MWNamespace::isCapitalized( NS_PROJECT ) ); |
| 517 | + $this->assertIsNotCapitalized( NS_PROJECT ); |
518 | 518 | $wgCapitalLinkOverrides[NS_PROJECT] = true ; |
519 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_PROJECT ) ); |
| 519 | + $this->assertIsCapitalized( NS_PROJECT ); |
520 | 520 | unset( $wgCapitalLinkOverrides[NS_PROJECT] ); |
521 | | - $this->assertTrue( MWNamespace::isCapitalized( NS_PROJECT ) ); |
| 521 | + $this->assertIsCapitalized( NS_PROJECT ); |
522 | 522 | |
523 | 523 | // reset global state: |
524 | 524 | $wgCapitalLinkOverrides = $savedGlobal; |
— | — | @@ -543,13 +543,17 @@ |
544 | 544 | return $this->$method( $args ); |
545 | 545 | } |
546 | 546 | |
547 | | - if( preg_match( '/^assert(Has|Is)(Not|)(Subject|Talk)$/', $method, $m ) ) { |
| 547 | + if( preg_match( '/^assert(Has|Is|Can)(Not|)(Subject|Talk|Watchable|Content|Subpages|Capitalized)$/', $method, $m ) ) { |
548 | 548 | # Interprets arguments: |
549 | 549 | $ns = $args[0]; |
550 | 550 | $msg = isset($args[1]) ? $args[1] : " dummy message"; |
551 | 551 | |
552 | 552 | # Forge the namespace constant name: |
553 | | - $ns_name = "NS_" . strtoupper( MWNamespace::getCanonicalName( $ns ) ); |
| 553 | + if( $ns === 0 ) { |
| 554 | + $ns_name = "NS_MAIN"; |
| 555 | + } else { |
| 556 | + $ns_name = "NS_" . strtoupper( MWNamespace::getCanonicalName( $ns ) ); |
| 557 | + } |
554 | 558 | # ... and the MWNamespace method name |
555 | 559 | $nsMethod = strtolower( $m[1] ) . $m[3]; |
556 | 560 | |