X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fuser%2FUserTest.php;h=b58d71cfa180f6919783b5e8b0b5d677e61647b0;hb=827c6bfa416d9d0de8cc8e22f9f3fa36d8129d44;hp=a596851c0ee429535623b40fdfc7c30c26780a3c;hpb=c9649314f710f722be2070f6f1bcae10189ba8f6;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php index a596851c0e..ea7f715b5f 100644 --- a/tests/phpunit/includes/user/UserTest.php +++ b/tests/phpunit/includes/user/UserTest.php @@ -25,9 +25,7 @@ class UserTest extends MediaWikiTestCase { $this->setUpPermissionGlobals(); - $this->user = new User; - $this->user->addToDatabase(); - $this->user->addGroup( 'unittesters' ); + $this->user = $this->getTestUser( [ 'unittesters' ] )->getUser(); } private function setUpPermissionGlobals() { @@ -100,10 +98,7 @@ class UserTest extends MediaWikiTestCase { * @covers User::getRights */ public function testUserGetRightsHooks() { - $user = new User; - $user->addToDatabase(); - $user->addGroup( 'unittesters' ); - $user->addGroup( 'testwriters' ); + $user = $this->getTestUser( [ 'unittesters', 'testwriters' ] )->getUser(); $userWrapper = TestingAccessWrapper::newFromObject( $user ); $rights = $user->getRights(); @@ -222,6 +217,8 @@ class UserTest extends MediaWikiTestCase { [ 'Ab/cd', false, 'Contains slash' ], [ 'Ab cd', true, 'Whitespace' ], [ '192.168.1.1', false, 'IP' ], + [ '116.17.184.5/32', false, 'IP range' ], + [ '::e:f:2001/96', false, 'IPv6 range' ], [ 'User:Abcd', false, 'Reserved Namespace' ], [ '12abcd232', true, 'Starts with Numbers' ], [ '?abcd', true, 'Start with ? mark' ], @@ -239,6 +236,8 @@ class UserTest extends MediaWikiTestCase { * Test, if for all rights a right- message exist, * which is used on Special:ListGroupRights as help text * Extensions and core + * + * @coversNothing */ public function testAllRightsWithMessage() { // Getting all user rights, for core: User::$mCoreRights, for extensions: $wgAvailableRights @@ -603,7 +602,13 @@ class UserTest extends MediaWikiTestCase { 'wgSecretKey' => MWCryptRand::generateHex( 64, true ), ] ); + // Unregister the hooks for proper unit testing + $this->mergeMwGlobalArrayValue( 'wgHooks', [ + 'PerformRetroactiveAutoblock' => [] + ] ); + // 1. Log in a test user, and block them. + $userBlocker = $this->getTestSysop()->getUser(); $user1tmp = $this->getTestUser()->getUser(); $request1 = new FauxRequest(); $request1->getSession()->setUser( $user1tmp ); @@ -613,7 +618,9 @@ class UserTest extends MediaWikiTestCase { 'expiry' => wfTimestamp( TS_MW, $expiryFiveHours ), ] ); $block->setTarget( $user1tmp ); - $block->insert(); + $block->setBlocker( $userBlocker ); + $res = $block->insert(); + $this->assertTrue( (bool)$res['id'], 'Failed to insert block' ); $user1 = User::newFromSession( $request1 ); $user1->mBlock = $block; $user1->load(); @@ -642,7 +649,8 @@ class UserTest extends MediaWikiTestCase { $this->assertTrue( $user2->isAnon() ); $this->assertFalse( $user2->isLoggedIn() ); $this->assertTrue( $user2->isBlocked() ); - $this->assertEquals( true, $user2->getBlock()->isAutoblocking() ); // Non-strict type-check. + // Non-strict type-check. + $this->assertEquals( true, $user2->getBlock()->isAutoblocking(), 'Autoblock does not work' ); // Can't directly compare the objects becuase of member type differences. // One day this will work: $this->assertEquals( $block, $user2->getBlock() ); $this->assertEquals( $block->getId(), $user2->getBlock()->getId() ); @@ -675,13 +683,21 @@ class UserTest extends MediaWikiTestCase { 'wgSecretKey' => MWCryptRand::generateHex( 64, true ), ] ); + // Unregister the hooks for proper unit testing + $this->mergeMwGlobalArrayValue( 'wgHooks', [ + 'PerformRetroactiveAutoblock' => [] + ] ); + // 1. Log in a test user, and block them. + $userBlocker = $this->getTestSysop()->getUser(); $testUser = $this->getTestUser()->getUser(); $request1 = new FauxRequest(); $request1->getSession()->setUser( $testUser ); $block = new Block( [ 'enableAutoblock' => true ] ); $block->setTarget( $testUser ); - $block->insert(); + $block->setBlocker( $userBlocker ); + $res = $block->insert(); + $this->assertTrue( (bool)$res['id'], 'Failed to insert block' ); $user = User::newFromSession( $request1 ); $user->mBlock = $block; $user->load(); @@ -711,13 +727,22 @@ class UserTest extends MediaWikiTestCase { 'wgCookiePrefix' => 'wm_infinite_block', 'wgSecretKey' => MWCryptRand::generateHex( 64, true ), ] ); + + // Unregister the hooks for proper unit testing + $this->mergeMwGlobalArrayValue( 'wgHooks', [ + 'PerformRetroactiveAutoblock' => [] + ] ); + // 1. Log in a test user, and block them indefinitely. + $userBlocker = $this->getTestSysop()->getUser(); $user1Tmp = $this->getTestUser()->getUser(); $request1 = new FauxRequest(); $request1->getSession()->setUser( $user1Tmp ); $block = new Block( [ 'enableAutoblock' => true, 'expiry' => 'infinity' ] ); $block->setTarget( $user1Tmp ); - $block->insert(); + $block->setBlocker( $userBlocker ); + $res = $block->insert(); + $this->assertTrue( (bool)$res['id'], 'Failed to insert block' ); $user1 = User::newFromSession( $request1 ); $user1->mBlock = $block; $user1->load(); @@ -798,13 +823,21 @@ class UserTest extends MediaWikiTestCase { 'wgSecretKey' => MWCryptRand::generateHex( 64, true ), ] ); + // Unregister the hooks for proper unit testing + $this->mergeMwGlobalArrayValue( 'wgHooks', [ + 'PerformRetroactiveAutoblock' => [] + ] ); + // 1. Log in a blocked test user. + $userBlocker = $this->getTestSysop()->getUser(); $user1tmp = $this->getTestUser()->getUser(); $request1 = new FauxRequest(); $request1->getSession()->setUser( $user1tmp ); $block = new Block( [ 'enableAutoblock' => true ] ); $block->setTarget( $user1tmp ); - $block->insert(); + $block->setBlocker( $userBlocker ); + $res = $block->insert(); + $this->assertTrue( (bool)$res['id'], 'Failed to insert block' ); $user1 = User::newFromSession( $request1 ); $user1->mBlock = $block; $user1->load(); @@ -835,13 +868,21 @@ class UserTest extends MediaWikiTestCase { 'wgSecretKey' => null, ] ); + // Unregister the hooks for proper unit testing + $this->mergeMwGlobalArrayValue( 'wgHooks', [ + 'PerformRetroactiveAutoblock' => [] + ] ); + // 1. Log in a blocked test user. + $userBlocker = $this->getTestSysop()->getUser(); $user1tmp = $this->getTestUser()->getUser(); $request1 = new FauxRequest(); $request1->getSession()->setUser( $user1tmp ); $block = new Block( [ 'enableAutoblock' => true ] ); $block->setTarget( $user1tmp ); - $block->insert(); + $block->setBlocker( $userBlocker ); + $res = $block->insert(); + $this->assertTrue( (bool)$res['id'], 'Failed to insert block' ); $user1 = User::newFromSession( $request1 ); $user1->mBlock = $block; $user1->load(); @@ -864,6 +905,9 @@ class UserTest extends MediaWikiTestCase { $block->delete(); } + /** + * @covers User::isPingLimitable + */ public function testIsPingLimitable() { $request = new FauxRequest(); $request->setIP( '1.2.3.4' ); @@ -900,6 +944,7 @@ class UserTest extends MediaWikiTestCase { } /** + * @covers User::getExperienceLevel * @dataProvider provideExperienceLevel */ public function testExperienceLevel( $editCount, $memberSince, $expLevel ) { @@ -929,6 +974,9 @@ class UserTest extends MediaWikiTestCase { $this->assertEquals( $expLevel, $user->getExperienceLevel() ); } + /** + * @covers User::getExperienceLevel + */ public function testExperienceLevelAnon() { $user = User::newFromName( '10.11.12.13', false );