$this->cheapCache->setField( $path, 'stat', $latest ? 'NOT_EXIST_LATEST' : 'NOT_EXIST' );
$this->cheapCache->setField( $path, 'xattr', [ 'map' => false, 'latest' => $latest ] );
$this->cheapCache->setField( $path, 'sha1', [ 'hash' => false, 'latest' => $latest ] );
- $this->logger->debug( __METHOD__ . ": File $path does not exist.\n" );
+ $this->logger->debug( __METHOD__ . ': File {path} does not exist', [
+ 'path' => $path,
+ ] );
} else { // an error occurred
- $this->logger->warning( __METHOD__ . ": Could not stat file $path.\n" );
+ $this->logger->warning( __METHOD__ . ': Could not stat file {path}', [
+ 'path' => $path,
+ ] );
}
return $stat;
[ 'map' => false, 'latest' => $latest ] );
$this->cheapCache->setField( $path, 'sha1',
[ 'hash' => false, 'latest' => $latest ] );
- $this->logger->debug( __METHOD__ . ": File $path does not exist.\n" );
+ $this->logger->debug( __METHOD__ . ': File {path} does not exist', [
+ 'path' => $path,
+ ] );
} else { // an error occurred
$success = false;
- $this->logger->warning( __METHOD__ . ": Could not stat file $path.\n" );
+ $this->logger->warning( __METHOD__ . ': Could not stat file {path}', [
+ 'path' => $path,
+ ] );
}
}
'JavaScriptTest' => [ '자바스크립트시험', '자바스크립트테스트' ],
'BlockList' => [ '차단목록', 'IP차단목록', '차단된사용자' ],
'LinkSearch' => [ '링크검색', '링크찾기' ],
- 'Listadmins' => [ '관리자', '관리자목록' ],
- 'Listbots' => [ '봇', '봇목록' ],
+ 'Listadmins' => [ '관리자목록', '관리자' ],
+ 'Listbots' => [ '봇목록', '봇' ],
'Listfiles' => [ '파일목록', '그림목록', '파일', '그림' ],
'Listgrouprights' => [ '사용자권한목록', '사용자권한', '권한목록' ],
'Listgrants' => [ '권한부여목록' ],
'Listredirects' => [ '넘겨주기목록' ],
'ListDuplicatedFiles' => [ '중복된파일목록' ],
- 'Listusers' => [ '사용자', '사용자목록' ],
+ 'Listusers' => [ '사용자목록', '사용자' ],
'Lockdb' => [ 'DB잠금', 'DB잠그기' ],
'Log' => [ '기록', '로그' ],
'Lonelypages' => [ '외톨이문서', '홀로된문서' ],
* @covers ApiUnblock
*/
class ApiUnblockTest extends ApiTestCase {
+ /** @var User */
+ private $blocker;
+
+ /** @var User */
+ private $blockee;
+
+ public function setUp() {
+ parent::setUp();
+
+ $this->tablesUsed = array_merge(
+ $this->tablesUsed,
+ [ 'ipblocks', 'change_tag', 'change_tag_def', 'logging' ]
+ );
+
+ $this->blocker = $this->getTestSysop()->getUser();
+ $this->blockee = $this->getMutableTestUser()->getUser();
+
+ // Initialize a blocked user (used by most tests, although not all)
+ $block = new Block( [
+ 'address' => $this->blockee->getName(),
+ 'by' => $this->blocker->getId(),
+ ] );
+ $result = $block->insert();
+ $this->assertNotFalse( $result, 'Could not insert block' );
+ $blockFromDB = Block::newFromID( $result['id'] );
+ $this->assertTrue( !is_null( $blockFromDB ), 'Could not retrieve block' );
+ }
+
+ private function getBlockFromParams( array $params ) {
+ if ( array_key_exists( 'user', $params ) ) {
+ return Block::newFromTarget( $params['user'] );
+ }
+ if ( array_key_exists( 'userid', $params ) ) {
+ return Block::newFromTarget( User::newFromId( $params['userid'] ) );
+ }
+ return Block::newFromId( $params['id'] );
+ }
+
+ /**
+ * Try to submit the unblock API request and check that the block no longer exists.
+ *
+ * @param array $params API request query parameters
+ */
+ private function doUnblock( array $params = [] ) {
+ $params += [ 'action' => 'unblock' ];
+ if ( !array_key_exists( 'userid', $params ) && !array_key_exists( 'id', $params ) ) {
+ $params += [ 'user' => $this->blockee->getName() ];
+ }
+
+ $originalBlock = $this->getBlockFromParams( $params );
+
+ $this->doApiRequestWithToken( $params );
+
+ // We only check later on whether the block existed to begin with, because maybe the caller
+ // expects doApiRequestWithToken to throw, in which case the block might not be expected to
+ // exist to begin with.
+ $this->assertInstanceOf( Block::class, $originalBlock, 'Block should initially exist' );
+ $this->assertNull( $this->getBlockFromParams( $params ), 'Block should have been removed' );
+ }
+
/**
* @expectedException ApiUsageException
*/
public function testWithNoToken() {
- $this->doApiRequest(
+ $this->doApiRequest( [
+ 'action' => 'unblock',
+ 'user' => $this->blockee->getName(),
+ 'reason' => 'Some reason',
+ ] );
+ }
+
+ public function testNormalUnblock() {
+ $this->doUnblock();
+ }
+
+ public function testUnblockNoPermission() {
+ $this->setExpectedApiException( 'apierror-permissiondenied-unblock' );
+
+ $this->setGroupPermissions( 'sysop', 'block', false );
+
+ $this->doUnblock();
+ }
+
+ public function testUnblockWhenBlocked() {
+ $this->setExpectedApiException( 'ipbblocked' );
+
+ $block = new Block( [
+ 'address' => $this->blocker->getName(),
+ 'by' => $this->getTestUser( 'sysop' )->getUser()->getId(),
+ ] );
+ $block->insert();
+
+ $this->doUnblock();
+ }
+
+ public function testUnblockSelfWhenBlocked() {
+ $block = new Block( [
+ 'address' => $this->blocker->getName(),
+ 'by' => $this->getTestUser( 'sysop' )->getUser()->getId(),
+ ] );
+ $result = $block->insert();
+ $this->assertNotFalse( $result, 'Could not insert block' );
+
+ $this->doUnblock( [ 'user' => $this->blocker->getName() ] );
+ }
+
+ // XXX These three tests copy-pasted from ApiBlockTest.php
+ public function testUnblockWithTag() {
+ $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH );
+ ChangeTags::defineTag( 'custom tag' );
+
+ $this->doUnblock( [ 'tags' => 'custom tag' ] );
+
+ $dbw = wfGetDB( DB_MASTER );
+ $this->assertSame( 1, (int)$dbw->selectField(
+ [ 'change_tag', 'logging' ],
+ 'COUNT(*)',
+ [ 'log_type' => 'block', 'ct_tag' => 'custom tag' ],
+ __METHOD__,
+ [],
+ [ 'change_tag' => [ 'INNER JOIN', 'ct_log_id = log_id' ] ]
+ ) );
+ }
+
+ public function testUnblockWithTagNewBackend() {
+ $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW );
+ ChangeTags::defineTag( 'custom tag' );
+
+ $this->doUnblock( [ 'tags' => 'custom tag' ] );
+
+ $dbw = wfGetDB( DB_MASTER );
+ $this->assertSame( 1, (int)$dbw->selectField(
+ [ 'change_tag', 'logging', 'change_tag_def' ],
+ 'COUNT(*)',
+ [ 'log_type' => 'block', 'ctd_name' => 'custom tag' ],
+ __METHOD__,
+ [],
[
- 'action' => 'unblock',
- 'user' => 'UTApiBlockee',
- 'reason' => 'Some reason',
+ 'change_tag' => [ 'INNER JOIN', 'ct_log_id = log_id' ],
+ 'change_tag_def' => [ 'INNER JOIN', 'ctd_id = ct_tag_id' ],
]
- );
+ ) );
+ }
+
+ public function testUnblockWithProhibitedTag() {
+ $this->setExpectedApiException( 'tags-apply-no-permission' );
+
+ ChangeTags::defineTag( 'custom tag' );
+
+ $this->setGroupPermissions( 'user', 'applychangetags', false );
+
+ $this->doUnblock( [ 'tags' => 'custom tag' ] );
+ }
+
+ public function testUnblockById() {
+ $this->doUnblock( [ 'userid' => $this->blockee->getId() ] );
+ }
+
+ public function testUnblockByInvalidId() {
+ $this->setExpectedApiException( [ 'apierror-nosuchuserid', 1234567890 ] );
+
+ $this->doUnblock( [ 'userid' => 1234567890 ] );
+ }
+
+ public function testUnblockNonexistentBlock() {
+ $this->setExpectedAPIException( [ 'ipb_cant_unblock', $this->blocker->getName() ] );
+
+ $this->doUnblock( [ 'user' => $this->blocker ] );
}
}