Add tests for User::getCanonicalName()
authorumherirrender <umherirrender_de.wp@web.de>
Mon, 25 Aug 2014 18:24:10 +0000 (20:24 +0200)
committerUmherirrender <umherirrender_de.wp@web.de>
Fri, 5 Sep 2014 13:46:00 +0000 (13:46 +0000)
Change-Id: I00097a4706c4ada41a5697470b550c925ae6051d

tests/phpunit/includes/UserTest.php

index 36de114..cabbf10 100644 (file)
@@ -323,4 +323,35 @@ class UserTest extends MediaWikiTestCase {
                $this->assertFalse( $user->checkPasswordValidity( 'Passpass' )->isGood() );
                $this->assertEquals( 'password-login-forbidden', $user->getPasswordValidity( 'Passpass' ) );
        }
+
+       /**
+        * @covers User::getCanonicalName()
+        * @dataProvider provideGetCanonicalName
+        */
+       public function testGetCanonicalName( $name, $expectedArray, $msg ) {
+               foreach ( $expectedArray as $validate => $expected ) {
+                       $this->assertEquals(
+                               User::getCanonicalName( $name, $validate === 'false' ? false : $validate ),
+                               $expected,
+                               $msg . ' (' . $validate . ')'
+                       );
+               }
+       }
+
+       public function provideGetCanonicalName() {
+               return array(
+                       array( ' trailing space ', array( 'creatable' => 'Trailing space' ), 'Trailing spaces' ),
+                       // @todo FIXME: Maybe the createable name should be 'Talk:Username' or false to reject?
+                       array( 'Talk:Username', array( 'creatable' => 'Username', 'usable' => 'Username',
+                               'valid' => 'Username', 'false' => 'Talk:Username' ), 'Namespace prefix' ),
+                       array( ' name with # hash', array( 'creatable' => false, 'usable' => false ), 'With hash' ),
+                       array( 'Multi  spaces', array( 'creatable' => 'Multi spaces',
+                               'usable' => 'Multi spaces' ), 'Multi spaces' ),
+                       array( 'lowercase', array( 'creatable' => 'Lowercase' ), 'Lowercase' ),
+                       array( 'in[]valid', array( 'creatable' => false, 'usable' => false, 'valid' => false,
+                               'false' => 'In[]valid' ), 'Invalid' ),
+                       array( 'with / slash', array( 'creatable' => false, 'usable' => false, 'valid' => false,
+                               'false' => 'With / slash' ), 'With slash' ),
+               );
+       }
 }