MediaWiki REL1_30
ApiBlockTest.php
Go to the documentation of this file.
1<?php
2
11 protected function setUp() {
12 parent::setUp();
13 $this->doLogin();
14
15 $this->setMwGlobals( 'wgBlockCIDRLimit', [
16 'IPv4' => 16,
17 'IPv6' => 19,
18 ] );
19 }
20
21 protected function tearDown() {
22 $block = Block::newFromTarget( 'UTApiBlockee' );
23 if ( !is_null( $block ) ) {
24 $block->delete();
25 }
26 parent::tearDown();
27 }
28
29 protected function getTokens() {
30 return $this->getTokenList( self::$users['sysop'] );
31 }
32
33 function addDBDataOnce() {
34 $user = User::newFromName( 'UTApiBlockee' );
35
36 if ( $user->getId() == 0 ) {
37 $user->addToDatabase();
38 TestUser::setPasswordForUser( $user, 'UTApiBlockeePassword' );
39
40 $user->saveSettings();
41 }
42 }
43
52 public function testMakeNormalBlock() {
53 $tokens = $this->getTokens();
54
55 $user = User::newFromName( 'UTApiBlockee' );
56
57 if ( !$user->getId() ) {
58 $this->markTestIncomplete( "The user UTApiBlockee does not exist" );
59 }
60
61 if ( !array_key_exists( 'blocktoken', $tokens ) ) {
62 $this->markTestIncomplete( "No block token found" );
63 }
64
65 $this->doApiRequest( [
66 'action' => 'block',
67 'user' => 'UTApiBlockee',
68 'reason' => 'Some reason',
69 'token' => $tokens['blocktoken'] ], null, false, self::$users['sysop']->getUser() );
70
71 $block = Block::newFromTarget( 'UTApiBlockee' );
72
73 $this->assertTrue( !is_null( $block ), 'Block is valid' );
74
75 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
76 $this->assertEquals( 'Some reason', $block->mReason );
77 $this->assertEquals( 'infinity', $block->mExpiry );
78 }
79
83 public function testMakeNormalBlockId() {
84 $tokens = $this->getTokens();
85 $user = User::newFromName( 'UTApiBlockee' );
86
87 if ( !$user->getId() ) {
88 $this->markTestIncomplete( "The user UTApiBlockee does not exist." );
89 }
90
91 if ( !array_key_exists( 'blocktoken', $tokens ) ) {
92 $this->markTestIncomplete( "No block token found" );
93 }
94
95 $data = $this->doApiRequest( [
96 'action' => 'block',
97 'userid' => $user->getId(),
98 'reason' => 'Some reason',
99 'token' => $tokens['blocktoken'] ], null, false, self::$users['sysop']->getUser() );
100
101 $block = Block::newFromTarget( 'UTApiBlockee' );
102
103 $this->assertTrue( !is_null( $block ), 'Block is valid.' );
104 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
105 $this->assertEquals( 'Some reason', $block->mReason );
106 $this->assertEquals( 'infinity', $block->mExpiry );
107 }
108
114 $this->doApiRequest(
115 [
116 'action' => 'block',
117 'user' => 'UTApiBlockee',
118 'reason' => 'Some reason',
119 ],
120 null,
121 false,
122 self::$users['sysop']->getUser()
123 );
124 }
125}
API Database medium.
testMakeNormalBlockId()
Block by user ID.
addDBDataOnce()
Stub.
testBlockingActionWithNoToken()
ApiUsageException The "token" parameter must be set.
testMakeNormalBlock()
This test has probably always been broken and use an invalid token Bug tracking brokenness is https:/...
doLogin( $testUser='sysop')
getTokenList(TestUser $user, $session=null)
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=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.
Definition Block.php:1112
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
static setPasswordForUser(User $user, $password)
Set the password on a testing user.
Definition TestUser.php:127
$tokens