r105889 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105888‎ | r105889 | r105890 >
Date:15:26, 12 December 2011
Author:hashar
Status:ok (Comments)
Tags:
Comment:
use MWNamespaceTest helpers based on __call()

* Added some new methos such as Watchable/Subpages/Capitalized/Content
* Fixed namespace 0 being converted to NS_ , now show NS_MAIN
* Converted all assertion calls to use the __call() hack

Follow up r105883
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/MWNamespaceTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/MWNamespaceTest.php
@@ -41,18 +41,18 @@
4242 */
4343 public function testIsSubject() {
4444 // 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 );
4747
4848 // 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
5252
5353 // 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
5757
5858 // Back compat
5959 $this->assertTrue( MWNamespace::isMain( NS_MAIN ) == MWNamespace::isSubject( NS_MAIN ) );
@@ -65,18 +65,18 @@
6666 */
6767 public function testIsTalk() {
6868 // 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 );
7171
7272 // 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
7676
7777 // 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
8181 }
8282
8383 /**
@@ -111,7 +111,7 @@
112112 $this->assertNull( MWNamespace::getTalk( NS_MEDIA ) );
113113 }
114114
115 - /**
 115+ /**
116116 * Exceptions with getTalk()
117117 * NS_SPECIAL does not have talk pages. MediaWiki raise an exception for them.
118118 * @expectedException MWException
@@ -240,17 +240,17 @@
241241 /**
242242 */
243243 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 );
246246
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 );
251251
252252 // User defined namespaces
253 - $this->assertTrue( MWNamespace::canTalk( 100 ) );
254 - $this->assertTrue( MWNamespace::canTalk( 101 ) );
 253+ $this->assertCanTalk( 100 );
 254+ $this->assertCanTalk( 101 );
