25 if ( !is_null( $block ) ) {
40 private function doBlock( array $extraParams = [],
User $blocker =
null ) {
41 if ( $blocker ===
null ) {
42 $blocker = self::$users[
'sysop']->getUser();
47 $this->assertNotNull( $this->mUser,
'Sanity check' );
49 $this->assertArrayHasKey(
'blocktoken',
$tokens,
'Sanity check' );
53 'user' => $this->mUser->getName(),
54 'reason' =>
'Some reason',
55 'token' =>
$tokens[
'blocktoken'],
57 if ( array_key_exists(
'userid', $extraParams ) ) {
66 $this->assertTrue( !is_null( $block ),
'Block is valid' );
68 $this->assertSame( $this->mUser->getName(), (
string)$block->getTarget() );
69 $this->assertSame(
'Some reason', $block->mReason );
85 $this->
doBlock( [
'userid' => $this->mUser->getId() ] );
92 $this->setExpectedException( ApiUsageException::class,
93 'You cannot block or unblock other users because you are yourself blocked.' );
97 'address' => $blocked->getName(),
98 'by' => self::$users[
'sysop']->getUser()->getId(),
99 'reason' =>
'Capriciousness',
100 'timestamp' =>
'19370101000000',
101 'expiry' =>
'infinity',
105 $this->
doBlock( [], $blocked );
109 $this->setExpectedException( ApiUsageException::class,
110 'There is no user by the name "Nonexistent". Check your spelling.' );
112 $this->
doBlock( [
'user' =>
'Nonexistent' ] );
117 $this->setExpectedException( ApiUsageException::class,
118 "There is no user with ID $id." );
120 $this->assertFalse(
User::whoIs( $id ),
'Sanity check' );
122 $this->
doBlock( [
'userid' => $id ] );
128 $this->
doBlock( [
'tags' =>
'custom tag' ] );
131 $this->assertSame(
'custom tag', $dbw->selectField(
132 [
'change_tag',
'logging' ],
134 [
'log_type' =>
'block' ],
137 [
'change_tag' => [
'INNER JOIN',
'ct_log_id = log_id' ] ]
142 $this->setExpectedException( ApiUsageException::class,
143 'You do not have permission to apply change tags along with your changes.' );
148 [
'user' => [
'applychangetags' =>
true ] ] );
150 $this->
doBlock( [
'tags' =>
'custom tag' ] );
156 $newPermissions[
'hideuser'] =
true;
158 [
'sysop' => $newPermissions ] );
163 $this->assertSame(
'1', $dbw->selectField(
166 [
'ipb_id' =>
$res[0][
'block'][
'id'] ],
172 $this->setExpectedException( ApiUsageException::class,
173 "You don't have permission to hide user names from the block log." );
175 $this->
doBlock( [
'hidename' =>
'' ] );
182 $this->assertSame(
'1', $dbw->selectField(
185 [
'ipb_id' =>
$res[0][
'block'][
'id'] ],
191 $this->setExpectedException( ApiUsageException::class,
192 "You don't have permission to block users from sending email through the wiki." );
195 [
'sysop' => [
'blockemail' =>
true ] ] );
197 $this->
doBlock( [
'noemail' =>
'' ] );
204 $expiry = $dbw->selectField(
207 [
'ipb_id' =>
$res[0][
'block'][
'id'] ],
212 $this->assertLessThanOrEqual( 1,
213 abs(
wfTimestamp( TS_UNIX, $expiry ) - ( time() + 86400 ) ) );
217 $this->setExpectedException( ApiUsageException::class,
"Expiry time invalid." );
219 $this->
doBlock( [
'expiry' =>
'' ] );
230 'user' => $this->mUser->getName(),
231 'reason' =>
'Some reason',
235 self::$users[
'sysop']->getUser()
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']
testBlockOfNonexistentUser()
testBlockByBlockedUser()
A blocked user can't block.
testBlockWithEmailBlock()
testBlockWithProhibitedTag()
testBlockById()
Block by user ID.
testNormalBlock()
Block by username.
testBlockWithProhibitedHide()
doBlock(array $extraParams=[], User $blocker=null)
testBlockWithInvalidExpiry()
testBlockingActionWithNoToken()
ApiUsageException The "token" parameter must be set.
testBlockOfNonexistentUserId()
testVeryLargeRangeBlock()
ApiUsageException Range blocks larger than /16 are not allowed.
testBlockWithProhibitedEmailBlock()
getTokenList(TestUser $user, $session=null)
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
Does the API request and returns the result.
static newFromTarget( $specificTarget, $vagueTarget=null, $fromMaster=false)
Given a target and the target's type, get an existing Block object if possible.
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 whoIs( $id)
Get the username corresponding to a given user ID.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret