10 class ApiBlockTest
extends ApiTestCase
{
11 protected function setUp() {
16 protected function tearDown() {
17 $block = Block
::newFromTarget( 'UTApiBlockee' );
18 if ( !is_null( $block ) ) {
24 protected function getTokens() {
25 return $this->getTokenList( self
::$users['sysop'] );
28 function addDBDataOnce() {
29 $user = User
::newFromName( 'UTApiBlockee' );
31 if ( $user->getId() == 0 ) {
32 $user->addToDatabase();
33 TestUser
::setPasswordForUser( $user, 'UTApiBlockeePassword' );
35 $user->saveSettings();
40 * This test has probably always been broken and use an invalid token
41 * Bug tracking brokenness is https://phabricator.wikimedia.org/T37646
43 * Root cause is https://gerrit.wikimedia.org/r/3434
44 * Which made the Block/Unblock API to actually verify the token
45 * previously always considered valid (T36212).
47 public function testMakeNormalBlock() {
48 $tokens = $this->getTokens();
50 $user = User
::newFromName( 'UTApiBlockee' );
52 if ( !$user->getId() ) {
53 $this->markTestIncomplete( "The user UTApiBlockee does not exist" );
56 if ( !array_key_exists( 'blocktoken', $tokens ) ) {
57 $this->markTestIncomplete( "No block token found" );
60 $this->doApiRequest( [
62 'user' => 'UTApiBlockee',
63 'reason' => 'Some reason',
64 'token' => $tokens['blocktoken'] ], null, false, self
::$users['sysop']->getUser() );
66 $block = Block
::newFromTarget( 'UTApiBlockee' );
68 $this->assertTrue( !is_null( $block ), 'Block is valid' );
70 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
71 $this->assertEquals( 'Some reason', $block->mReason
);
72 $this->assertEquals( 'infinity', $block->mExpiry
);
78 public function testMakeNormalBlockId() {
79 $tokens = $this->getTokens();
80 $user = User
::newFromName( 'UTApiBlockee' );
82 if ( !$user->getId() ) {
83 $this->markTestIncomplete( "The user UTApiBlockee does not exist." );
86 if ( !array_key_exists( 'blocktoken', $tokens ) ) {
87 $this->markTestIncomplete( "No block token found" );
90 $data = $this->doApiRequest( [
92 'userid' => $user->getId(),
93 'reason' => 'Some reason',
94 'token' => $tokens['blocktoken'] ], null, false, self
::$users['sysop']->getUser() );
96 $block = Block
::newFromTarget( 'UTApiBlockee' );
98 $this->assertTrue( !is_null( $block ), 'Block is valid.' );
99 $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
100 $this->assertEquals( 'Some reason', $block->mReason
);
101 $this->assertEquals( 'infinity', $block->mExpiry
);
105 * @expectedException ApiUsageException
106 * @expectedExceptionMessage The "token" parameter must be set
108 public function testBlockingActionWithNoToken() {
112 'user' => 'UTApiBlockee',
113 'reason' => 'Some reason',
117 self
::$users['sysop']->getUser()