X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fuser%2FUserTest.php;h=ea7f715b5f3221da047030d7043fb142c3432efa;hb=5f0080715ab1f9e176420c737b4a0511e3cb280b;hp=aa368de746e900188302404c0b868ef736458b8d;hpb=d19826aa35b206847a568a4b2c1c9ffaa615fca5;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php index aa368de746..ea7f715b5f 100644 --- a/tests/phpunit/includes/user/UserTest.php +++ b/tests/phpunit/includes/user/UserTest.php @@ -236,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 @@ -600,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 ); @@ -610,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(); @@ -639,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() ); @@ -672,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(); @@ -708,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(); @@ -795,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(); @@ -832,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(); @@ -861,6 +905,9 @@ class UserTest extends MediaWikiTestCase { $block->delete(); } + /** + * @covers User::isPingLimitable + */ public function testIsPingLimitable() { $request = new FauxRequest(); $request->setIP( '1.2.3.4' ); @@ -897,6 +944,7 @@ class UserTest extends MediaWikiTestCase { } /** + * @covers User::getExperienceLevel * @dataProvider provideExperienceLevel */ public function testExperienceLevel( $editCount, $memberSince, $expLevel ) { @@ -926,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 );