3define(
'NS_UNITTEST', 5600 );
4define(
'NS_UNITTEST_TALK', 5601 );
7use Wikimedia\TestingAccessWrapper;
22 'wgGroupPermissions' => [],
23 'wgRevokePermissions' => [],
30 $this->user = $this->
getTestUser( [
'unittesters' ] )->getUser();
36 # Data for regular $wgGroupPermissions test
49 # Data for regular $wgRevokePermissions test
54 # For the options test
56 'editmyoptions' =>
true,
65 $this->assertContains(
'runtest', $rights );
66 $this->assertNotContains(
'writetest', $rights );
67 $this->assertNotContains(
'modifytest', $rights );
68 $this->assertNotContains(
'nukeworld', $rights );
71 $this->assertContains(
'runtest', $rights );
72 $this->assertContains(
'writetest', $rights );
73 $this->assertContains(
'modifytest', $rights );
74 $this->assertNotContains(
'nukeworld', $rights );
82 $this->assertNotContains(
'runtest', $rights );
83 $this->assertNotContains(
'writetest', $rights );
84 $this->assertNotContains(
'modifytest', $rights );
85 $this->assertNotContains(
'nukeworld', $rights );
92 $rights = $this->user->getRights();
93 $this->assertContains(
'runtest', $rights );
94 $this->assertNotContains(
'writetest', $rights );
95 $this->assertNotContains(
'modifytest', $rights );
96 $this->assertNotContains(
'nukeworld', $rights );
103 $user = $this->
getTestUser( [
'unittesters',
'testwriters' ] )->getUser();
104 $userWrapper = TestingAccessWrapper::newFromObject( $user );
106 $rights = $user->getRights();
107 $this->assertContains(
'test', $rights,
'sanity check' );
108 $this->assertContains(
'runtest', $rights,
'sanity check' );
109 $this->assertContains(
'writetest', $rights,
'sanity check' );
110 $this->assertNotContains(
'nukeworld', $rights,
'sanity check' );
114 $rights[] =
'nukeworld';
115 $rights = array_diff( $rights, [
'writetest' ] );
118 $userWrapper->mRights =
null;
119 $rights = $user->getRights();
120 $this->assertContains(
'test', $rights );
121 $this->assertContains(
'runtest', $rights );
122 $this->assertNotContains(
'writetest', $rights );
123 $this->assertContains(
'nukeworld', $rights );
126 $mock = $this->getMockBuilder( stdClass::class )
127 ->setMethods( [
'getAllowedUserRights',
'deregisterSession',
'getSessionId' ] )
129 $mock->method(
'getAllowedUserRights' )->willReturn( [
'test',
'writetest' ] );
130 $mock->method(
'getSessionId' )->willReturn(
131 new MediaWiki\Session\SessionId( str_repeat(
'X', 32 ) )
133 $session = MediaWiki\Session\TestUtils::getDummySession( $mock );
134 $mockRequest = $this->getMockBuilder( FauxRequest::class )
135 ->setMethods( [
'getSession' ] )
137 $mockRequest->method(
'getSession' )->willReturn( $session );
138 $userWrapper->mRequest = $mockRequest;
140 $userWrapper->mRights =
null;
141 $rights = $user->getRights();
142 $this->assertContains(
'test', $rights );
143 $this->assertNotContains(
'runtest', $rights );
144 $this->assertNotContains(
'writetest', $rights );
145 $this->assertNotContains(
'nukeworld', $rights );
157 $this->assertEquals( $expected, $result,
"Groups with permission $right" );
163 [
'unittesters',
'testwriters' ],
186 $this->assertEquals( $this->user->isIP(
$value ), $result, $message );
191 [
'',
false,
'Empty string' ],
192 [
' ',
false,
'Blank space' ],
193 [
'10.0.0.0',
true,
'IPv4 private 10/8' ],
194 [
'10.255.255.255',
true,
'IPv4 private 10/8' ],
195 [
'192.168.1.1',
true,
'IPv4 private 192.168/16' ],
196 [
'203.0.113.0',
true,
'IPv4 example' ],
197 [
'2002:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
true,
'IPv6 example' ],
201 [
'300.300.300.300',
true,
'Looks too much like an IPv4 address' ],
202 [
'203.0.113.xxx',
true,
'Assigned by UseMod to cloaked logged-out users' ],
211 $this->assertEquals( $this->user->isValidUserName(
$username ), $result, $message );
216 [
'',
false,
'Empty string' ],
217 [
' ',
false,
'Blank space' ],
218 [
'abcd',
false,
'Starts with small letter' ],
219 [
'Ab/cd',
false,
'Contains slash' ],
220 [
'Ab cd',
true,
'Whitespace' ],
221 [
'192.168.1.1',
false,
'IP' ],
222 [
'116.17.184.5/32',
false,
'IP range' ],
223 [
'::e:f:2001/96',
false,
'IPv6 range' ],
224 [
'User:Abcd',
false,
'Reserved Namespace' ],
225 [
'12abcd232',
true,
'Starts with Numbers' ],
226 [
'?abcd',
true,
'Start with ? mark' ],
227 [
'#abcd',
false,
'Start with #' ],
228 [
'Abcdകഖഗഘ',
true,
' Mixed scripts' ],
229 [
'ജോസ്തോമസ്',
false,
'ZWNJ- Format control character' ],
230 [
'Ab cd',
false,
' Ideographic space' ],
231 [
'300.300.300.300',
false,
'Looks too much like an IPv4 address' ],
232 [
'302.113.311.900',
false,
'Looks too much like an IPv4 address' ],
233 [
'203.0.113.xxx',
false,
'Reserved for usage by UseMod for cloaked logged-out users' ],
247 $allMessageKeys = Language::getMessageKeysFor(
'en' );
249 $rightsWithMessage = [];
250 foreach ( $allMessageKeys as $message ) {
252 if ( strpos( $message,
'right-' ) === 0 ) {
253 $rightsWithMessage[] = substr( $message, strlen(
'right-' ) );
258 sort( $rightsWithMessage );
263 'Each user rights (core/extensions) has a corresponding right- message.'
276 $page = WikiPage::factory( Title::newFromText(
'Help:UserTest_EditCount' ) );
277 for ( $i = 0; $i < 3; $i++ ) {
278 $page->doEditContent(
279 ContentHandler::makeContent( (
string)$i, $page->getTitle() ),
289 $user->getEditCount(),
290 'After three edits, the user edit count should be 3'
294 $user->incEditCount();
298 $user->getEditCount(),
299 'After increasing the edit count manually, the user edit count should be 4'
312 $user->getEditCount(),
313 'Edit count starts null for anonymous users.'
316 $user->incEditCount();
319 $user->getEditCount(),
320 'Edit count remains null for anonymous users despite calls to increase it.'
331 $user->incEditCount();
334 $reloadedUser->incEditCount();
338 $reloadedUser->getEditCount(),
339 'Increasing the edit count after a fresh load leaves the object up to date.'
351 $user->setOption(
'userjs-someoption',
'test' );
352 $user->setOption(
'rclimit', 200 );
353 $user->setOption(
'wpwatchlistdays',
'0' );
354 $user->saveSettings();
357 $user->load( User::READ_LATEST );
358 $this->assertEquals(
'test', $user->getOption(
'userjs-someoption' ) );
359 $this->assertEquals( 200, $user->getOption(
'rclimit' ) );
362 MediaWikiServices::getInstance()->getMainWANObjectCache()->clearProcessCache();
363 $this->assertEquals(
'test', $user->getOption(
'userjs-someoption' ) );
364 $this->assertEquals( 200, $user->getOption(
'rclimit' ) );
368 $user->load( User::READ_LATEST );
369 $this->assertSame( 0, $user->getOption(
'wpwatchlistdays' ) );
379 $this->user->setOption(
'userjs-someoption',
'test' );
381 $this->assertEquals(
'test', $this->user->getOption(
'userjs-someoption' ) );
395 'wgPasswordPolicy' => [
398 'MinimalPasswordLength' => 8,
399 'MinimumPasswordLengthToLogin' => 1,
400 'PasswordCannotMatchUsername' => 1,
403 'MinimalPasswordLength' => 6,
404 'PasswordCannotMatchUsername' =>
true,
405 'PasswordCannotMatchBlacklist' =>
true,
406 'MaximalPasswordLength' => 40,
410 'MinimalPasswordLength' =>
'PasswordPolicyChecks::checkMinimalPasswordLength',
411 'MinimumPasswordLengthToLogin' =>
'PasswordPolicyChecks::checkMinimumPasswordLengthToLogin',
412 'PasswordCannotMatchUsername' =>
'PasswordPolicyChecks::checkPasswordCannotMatchUsername',
413 'PasswordCannotMatchBlacklist' =>
'PasswordPolicyChecks::checkPasswordCannotMatchBlacklist',
414 'MaximalPasswordLength' =>
'PasswordPolicyChecks::checkMaximalPasswordLength',
419 $user = static::getTestUser()->getUser();
422 $this->assertTrue( $user->isValidPassword(
'Password1234' ) );
425 $this->assertFalse( $user->isValidPassword(
'a' ) );
426 $this->assertFalse( $user->checkPasswordValidity(
'a' )->isGood() );
427 $this->assertTrue( $user->checkPasswordValidity(
'a' )->isOK() );
428 $this->assertEquals(
'passwordtooshort', $user->getPasswordValidity(
'a' ) );
431 $longPass = str_repeat(
'a', 41 );
432 $this->assertFalse( $user->isValidPassword( $longPass ) );
433 $this->assertFalse( $user->checkPasswordValidity( $longPass )->isGood() );
434 $this->assertFalse( $user->checkPasswordValidity( $longPass )->isOK() );
435 $this->assertEquals(
'passwordtoolong', $user->getPasswordValidity( $longPass ) );
438 $this->assertFalse( $user->checkPasswordValidity( $user->getName() )->isGood() );
439 $this->assertTrue( $user->checkPasswordValidity( $user->getName() )->isOK() );
440 $this->assertEquals(
'password-name-match', $user->getPasswordValidity( $user->getName() ) );
444 $this->assertFalse( $user->checkPasswordValidity(
'Passpass' )->isGood() );
445 $this->assertEquals(
'password-login-forbidden', $user->getPasswordValidity(
'Passpass' ) );
455 'InterwikiLoadPrefix' => [
456 function ( $prefix, &$iwdata ) {
457 if ( $prefix ===
'interwiki' ) {
459 'iw_url' =>
'http://example.com/',
469 foreach ( $expectedArray as $validate => $expected ) {
478 'Leading space' => [
' Leading space', [
'creatable' =>
'Leading space' ] ],
479 'Trailing space ' => [
'Trailing space ', [
'creatable' =>
'Trailing space' ] ],
480 'Namespace prefix' => [
'Talk:Username', [
'creatable' =>
false,
'usable' =>
false,
481 'valid' =>
false,
'false' =>
'Talk:Username' ] ],
482 'Interwiki prefix' => [
'interwiki:Username', [
'creatable' =>
false,
'usable' =>
false,
483 'valid' =>
false,
'false' =>
'Interwiki:Username' ] ],
484 'With hash' => [
'name with # hash', [
'creatable' =>
false,
'usable' =>
false ] ],
485 'Multi spaces' => [
'Multi spaces', [
'creatable' =>
'Multi spaces',
486 'usable' =>
'Multi spaces' ] ],
487 'Lowercase' => [
'lowercase', [
'creatable' =>
'Lowercase' ] ],
488 'Invalid character' => [
'in[]valid', [
'creatable' =>
false,
'usable' =>
false,
489 'valid' =>
false,
'false' =>
'In[]valid' ] ],
490 'With slash' => [
'with / slash', [
'creatable' =>
false,
'usable' =>
false,
'valid' =>
false,
491 'false' =>
'With / slash' ] ],
502 $this->assertTrue( $first->equals( $first ) );
503 $this->assertTrue( $first->equals( $second ) );
504 $this->assertTrue( $second->equals( $first ) );
509 $this->assertFalse( $third->equals( $fourth ) );
510 $this->assertFalse( $fourth->equals( $third ) );
516 $this->assertTrue( $fifth->equals( $sixth ) );
523 $user = static::getTestUser()->getUser();
524 $this->assertTrue( $user->getId() > 0 );
533 $this->assertTrue( $user->isLoggedIn() );
534 $this->assertFalse( $user->isAnon() );
538 $this->assertFalse( $user->isLoggedIn() );
539 $this->assertTrue( $user->isAnon() );
542 $this->assertFalse( $user->isLoggedIn() );
543 $this->assertTrue( $user->isAnon() );
551 $user = TestingAccessWrapper::newFromObject( $user );
552 $this->assertTrue( $user->isLoggedIn() );
554 $touched = $user->getDBTouched();
556 $user->checkAndSetTouched(),
"checkAndSetTouched() succeded" );
557 $this->assertGreaterThan(
558 $touched, $user->getDBTouched(),
"user_touched increased with casOnTouched()" );
560 $touched = $user->getDBTouched();
562 $user->checkAndSetTouched(),
"checkAndSetTouched() succeded #2" );
563 $this->assertGreaterThan(
564 $touched, $user->getDBTouched(),
"user_touched increased with casOnTouched() #2" );
572 $this->assertEquals( 0, iterator_count(
$users ) );
575 $this->assertEquals( 0, iterator_count(
$users ) );
579 $this->assertEquals( 1, iterator_count(
$users ) );
581 $this->assertTrue( $user->equals(
$users->current() ) );
586 $this->assertEquals( 2, iterator_count(
$users ) );
588 $this->assertTrue( $user->equals(
$users->current() ) );
590 $this->assertTrue( $user2->equals(
$users->current() ) );
595 $this->assertEquals( 1, iterator_count(
$users ) );
597 $this->assertTrue( $user->equals(
$users->current() ) );
608 'wgCookieSetOnAutoblock' =>
true,
609 'wgCookiePrefix' =>
'wmsitetitle',
615 'PerformRetroactiveAutoblock' => []
622 $request1->getSession()->setUser( $user1tmp );
623 $expiryFiveHours =
wfTimestamp() + ( 5 * 60 * 60 );
624 $block =
new Block( [
625 'enableAutoblock' =>
true,
626 'expiry' =>
wfTimestamp( TS_MW, $expiryFiveHours ),
629 $block->setTarget( $user1tmp );
630 $block->setBlocker( $userBlocker );
631 $res = $block->insert();
632 $this->assertTrue( (
bool)
$res[
'id'],
'Failed to insert block' );
634 $user1->mBlock = $block;
638 $this->assertTrue( $user1->isLoggedIn() );
639 $this->assertTrue( $user1->isBlocked() );
641 $this->assertTrue( $block->isAutoblocking() );
642 $this->assertGreaterThanOrEqual( 1, $block->getId() );
645 $cookies = $request1->response()->getCookies();
646 $this->assertArrayHasKey(
'wmsitetitleBlockID', $cookies );
647 $this->assertEquals( $expiryFiveHours, $cookies[
'wmsitetitleBlockID'][
'expire'] );
649 $this->assertEquals( $block->getId(), $cookieValue );
653 $request2->setCookie(
'BlockID', $block->getCookieValue() );
656 $this->assertNotEquals( $user1->getId(), $user2->getId() );
657 $this->assertNotEquals( $user1->getToken(), $user2->getToken() );
658 $this->assertTrue( $user2->isAnon() );
659 $this->assertFalse( $user2->isLoggedIn() );
660 $this->assertTrue( $user2->isBlocked() );
662 $this->assertEquals(
true, $user2->getBlock()->isAutoblocking(),
'Autoblock does not work' );
665 $this->assertEquals( $block->getId(), $user2->getBlock()->getId() );
666 $this->assertEquals( $block->getExpiry(), $user2->getBlock()->getExpiry() );
671 $request3->getSession()->setUser( $user3tmp );
672 $request3->setCookie(
'BlockID', $block->getId() );
675 $this->assertTrue( $user3->isLoggedIn() );
676 $this->assertTrue( $user3->isBlocked() );
677 $this->assertEquals(
true, $user3->getBlock()->isAutoblocking() );
690 'wgCookieSetOnAutoblock' =>
false,
691 'wgCookiePrefix' =>
'wm_no_cookies',
697 'PerformRetroactiveAutoblock' => []
704 $request1->getSession()->setUser( $testUser );
705 $block =
new Block( [
'enableAutoblock' =>
true ] );
707 $block->setTarget( $testUser );
708 $block->setBlocker( $userBlocker );
709 $res = $block->insert();
710 $this->assertTrue( (
bool)
$res[
'id'],
'Failed to insert block' );
712 $user->mBlock = $block;
716 $this->assertTrue( $user->isLoggedIn() );
717 $this->assertTrue( $user->isBlocked() );
719 $this->assertTrue( $block->isAutoblocking() );
720 $this->assertGreaterThanOrEqual( 1, $user->getBlockId() );
721 $this->assertGreaterThanOrEqual( $block->getId(), $user->getBlockId() );
722 $cookies = $request1->response()->getCookies();
723 $this->assertArrayNotHasKey(
'wm_no_cookiesBlockID', $cookies );
736 'wgCookieSetOnAutoblock' =>
true,
737 'wgCookiePrefix' =>
'wm_infinite_block',
743 'PerformRetroactiveAutoblock' => []
750 $request1->getSession()->setUser( $user1Tmp );
751 $block =
new Block( [
'enableAutoblock' =>
true,
'expiry' =>
'infinity' ] );
753 $block->setTarget( $user1Tmp );
754 $block->setBlocker( $userBlocker );
755 $res = $block->insert();
756 $this->assertTrue( (
bool)
$res[
'id'],
'Failed to insert block' );
758 $user1->mBlock = $block;
762 $this->assertTrue( $user1->isLoggedIn() );
763 $this->assertTrue( $user1->isBlocked() );
765 $this->assertTrue( $block->isAutoblocking() );
766 $this->assertGreaterThanOrEqual( 1, $user1->getBlockId() );
767 $cookies = $request1->response()->getCookies();
769 $this->assertArrayHasKey(
'wm_infinite_blockBlockID', $cookies );
774 $cookies[
'wm_infinite_blockBlockID'][
'expire'],
781 $block->mExpiry =
wfTimestamp( TS_MW, $newExpiry );
785 $request2->getSession()->setUser( $user2tmp );
787 $user2->mBlock = $block;
789 $cookies = $request2->response()->getCookies();
790 $this->assertEquals(
wfTimestamp( TS_MW, $newExpiry ), $block->getExpiry() );
791 $this->assertEquals( $newExpiry, $cookies[
'wm_infinite_blockBlockID'][
'expire'] );
802 TestingAccessWrapper::newFromObject( $user )->mRequest =
$request;
803 $request->getSession()->setUser( $user );
805 $this->
setMwGlobals(
'wgSoftBlockRanges', [
'10.0.0.0/8' ] );
812 $this->assertNull(
$wgUser->getBlock() );
820 $this->assertInstanceOf( Block::class, $block );
821 $this->assertSame(
'wgSoftBlockRanges', $block->getSystemBlockType() );
828 $this->assertFalse(
$wgUser->isAnon(),
'sanity check' );
829 $this->assertNull(
$wgUser->getBlock() );
838 'wgCookieSetOnAutoblock' =>
true,
839 'wgCookiePrefix' =>
'wmsitetitle',
845 'PerformRetroactiveAutoblock' => []
852 $request1->getSession()->setUser( $user1tmp );
853 $block =
new Block( [
'enableAutoblock' =>
true ] );
855 $block->setTarget( $user1tmp );
856 $block->setBlocker( $userBlocker );
857 $res = $block->insert();
858 $this->assertTrue( (
bool)
$res[
'id'],
'Failed to insert block' );
860 $user1->mBlock = $block;
866 $request2->setCookie(
'BlockID', $block->getId() .
'!zzzzzzz' );
869 $this->assertTrue( $user2->isAnon() );
870 $this->assertFalse( $user2->isLoggedIn() );
871 $this->assertFalse( $user2->isBlocked() );
884 'wgCookieSetOnAutoblock' =>
true,
885 'wgCookiePrefix' =>
'wmsitetitle',
886 'wgSecretKey' =>
null,
891 'PerformRetroactiveAutoblock' => []
898 $request1->getSession()->setUser( $user1tmp );
899 $block =
new Block( [
'enableAutoblock' =>
true ] );
901 $block->setTarget( $user1tmp );
902 $block->setBlocker( $userBlocker );
903 $res = $block->insert();
904 $this->assertTrue( (
bool)
$res[
'id'],
'Failed to insert block' );
906 $user1->mBlock = $block;
908 $this->assertTrue( $user1->isBlocked() );
913 $request2->setCookie(
'BlockID', $block->getId() );
916 $this->assertNotEquals( $user1->getId(), $user2->getId() );
917 $this->assertNotEquals( $user1->getToken(), $user2->getToken() );
918 $this->assertTrue( $user2->isAnon() );
919 $this->assertFalse( $user2->isLoggedIn() );
920 $this->assertTrue( $user2->isBlocked() );
921 $this->assertEquals(
true, $user2->getBlock()->isAutoblocking() );
936 $this->assertTrue( $user->isPingLimitable() );
938 $this->
setMwGlobals(
'wgRateLimitsExcludedIPs', [
'1.2.3.4' ] );
939 $this->assertFalse( $user->isPingLimitable() );
941 $this->
setMwGlobals(
'wgRateLimitsExcludedIPs', [
'1.2.3.0/8' ] );
942 $this->assertFalse( $user->isPingLimitable() );
945 $noRateLimitUser = $this->getMockBuilder( User::class )->disableOriginalConstructor()
946 ->setMethods( [
'getIP',
'getRights' ] )->getMock();
947 $noRateLimitUser->expects( $this->
any() )->method(
'getIP' )->willReturn(
'1.2.3.4' );
948 $noRateLimitUser->expects( $this->
any() )->method(
'getRights' )->willReturn( [
'noratelimit' ] );
949 $this->assertFalse( $noRateLimitUser->isPingLimitable() );
954 [ 2, 2,
'newcomer' ],
955 [ 12, 3,
'newcomer' ],
956 [ 8, 5,
'newcomer' ],
957 [ 15, 10,
'learner' ],
958 [ 450, 20,
'learner' ],
959 [ 460, 33,
'learner' ],
960 [ 525, 28,
'learner' ],
961 [ 538, 33,
'experienced' ],
971 'wgLearnerEdits' => 10,
972 'wgLearnerMemberSince' => 4,
973 'wgExperiencedUserEdits' => 500,
974 'wgExperiencedUserMemberSince' => 30,
980 $userQuery[
'tables'],
981 $userQuery[
'fields'],
982 [
'user_id' => $this->
getTestUser()->getUser()->getId() ],
987 $row->user_editcount = $editCount;
988 $row->user_registration =
$db->
timestamp( time() - $memberSince * 86400 );
991 $this->assertEquals( $expLevel, $user->getExperienceLevel() );
1000 $this->assertFalse( $user->getExperienceLevel() );
1005 [
'1.2.3.4',
'1.2.3.4' ],
1006 [
'1.2.3.4',
'1.2.3.0/16' ],
1031 'test' => $blockListEntry
1037 'IP addresses in the keys of $wgProxyList (found the following IP ' .
1038 'addresses in keys: ' . $blockListEntry .
', please move them to values)'
1043 $blockListEntry =>
'test'
1054 $id = $user->getId();
1055 $this->assertTrue( $user->getActorId() > 0,
'User::createNew sets an actor ID' );
1058 $user->addToDatabase();
1059 $this->assertTrue( $user->getActorId() > 0,
'User::addToDatabase sets an actor ID' );
1062 $this->assertTrue( $user->getActorId() > 0,
'Actor ID can be retrieved for user loaded by name' );
1065 $this->assertTrue( $user->getActorId() > 0,
'Actor ID can be retrieved for user loaded by ID' );
1068 $this->assertEquals( $user->getId(), $user2->getId(),
1069 'User::newFromActorId works for an existing user' );
1071 $row = $this->db->selectRow(
'user',
User::selectFields(), [
'user_id' => $id ], __METHOD__ );
1073 $this->assertTrue( $user->getActorId() > 0,
1074 'Actor ID can be retrieved for user loaded with User::selectFields()' );
1076 $this->db->delete(
'actor', [
'actor_user' => $id ], __METHOD__ );
1079 ObjectCache::getMainWANInstance()->clearProcessCache();
1082 $this->assertFalse( $user->getActorId() > 0,
'No Actor ID by default if none in database' );
1083 $this->assertTrue( $user->getActorId( $this->db ) > 0,
'Actor ID can be created if none in db' );
1085 $user->setName(
'UserTestActorId4-renamed' );
1086 $user->saveSettings();
1087 $this->assertEquals(
1089 $this->db->selectField(
1090 'actor',
'actor_name', [
'actor_id' => $user->getActorId() ], __METHOD__
1092 'User::saveSettings updates actor table for name change'
1096 $ip =
'192.168.12.34';
1097 $this->db->delete(
'actor', [
'actor_name' => $ip ], __METHOD__ );
1100 $this->assertFalse( $user->getActorId() > 0,
'Anonymous user has no actor ID by default' );
1101 $this->assertTrue( $user->getActorId( $this->db ) > 0,
1102 'Actor ID can be created for an anonymous user' );
1105 $this->assertTrue( $user->getActorId() > 0,
'Actor ID can be loaded for an anonymous user' );
1107 $this->assertEquals( $user->getName(), $user2->getName(),
1108 'User::newFromActorId works for an anonymous user' );
1114 for ( $i = 1; $i <= 7; $i++ ) {
1116 ( $i & 1 ) ? $user->getId() :
null,
1117 ( $i & 2 ) ? $user->getName() :
null,
1118 ( $i & 4 ) ? $user->getActorId() : null
1120 $this->assertSame( $user->getId(), $test->getId() );
1121 $this->assertSame( $user->getName(), $test->getName() );
1122 $this->assertSame( $user->getActorId(), $test->getActorId() );
1127 $user->getActorId( $this->db );
1130 $this->assertSame( $user->getId(), $test->getId() );
1131 $this->assertSame( $user->getName(), $test->getName() );
1132 $this->assertSame( $user->getActorId(), $test->getActorId() );
1134 $this->assertSame( $user->getId(), $test->getId() );
1135 $this->assertSame( $user->getName(), $test->getName() );
1136 $this->assertSame( $user->getActorId(), $test->getActorId() );
1141 $this->assertSame( 123456, $test->getId() );
1142 $this->assertSame(
'Bogus', $test->getName() );
1143 $this->assertSame( 654321, $test->getActorId() );
1148 $this->fail(
'Expected exception not thrown' );
1149 }
catch ( InvalidArgumentException $ex ) {
1153 $this->fail(
'Expected exception not thrown' );
1154 }
catch ( InvalidArgumentException $ex ) {
1169 $ut = Title::makeTitle(
NS_USER_TALK, $user->getName() );
1170 $this->assertNull( $user->getBlock(
false ),
'sanity check' );
1171 $this->assertSame(
'', $user->blockedBy(),
'sanity check' );
1172 $this->assertSame(
'', $user->blockedFor(),
'sanity check' );
1173 $this->assertFalse( (
bool)$user->isHidden(),
'sanity check' );
1174 $this->assertFalse( $user->isBlockedFrom( $ut ),
'sanity check' );
1178 $block =
new Block( [
1180 'allowUsertalk' =>
false,
1181 'reason' =>
'Because',
1183 $block->setTarget( $user );
1184 $block->setBlocker( $blocker );
1185 $res = $block->insert();
1186 $this->assertTrue( (
bool)
$res[
'id'],
'sanity check: Failed to insert block' );
1189 $user->clearInstanceCache();
1190 $this->assertInstanceOf( Block::class, $user->getBlock(
false ) );
1191 $this->assertSame( $blocker->getName(), $user->blockedBy() );
1192 $this->assertSame(
'Because', $user->blockedFor() );
1193 $this->assertTrue( (
bool)$user->isHidden() );
1194 $this->assertTrue( $user->isBlockedFrom( $ut ) );
1200 $user->clearInstanceCache();
1201 $this->assertNull( $user->getBlock(
false ) );
1202 $this->assertSame(
'', $user->blockedBy() );
1203 $this->assertSame(
'', $user->blockedFor() );
1204 $this->assertFalse( (
bool)$user->isHidden() );
1205 $this->assertFalse( $user->isBlockedFrom( $ut ) );
1212 $user = $this->getMockBuilder( User::class )
1213 ->setMethods( [
'getId',
'getName',
'getRequest',
'getGroups' ] )
1216 $user->method(
'getId' )->willReturn( $id );
1217 $user->method(
'getName' )->willReturn( $name );
1218 $user->method(
'getRequest' )->willReturn(
$req );
1219 $user->method(
'getGroups' )->willReturn( [
'user' ] );
1222 'noratelimit' =>
false,
1239 'anon' => [ 1, 60 ],
1243 'subnet' => [ 1, 60 ],
1246 'user' => [ 1, 60 ],
1249 'user-global' => [ 1, 60 ],
1252 'ip-all' => [ 1, 60 ],
1253 'subnet-all' => [ 1, 60 ],
1264 $cacheAccess = TestingAccessWrapper::newFromObject(
$cache );
1265 $cacheAccess->keyspace =
'xwiki';
1278 $frankX1 = $this->
newFakeUser(
'Frank',
'1.2.3.4', 111 );
1279 $frankX2 = $this->
newFakeUser(
'Frank',
'1.2.3.8', 111 );
1280 $frankY1 = $this->
newFakeUser(
'Frank',
'1.2.3.4', 211 );
1281 $janeX1 = $this->
newFakeUser(
'Jane',
'1.2.3.4', 456 );
1282 $janeX3 = $this->
newFakeUser(
'Jane',
'6.7.8.9', 456 );
1283 $janeY1 = $this->
newFakeUser(
'Jane',
'1.2.3.4', 756 );
1284 $karaX1 = $this->
newFakeUser(
'Kara',
'5.5.5.5', 100 );
1285 $karaY1 = $this->
newFakeUser(
'Kara',
'5.5.5.5', 200 );
1288 $this->assertFalse( $anon1->pingLimiter(
'edit' ),
'First anon edit' );
1289 $this->assertTrue( $anon2->pingLimiter(
'edit' ),
'Second anon edit' );
1291 $this->assertFalse( $anon1->pingLimiter(
'purge' ),
'Anon purge' );
1292 $this->assertTrue( $anon1->pingLimiter(
'purge' ),
'Anon purge via same IP' );
1294 $this->assertFalse( $anon3->pingLimiter(
'purge' ),
'Anon purge via different subnet' );
1295 $this->assertTrue( $anon2->pingLimiter(
'purge' ),
'Anon purge via same subnet' );
1297 $this->assertFalse( $frankX1->pingLimiter(
'rollback' ),
'First rollback' );
1298 $this->assertTrue( $frankX2->pingLimiter(
'rollback' ),
'Second rollback via different IP' );
1299 $this->assertFalse( $janeX1->pingLimiter(
'rollback' ),
'Rlbk by different user, same IP' );
1301 $this->assertFalse( $frankX1->pingLimiter(
'move' ),
'First move' );
1302 $this->assertTrue( $frankX2->pingLimiter(
'move' ),
'Second move via different IP' );
1303 $this->assertFalse( $janeX1->pingLimiter(
'move' ),
'Move by different user, same IP' );
1304 $this->assertFalse( $karaX1->pingLimiter(
'move' ),
'Move by another user' );
1305 $this->assertTrue( $karaX1->pingLimiter(
'move' ),
'Second move by another user' );
1307 $this->assertFalse( $frankX1->pingLimiter(
'delete' ),
'First delete' );
1308 $this->assertTrue( $janeX1->pingLimiter(
'delete' ),
'Delete via same IP' );
1310 $this->assertTrue( $frankX2->pingLimiter(
'delete' ),
'Delete via same subnet' );
1311 $this->assertFalse( $janeX3->pingLimiter(
'delete' ),
'Delete via different subnet' );
1314 $cacheAccess->keyspace =
'ywiki';
1316 $this->assertFalse( $anon3->pingLimiter(
'edit' ),
'Anon edit on wiki Y' );
1317 $this->assertTrue( $anon4->pingLimiter(
'purge' ),
'Anon purge on wiki Y, same subnet' );
1318 $this->assertFalse( $frankY1->pingLimiter(
'rollback' ),
'Rollback on wiki Y, same name' );
1319 $this->assertTrue( $frankY1->pingLimiter(
'move' ),
'Move on wiki Y, same name' );
1320 $this->assertTrue( $janeY1->pingLimiter(
'move' ),
'Move on wiki Y, different user' );
1321 $this->assertTrue( $frankY1->pingLimiter(
'delete' ),
'Delete on wiki Y, same IP' );
1324 $this->assertFalse( $karaY1->pingLimiter(
'move' ),
'Move by another user' );
1325 $this->assertTrue( $karaY1->pingLimiter(
'move' ),
'Second move by another user' );
1329 $mockCentralIdLookup = $this->createMock( CentralIdLookup::class );
1331 $mockCentralIdLookup->method(
'centralIdFromLocalUser' )
1332 ->willReturnCallback(
function (
User $user ) {
1333 return $user->getId() % 100;
1335 $mockCentralIdLookup->method(
'getProviderId' )
1336 ->willReturn(
'test' );
1339 'wgCentralIdLookupProvider' =>
'test',
1340 'wgCentralIdLookupProviders' => [
1342 'factory' =>
function () use ( $mockCentralIdLookup ) {
1343 return $mockCentralIdLookup;
1359 $user->mRights = $permissions;
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
$wgDefaultUserOptions
Settings added to this array will override the default globals for the user preferences used by anony...
$wgRevokePermissions
Permission keys revoked from users in each group.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
$wgGroupPermissions['sysop']['replacetext']
static getIdFromCookieValue( $cookieValue)
Get the stored ID from the 'BlockID' cookie.
WebRequest clone which takes values from a provided array.
Simple store for keeping values in an associative array for the current process.
static generateHex( $chars, $forceStrong=false)
Generate a run of (ideally) cryptographically random data and return it in hexadecimal string format.
static getMain()
Get the RequestContext object associated with the main request.
testUserPermissions()
User::getRights.
testGetGroupsWithPermission( $expected, $right)
provideGetGroupsWithPermission User::getGroupsWithPermission
testExperienceLevelAnon()
User::getExperienceLevel.
testUserGetRightsHooks()
User::getRights.
testOptions()
Test changing user options.
newFakeUser( $name, $ip, $id)
testGetCanonicalName( $name, $expectedArray)
User::getCanonicalName() provideGetCanonicalName.
testAutoblockCookies()
When a user is autoblocked a cookie is set with which to track them in case they log out and change I...
testAutoblockCookieInfiniteExpiry()
When a user is autoblocked and a cookie is set to track them, the expiry time of the cookie should ma...
testAutoblockCookieInauthentic()
Test that a modified BlockID cookie doesn't actually load the relevant block (T152951).
testExperienceLevel( $editCount, $memberSince, $expLevel)
User::getExperienceLevel provideExperienceLevel.
testIsPingLimitable()
User::isPingLimitable.
static provideGetGroupsWithPermission()
testIsValidUserName( $username, $result, $message)
provideUserNames User::isValidUserName
testIsIP( $value, $result, $message)
provideIPs User::isIP
testGetEditCount()
Test User::editCount medium User::getEditCount.
testAutoblockCookieNoSecretKey()
The BlockID cookie is normally verified with a HMAC, but not if wgSecretKey is not set.
static provideGetCanonicalName()
testAnonOptions()
T39963 Make sure defaults are loaded when setOption is called.
testIncEditCount()
Test User::editCount medium User::incEditCount.
testGetEditCountForAnons()
Test User::editCount medium User::getEditCount.
testRevokePermissions()
User::getGroupPermissions.
static provideIsLocallBlockedProxy()
installMockContralIdProvider()
testEquals()
User::equals.
testCheckPasswordValidity()
Test password validity checks.
testIsLocallyBlockedProxy( $ip, $blockListEntry)
provideIsLocallBlockedProxy User::isLocallyBlockedProxy
testBlockInstanceCache()
User::getBlockedStatus User::getBlock User::blockedBy User::blockedFor User::isHidden User::isBlocked...
testAllRightsWithMessage()
Test, if for all rights a right- message exist, which is used on Special:ListGroupRights as help text...
testCheckAndSetTouched()
User::checkAndSetTouched.
testPingLimiterGlobal()
User::pingLimiter.
testLoggedIn()
User::isLoggedIn User::isAnon.
testAutoblockCookiesDisabled()
Make sure that no cookie is set to track autoblocked users when $wgCookieSetOnAutoblock is false.
testGroupPermissions()
User::getGroupPermissions.
testFindUsersByGroup()
User::findUsersByGroup.
overrideUserPermissions( $user, $permissions=[])
Overrides specific user permissions.
static provideUserNames()
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new user object.
static isLocallyBlockedProxy( $ip)
Check if an IP address is in the local proxy list.
static newFromAnyId( $userId, $userName, $actorId)
Static factory method for creation from an ID, name, and/or actor ID.
static purge( $wikiId, $userId)
static getCanonicalName( $name, $validate='valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid.
static newFromRow( $row, $data=null)
Create a new user object from a user row.
static newFromId( $id)
Static factory method for creation from a given user ID.
static getGroupsWithPermission( $role)
Get all the groups who have a given permission.
static getGroupPermissions( $groups)
Get the permissions associated with a given list of groups.
static findUsersByGroup( $groups, $limit=5000, $after=null)
Return the users who are members of the given group(s).
static selectFields()
Return the list of user fields that should be selected to create a new user object.
static newFromSession(WebRequest $request=null)
Create a new user object using data from session.
static getAllRights()
Get a list of all available permissions.
setOption( $oname, $val)
Set the given option for a user.
static createNew( $name, $params=[])
Add a user to the database, return the user object.
incEditCount()
Deferred version of incEditCountImmediate()
static newFromActorId( $id)
Static factory method for creation from a given actor ID.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
this hook is for auditing only $req
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on $request
this hook is for auditing only or null if authentication failed before getting that far $username
processing should stop and the error should be shown to the user * false
const MIGRATION_WRITE_BOTH
CACHE_MEMCACHED $wgMainCacheType