255255 }
256256
257257 /**
@@ -258,45 +258,45 @@
259259 public function testIsContent() {
260260 // NS_MAIN is a content namespace per DefaultSettings.php
261261 // and per function definition.
262 - $this->assertTrue( MWNamespace::isContent( NS_MAIN ) );
 262+ $this->assertIsContent( NS_MAIN );
263263
264264 global $wgContentNamespaces;
265265
266266 $saved = $wgContentNamespaces;
267267
268268 $wgContentNamespaces[] = NS_MAIN;
269 - $this->assertTrue( MWNamespace::isContent( NS_MAIN ) );
 269+ $this->assertIsContent( NS_MAIN );
270270
271271 // Other namespaces which are not expected to be content
272272 if ( isset( $wgContentNamespaces[NS_MEDIA] ) ) {
273273 unset( $wgContentNamespaces[NS_MEDIA] );
274274 }
275 - $this->assertFalse( MWNamespace::isContent( NS_MEDIA ) );
 275+ $this->assertIsNotContent( NS_MEDIA );
276276
277277 if ( isset( $wgContentNamespaces[NS_SPECIAL] ) ) {
278278 unset( $wgContentNamespaces[NS_SPECIAL] );
279279 }
280 - $this->assertFalse( MWNamespace::isContent( NS_SPECIAL ) );
 280+ $this->assertIsNotContent( NS_SPECIAL );
281281
282282 if ( isset( $wgContentNamespaces[NS_TALK] ) ) {
283283 unset( $wgContentNamespaces[NS_TALK] );
284284 }
285 - $this->assertFalse( MWNamespace::isContent( NS_TALK ) );
 285+ $this->assertIsNotContent( NS_TALK );
286286
287287 if ( isset( $wgContentNamespaces[NS_USER] ) ) {
288288 unset( $wgContentNamespaces[NS_USER] );
289289 }
290 - $this->assertFalse( MWNamespace::isContent( NS_USER ) );
 290+ $this->assertIsNotContent( NS_USER );
291291
292292 if ( isset( $wgContentNamespaces[NS_CATEGORY] ) ) {
293293 unset( $wgContentNamespaces[NS_CATEGORY] );
294294 }
295 - $this->assertFalse( MWNamespace::isContent( NS_CATEGORY ) );
 295+ $this->assertIsNotContent( NS_CATEGORY );
296296
297297 if ( isset( $wgContentNamespaces[100] ) ) {
298298 unset( $wgContentNamespaces[100] );
299299 }
300 - $this->assertFalse( MWNamespace::isContent( 100 ) );
 300+ $this->assertIsNotContent( 100 );
301301
302302 $wgContentNamespaces = $saved;
303303 }
@@ -308,47 +308,47 @@
309309 public function testIsContentWithAdditionsInWgContentNamespaces() {
310310 // NS_MAIN is a content namespace per DefaultSettings.php
311311 // and per function definition.
312 - $this->assertTrue( MWNamespace::isContent( NS_MAIN ) );
 312+ $this->assertIsContent( NS_MAIN );
313313
314314 // Tests that user defined namespace #252 is not content:
315 - $this->assertFalse( MWNamespace::isContent( 252 ) );
 315+ $this->assertIsNotContent( 252 );
316316
317317 # @todo FIXME: Is global saving really required for PHPUnit?
318318 // Bless namespace # 252 as a content namespace
319319 global $wgContentNamespaces;
320320 $savedGlobal = $wgContentNamespaces;
321321 $wgContentNamespaces[] = 252;
322 - $this->assertTrue( MWNamespace::isContent( 252 ) );
 322+ $this->assertIsContent( 252 );
323323
324324 // Makes sure NS_MAIN was not impacted
325 - $this->assertTrue( MWNamespace::isContent( NS_MAIN ) );
 325+ $this->assertIsContent( NS_MAIN );
326326
327327 // Restore global
328328 $wgContentNamespaces = $savedGlobal;
329329
330330 // 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 );
333333 }
334334
335335 public function testIsWatchable() {
336336 // 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 );
339339
340340 // 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 );
343343
344344 // 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 );
347347 }
348348
349349 public function testHasSubpages() {
350350 // 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 );
353353
354354 // namespaces without subpages
355355 # save up global
@@ -359,12 +359,12 @@
360360 unset( $wgNamespacesWithSubpages[NS_MAIN] );
361361 }
362362
363 - $this->assertFalse( MWNamespace::hasSubpages( NS_MAIN ) );
 363+ $this->assertHasNotSubpages( NS_MAIN );
364364
365365 $wgNamespacesWithSubpages[NS_MAIN] = true;
366 - $this->assertTrue( MWNamespace::hasSubpages( NS_MAIN ) );
 366+ $this->assertHasSubpages( NS_MAIN );
367367 $wgNamespacesWithSubpages[NS_MAIN] = false;
368 - $this->assertFalse( MWNamespace::hasSubpages( NS_MAIN ) );
 368+ $this->assertHasNotSubpages( NS_MAIN );
369369
370370 # restore global
371371 if( $saved !== null ) {
@@ -372,9 +372,9 @@
373373 }
374374
375375 // 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 );
379379 }
380380
381381 /**
@@ -440,14 +440,14 @@
441441 );
442442
443443 // 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 );
446446
447447 // Always capitalized namespaces
448448 // @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 );
452452 }
453453
454454 /**
@@ -468,17 +468,17 @@
469469 $savedGlobal = $wgCapitalLinks;
470470
471471 $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 );
474474
475475 $wgCapitalLinks = false;
476476 // 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 );
480480 // 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 );
483483
484484 // reset global state:
485485 $wgCapitalLinks = $savedGlobal;
@@ -496,28 +496,28 @@
497497 $savedGlobal = $wgCapitalLinkOverrides;
498498
499499 // 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 );
502502 // 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 );
506506
507507 // Hardcoded namespaces remains capitalized
508508 $wgCapitalLinkOverrides[NS_SPECIAL] = false;
509509 $wgCapitalLinkOverrides[NS_USER] = false;
510510 $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 );
514514
515515 $wgCapitalLinkOverrides = $savedGlobal;
516516 $wgCapitalLinkOverrides[NS_PROJECT] = false;
517 - $this->assertFalse( MWNamespace::isCapitalized( NS_PROJECT ) );
 517+ $this->assertIsNotCapitalized( NS_PROJECT );
518518 $wgCapitalLinkOverrides[NS_PROJECT] = true ;
519 - $this->assertTrue( MWNamespace::isCapitalized( NS_PROJECT ) );
 519+ $this->assertIsCapitalized( NS_PROJECT );
520520 unset( $wgCapitalLinkOverrides[NS_PROJECT] );
521 - $this->assertTrue( MWNamespace::isCapitalized( NS_PROJECT ) );
 521+ $this->assertIsCapitalized( NS_PROJECT );
522522
523523 // reset global state:
524524 $wgCapitalLinkOverrides = $savedGlobal;
@@ -543,13 +543,17 @@
544544 return $this->$method( $args );
545545 }
546546
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 ) ) {
548548 # Interprets arguments:
549549 $ns = $args[0];
550550 $msg = isset($args[1]) ? $args[1] : " dummy message";
551551
552552 # 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+ }
554558 # ... and the MWNamespace method name
555559 $nsMethod = strtolower( $m[1] ) . $m[3];
556560

Sign-offs

UserFlagDate
Nikerabbitinspected15:39, 12 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r105883use __call() to instantly have some new fresh helpers...hashar15:02, 12 December 2011

Comments

#Comment by 😂 (talk | contribs)   15:28, 12 December 2011

This should really be rewritten to use data providers.

Status & tagging log