X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FMWNamespaceTest.php;h=1b91a87fb75a47d65d05f2d65c8163a8fb4b5222;hp=f705537d7580dea5382a139fccf35ae9916a952d;hb=733704ed8248f71dfb982d22799104a976d1ada4;hpb=6f7e982df6479e27c3b17f2deda8404ef55f50e6 diff --git a/tests/phpunit/includes/MWNamespaceTest.php b/tests/phpunit/includes/MWNamespaceTest.php index f705537d75..1b91a87fb7 100644 --- a/tests/phpunit/includes/MWNamespaceTest.php +++ b/tests/phpunit/includes/MWNamespaceTest.php @@ -31,6 +31,14 @@ class MWNamespaceTest extends MediaWikiTestCase { $this->assertFalse( MWNamespace::isMovable( NS_SPECIAL ) ); } + private function assertIsSubject( $ns ) { + $this->assertTrue( MWNamespace::isSubject( $ns ) ); + } + + private function assertIsNotSubject( $ns ) { + $this->assertFalse( MWNamespace::isSubject( $ns ) ); + } + /** * Please make sure to change testIsTalk() if you change the assertions below * @covers MWNamespace::isSubject @@ -51,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 @@ -236,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 */ @@ -275,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 */ @@ -292,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 */ @@ -400,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 @@ -520,48 +568,41 @@ 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"; + private function assertSameSubject( $ns1, $ns2, $msg = '' ) { + $this->assertTrue( MWNamespace::subjectEquals( $ns1, $ns2 ), $msg ); + } - # 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]; + private function assertDifferentSubject( $ns1, $ns2, $msg = '' ) { + $this->assertFalse( MWNamespace::subjectEquals( $ns1, $ns2 ), $msg ); + } - $expect = ( $m[2] === '' ); - $expect_name = $expect ? 'TRUE' : 'FALSE'; + public function provideGetCategoryLinkType() { + return [ + [ NS_MAIN, 'page' ], + [ NS_TALK, 'page' ], + [ NS_USER, 'page' ], + [ NS_USER_TALK, 'page' ], - return $this->assertEquals( $expect, - MWNamespace::$nsMethod( $ns, $msg ), - "MWNamespace::$nsMethod( $ns_name ) should returns $expect_name" - ); - } + [ NS_FILE, 'file' ], + [ NS_FILE_TALK, 'page' ], - throw new Exception( __METHOD__ . " could not find a method named $method\n" ); - } + [ NS_CATEGORY, 'subcat' ], + [ NS_CATEGORY_TALK, 'page' ], - function assertSameSubject( $ns1, $ns2, $msg = '' ) { - $this->assertTrue( MWNamespace::subjectEquals( $ns1, $ns2, $msg ) ); + [ 100, 'page' ], + [ 101, 'page' ], + ]; } - function assertDifferentSubject( $ns1, $ns2, $msg = '' ) { - $this->assertFalse( MWNamespace::subjectEquals( $ns1, $ns2, $msg ) ); + /** + * @dataProvider provideGetCategoryLinkType + * @covers MWNamespace::getCategoryLinkType + * + * @param int $index + * @param string $expected + */ + public function testGetCategoryLinkType( $index, $expected ) { + $actual = MWNamespace::getCategoryLinkType( $index ); + $this->assertSame( $expected, $actual, "NS $index" ); } }