X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fapi%2FApiBlockTest.php;h=832a113f0e111a1d75a83f1ea72c812c714727c6;hb=199df046c48a29c9ae2ea6194dad664ffc8fb9f8;hp=d2dccf997d27c290fe9cdc91dd508dca0208ca86;hpb=1ed1cc8769c43b967a7f03ff33bf129318e0eea0;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php index d2dccf997d..832a113f0e 100644 --- a/tests/phpunit/includes/api/ApiBlockTest.php +++ b/tests/phpunit/includes/api/ApiBlockTest.php @@ -13,6 +13,14 @@ class ApiBlockTest extends ApiTestCase { $this->doLogin(); } + protected function tearDown() { + $block = Block::newFromTarget( 'UTApiBlockee' ); + if ( !is_null( $block ) ) { + $block->delete(); + } + parent::tearDown(); + } + protected function getTokens() { return $this->getTokenList( self::$users['sysop'] ); } @@ -65,8 +73,37 @@ class ApiBlockTest extends ApiTestCase { } /** - * @expectedException UsageException - * @expectedExceptionMessage The token parameter must be set + * Block by user ID + */ + public function testMakeNormalBlockId() { + $tokens = $this->getTokens(); + $user = User::newFromName( 'UTApiBlockee' ); + + if ( !$user->getId() ) { + $this->markTestIncomplete( "The user UTApiBlockee does not exist." ); + } + + if ( !array_key_exists( 'blocktoken', $tokens ) ) { + $this->markTestIncomplete( "No block token found" ); + } + + $data = $this->doApiRequest( [ + 'action' => 'block', + 'userid' => $user->getId(), + 'reason' => 'Some reason', + 'token' => $tokens['blocktoken'] ], null, false, self::$users['sysop']->getUser() ); + + $block = Block::newFromTarget( 'UTApiBlockee' ); + + $this->assertTrue( !is_null( $block ), 'Block is valid.' ); + $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() ); + $this->assertEquals( 'Some reason', $block->mReason ); + $this->assertEquals( 'infinity', $block->mExpiry ); + } + + /** + * @expectedException ApiUsageException + * @expectedExceptionMessage The "token" parameter must be set */ public function testBlockingActionWithNoToken() { $this->doApiRequest(