Make BatchRowUpdateTest compatible with PHPUnit 6
[lhc/web/wiklou.git] / tests / phpunit / includes / MWNamespaceTest.php
index 91101bd..15e2def 100644 (file)
@@ -5,11 +5,8 @@
  * @file
  */
 
-/**
- * Test class for MWNamespace.
- * @todo FIXME: this test file is a mess
- */
 class MWNamespaceTest extends MediaWikiTestCase {
+
        protected function setUp() {
                parent::setUp();
 
@@ -26,15 +23,20 @@ class MWNamespaceTest extends MediaWikiTestCase {
                ] );
        }
 
-# ### START OF TESTS #########################################################
-
        /**
         * @todo Write more texts, handle $wgAllowImageMoving setting
         * @covers MWNamespace::isMovable
         */
        public function testIsMovable() {
                $this->assertFalse( MWNamespace::isMovable( NS_SPECIAL ) );
-               # @todo FIXME: Write more tests!!
+       }
+
+       private function assertIsSubject( $ns ) {
+               $this->assertTrue( MWNamespace::isSubject( $ns ) );
+       }
+
+       private function assertIsNotSubject( $ns ) {
+               $this->assertFalse( MWNamespace::isSubject( $ns ) );
        }
 
        /**
@@ -57,6 +59,14 @@ class MWNamespaceTest extends MediaWikiTestCase {
                $this->assertIsNotSubject( 101 ); # user defined
        }
 
+       private function assertIsTalk( $ns ) {
+               $this->assertTrue( MWNamespace::isTalk( $ns ) );
+       }
+
+       private function assertIsNotTalk( $ns ) {
+               $this->assertFalse( MWNamespace::isTalk( $ns ) );
+       }
+
        /**
         * Reverse of testIsSubject().
         * Please update testIsSubject() if you change assertions below
@@ -153,18 +163,6 @@ class MWNamespaceTest extends MediaWikiTestCase {
                $this->assertNull( MWNamespace::getAssociated( NS_SPECIAL ) );
        }
 
-       /**
-        * @todo Implement testExists().
-        */
-       /*
-       public function testExists() {
-               // Remove the following lines when you implement this test.
-               $this->markTestIncomplete(
-                       'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.'
-               );
-       }
-       */
-
        /**
         * Test MWNamespace::equals
         * Note if we add a namespace registration system with keys like 'MAIN'
@@ -215,52 +213,6 @@ class MWNamespaceTest extends MediaWikiTestCase {
                );
        }
 
-       /**
-        * @todo Implement testGetCanonicalNamespaces().
-        */
-       /*
-       public function testGetCanonicalNamespaces() {
-               // Remove the following lines when you implement this test.
-               $this->markTestIncomplete(
-                       'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.'
-               );
-       }
-       */
-       /**
-        * @todo Implement testGetCanonicalName().
-        */
-       /*
-               public function testGetCanonicalName() {
-                       // Remove the following lines when you implement this test.
-                       $this->markTestIncomplete(
-                               'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.'
-                       );
-               }
-       */
-       /**
-        * @todo Implement testGetCanonicalIndex().
-        */
-       /*
-       public function testGetCanonicalIndex() {
-               // Remove the following lines when you implement this test.
-               $this->markTestIncomplete(
-                       'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.'
-               );
-       }
-       */
-
-       /**
-        * @todo Implement testGetValidNamespaces().
-        */
-       /*
-       public function testGetValidNamespaces() {
-               // Remove the following lines when you implement this test.
-               $this->markTestIncomplete(
-                       'This test has not been implemented yet. Rely on $wgCanonicalNamespaces.'
-               );
-       }
-       */
-
        public function provideHasTalkNamespace() {
                return [
                        [ NS_MEDIA, false ],
@@ -300,6 +252,14 @@ class MWNamespaceTest extends MediaWikiTestCase {
                $this->assertSame( $actual, $expected, "NS $index" );
        }
 
+       private function assertIsContent( $ns ) {
+               $this->assertTrue( MWNamespace::isContent( $ns ) );
+       }
+
+       private function assertIsNotContent( $ns ) {
+               $this->assertFalse( MWNamespace::isContent( $ns ) );
+       }
+
        /**
         * @covers MWNamespace::isContent
         */
@@ -339,6 +299,14 @@ class MWNamespaceTest extends MediaWikiTestCase {
                $this->assertIsContent( NS_MAIN );
        }
 
+       private function assertIsWatchable( $ns ) {
+               $this->assertTrue( MWNamespace::isWatchable( $ns ) );
+       }
+
+       private function assertIsNotWatchable( $ns ) {
+               $this->assertFalse( MWNamespace::isWatchable( $ns ) );
+       }
+
        /**
         * @covers MWNamespace::isWatchable
         */
@@ -356,6 +324,14 @@ class MWNamespaceTest extends MediaWikiTestCase {
                $this->assertIsWatchable( 101 );
        }
 
+       private function assertHasSubpages( $ns ) {
+               $this->assertTrue( MWNamespace::hasSubpages( $ns ) );
+       }
+
+       private function assertHasNotSubpages( $ns ) {
+               $this->assertFalse( MWNamespace::hasSubpages( $ns ) );
+       }
+
        /**
         * @covers MWNamespace::hasSubpages
         */
@@ -464,6 +440,14 @@ class MWNamespaceTest extends MediaWikiTestCase {
                        "Subject namespaces should not have NS_SPECIAL" );
        }
 
+       private function assertIsCapitalized( $ns ) {
+               $this->assertTrue( MWNamespace::isCapitalized( $ns ) );
+       }
+
+       private function assertIsNotCapitalized( $ns ) {
+               $this->assertFalse( MWNamespace::isCapitalized( $ns ) );
+       }
+
        /**
         * Some namespaces are always capitalized per code definition
         * in MWNamespace::$alwaysCapitalizedNamespaces
@@ -584,48 +568,11 @@ class MWNamespaceTest extends MediaWikiTestCase {
                $this->assertFalse( MWNamespace::isNonincludable( NS_TEMPLATE ) );
        }
 
-       # ###### HELPERS ###########################################################
-       function __call( $method, $args ) {
-               // Call the real method if it exists
-               if ( method_exists( $this, $method ) ) {
-                       return $this->$method( $args );
-               }
-
-               if ( preg_match(
-                       '/^assert(Has|Is|Can)(Not|)(Subject|Talk|Watchable|Content|Subpages|Capitalized)$/',
-                       $method,
-                       $m
-               ) ) {
-                       # Interprets arguments:
-                       $ns = $args[0];
-                       $msg = isset( $args[1] ) ? $args[1] : " dummy message";
-
-                       # Forge the namespace constant name:
-                       if ( $ns === 0 ) {
-                               $ns_name = "NS_MAIN";
-                       } else {
-                               $ns_name = "NS_" . strtoupper( MWNamespace::getCanonicalName( $ns ) );
-                       }
-                       # ... and the MWNamespace method name
-                       $nsMethod = strtolower( $m[1] ) . $m[3];
-
-                       $expect = ( $m[2] === '' );
-                       $expect_name = $expect ? 'TRUE' : 'FALSE';
-
-                       return $this->assertEquals( $expect,
-                               MWNamespace::$nsMethod( $ns, $msg ),
-                               "MWNamespace::$nsMethod( $ns_name ) should returns $expect_name"
-                       );
-               }
-
-               throw new Exception( __METHOD__ . " could not find a method named $method\n" );
-       }
-
-       function assertSameSubject( $ns1, $ns2, $msg = '' ) {
-               $this->assertTrue( MWNamespace::subjectEquals( $ns1, $ns2, $msg ) );
+       private function assertSameSubject( $ns1, $ns2, $msg = '' ) {
+               $this->assertTrue( MWNamespace::subjectEquals( $ns1, $ns2 ), $msg );
        }
 
-       function assertDifferentSubject( $ns1, $ns2, $msg = '' ) {
-               $this->assertFalse( MWNamespace::subjectEquals( $ns1, $ns2, $msg ) );
+       private function assertDifferentSubject( $ns1, $ns2, $msg = '' ) {
+               $this->assertFalse( MWNamespace::subjectEquals( $ns1, $ns2 ), $msg );
        }
 }