From f3dbe5ba365dbdf05965eeb2a6ea8a92d92d9fed Mon Sep 17 00:00:00 2001 From: umherirrender Date: Mon, 25 Aug 2014 20:24:10 +0200 Subject: [PATCH] Add tests for User::getCanonicalName() Change-Id: I00097a4706c4ada41a5697470b550c925ae6051d --- tests/phpunit/includes/UserTest.php | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/phpunit/includes/UserTest.php b/tests/phpunit/includes/UserTest.php index 36de114ead..cabbf10fc0 100644 --- a/tests/phpunit/includes/UserTest.php +++ b/tests/phpunit/includes/UserTest.php @@ -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' ), + ); + } } -- 2.20.1