From: Timo Tijhof Date: Thu, 2 Apr 2015 01:15:50 +0000 (+0100) Subject: User: Add unit tests for getId, isAnon and isLoggedIn X-Git-Tag: 1.31.0-rc.0~11882 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmes_infos.php?a=commitdiff_plain;h=8b1d94082dd6cd756c3e31f2a5896b956cc5ff21;p=lhc%2Fweb%2Fwiklou.git User: Add unit tests for getId, isAnon and isLoggedIn Change-Id: Ie007d9da47df871f99ca19c4d7364f46f71c255b --- diff --git a/tests/phpunit/includes/UserTest.php b/tests/phpunit/includes/UserTest.php index 73e50518f8..b74a7eadc0 100644 --- a/tests/phpunit/includes/UserTest.php +++ b/tests/phpunit/includes/UserTest.php @@ -397,4 +397,32 @@ class UserTest extends MediaWikiTestCase { $sixth = User::newFromName( 'EqualUnitTestUser' ); $this->assertTrue( $fifth->equals( $sixth ) ); } + + /** + * @covers User::getId + */ + public function testGetId() { + $user = User::newFromName( 'UTSysop' ); + $this->assertTrue( $user->getId() > 0 ); + + } + + /** + * @covers User::isLoggedIn + * @covers User::isAnon + */ + public function testLoggedIn() { + $user = User::newFromName( 'UTSysop' ); + $this->assertTrue( $user->isLoggedIn() ); + $this->assertFalse( $user->isAnon() ); + + // Non-existent users are perceived as anonymous + $user = User::newFromName( 'UTNonexistent' ); + $this->assertFalse( $user->isLoggedIn() ); + $this->assertTrue( $user->isAnon() ); + + $user = new User; + $this->assertFalse( $user->isLoggedIn() ); + $this->assertTrue( $user->isAnon() ); + } }