diff options
author | Thalia <thalia.e.chan@googlemail.com> | 2019-05-13 15:18:07 +0100 |
---|---|---|
committer | Thalia <thalia.e.chan@googlemail.com> | 2019-05-28 12:20:48 +0100 |
commit | e65a5b58821873fdfdd15a4de6c1590fbea9a5fd (patch) | |
tree | 0478aeb190749f06549befce2734d6d9014239fd /tests | |
parent | f4de088e6322d969b88edeb1c417549849c3803d (diff) | |
download | mediawikicore-e65a5b58821873fdfdd15a4de6c1590fbea9a5fd.tar.gz mediawikicore-e65a5b58821873fdfdd15a4de6c1590fbea9a5fd.zip |
Rename Block to MediaWiki\Block\DatabaseBlock
Keep Block as a deprecated class alias for DatabaseBlock.
Update calls to the Block constructor and Block static
methods from external classes.
Also update documentation in several places that refer to
blocks as Blocks.
Bug: T222737
Change-Id: I6d96b63ca0a84bee19486471e0a16a53a79d768a
Diffstat (limited to 'tests')
24 files changed, 201 insertions, 168 deletions
diff --git a/tests/phpunit/includes/Permissions/PermissionManagerTest.php b/tests/phpunit/includes/Permissions/PermissionManagerTest.php index 4676fc545ece..2ce50b7e9da4 100644 --- a/tests/phpunit/includes/Permissions/PermissionManagerTest.php +++ b/tests/phpunit/includes/Permissions/PermissionManagerTest.php @@ -3,11 +3,11 @@ namespace MediaWiki\Tests\Permissions; use Action; -use Block; use MediaWikiLangTestCase; use RequestContext; use Title; use User; +use MediaWiki\Block\DatabaseBlock; use MediaWiki\Block\Restriction\NamespaceRestriction; use MediaWiki\Block\Restriction\PageRestriction; use MediaWiki\Block\SystemBlock; @@ -1036,7 +1036,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase { $prev = time(); $now = time() + 120; $this->user->mBlockedby = $this->user->getId(); - $this->user->mBlock = new Block( [ + $this->user->mBlock = new DatabaseBlock( [ 'address' => '127.0.8.1', 'by' => $this->user->getId(), 'reason' => 'no reason given', @@ -1062,7 +1062,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase { global $wgLocalTZoffset; $wgLocalTZoffset = -60; $this->user->mBlockedby = $this->user->getName(); - $this->user->mBlock = new Block( [ + $this->user->mBlock = new DatabaseBlock( [ 'address' => '127.0.8.1', 'by' => $this->user->getId(), 'reason' => 'no reason given', @@ -1116,7 +1116,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase { // partial block message test $this->user->mBlockedby = $this->user->getName(); - $this->user->mBlock = new Block( [ + $this->user->mBlock = new DatabaseBlock( [ 'address' => '127.0.8.1', 'by' => $this->user->getId(), 'reason' => 'no reason given', @@ -1213,7 +1213,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase { $now = time(); $this->user->mBlockedby = $this->user->getName(); - $this->user->mBlock = new Block( [ + $this->user->mBlock = new DatabaseBlock( [ 'address' => '127.0.8.1', 'by' => $this->user->getId(), 'reason' => 'no reason given', @@ -1248,7 +1248,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase { // Block the user $blocker = $this->getTestSysop()->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'hideName' => true, 'allowUsertalk' => false, 'reason' => 'Because', @@ -1260,7 +1260,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase { // Clear cache and confirm it loaded the block properly $user->clearInstanceCache(); - $this->assertInstanceOf( Block::class, $user->getBlock( false ) ); + $this->assertInstanceOf( DatabaseBlock::class, $user->getBlock( false ) ); //$this->assertSame( $blocker->getName(), $user->blockedBy() ); //$this->assertSame( 'Because', $user->blockedFor() ); //$this->assertTrue( (bool)$user->isHidden() ); @@ -1285,7 +1285,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase { * @param bool $expect Expected result from User::isBlockedFrom() * @param array $options Additional test options: * - 'blockAllowsUTEdit': (bool, default true) Value for $wgBlockAllowsUTEdit - * - 'allowUsertalk': (bool, default false) Passed to Block::__construct() + * - 'allowUsertalk': (bool, default false) Passed to DatabaseBlock::__construct() * - 'pageRestrictions': (array|null) If non-empty, page restriction titles for the block. */ public function testIsBlockedFrom( $title, $expect, array $options = [] ) { @@ -1312,7 +1312,7 @@ class PermissionManagerTest extends MediaWikiLangTestCase { $restrictions[] = new NamespaceRestriction( 0, $ns ); } - $block = new Block( [ + $block = new DatabaseBlock( [ 'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ), 'allowUsertalk' => $options['allowUsertalk'] ?? false, 'sitewide' => !$restrictions, diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php index 1f8011d46340..e09546e7eef9 100644 --- a/tests/phpunit/includes/TitlePermissionTest.php +++ b/tests/phpunit/includes/TitlePermissionTest.php @@ -1,5 +1,6 @@ <?php +use MediaWiki\Block\DatabaseBlock; use MediaWiki\Block\Restriction\PageRestriction; use MediaWiki\Block\SystemBlock; use MediaWiki\MediaWikiServices; @@ -920,7 +921,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $prev = time(); $now = time() + 120; $this->user->mBlockedby = $this->user->getId(); - $this->user->mBlock = new Block( [ + $this->user->mBlock = new DatabaseBlock( [ 'address' => '127.0.8.1', 'by' => $this->user->getId(), 'reason' => 'no reason given', @@ -943,7 +944,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { global $wgLocalTZoffset; $wgLocalTZoffset = -60; $this->user->mBlockedby = $this->user->getName(); - $this->user->mBlock = new Block( [ + $this->user->mBlock = new DatabaseBlock( [ 'address' => '127.0.8.1', 'by' => $this->user->getId(), 'reason' => 'no reason given', @@ -989,7 +990,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { // partial block message test $this->user->mBlockedby = $this->user->getName(); - $this->user->mBlock = new Block( [ + $this->user->mBlock = new DatabaseBlock( [ 'address' => '127.0.8.1', 'by' => $this->user->getId(), 'reason' => 'no reason given', @@ -1073,7 +1074,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $now = time(); $this->user->mBlockedby = $this->user->getName(); - $this->user->mBlock = new Block( [ + $this->user->mBlock = new DatabaseBlock( [ 'address' => '127.0.8.1', 'by' => $this->user->getId(), 'reason' => 'no reason given', diff --git a/tests/phpunit/includes/actions/ActionTest.php b/tests/phpunit/includes/actions/ActionTest.php index d80d627b4fac..5ad773681dcc 100644 --- a/tests/phpunit/includes/actions/ActionTest.php +++ b/tests/phpunit/includes/actions/ActionTest.php @@ -1,5 +1,6 @@ <?php +use MediaWiki\Block\DatabaseBlock; use MediaWiki\Block\Restriction\PageRestriction; /** @@ -213,7 +214,7 @@ class ActionTest extends MediaWikiTestCase { $page = $this->getExistingTestPage(); $action = Action::factory( 'unblock', $page, $this->getContext() ); - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => $user, 'by' => $this->getTestSysop()->getUser()->getId(), 'expiry' => 'infinity', diff --git a/tests/phpunit/includes/api/ApiBaseTest.php b/tests/phpunit/includes/api/ApiBaseTest.php index 64b2cd651ccd..6a44ff359431 100644 --- a/tests/phpunit/includes/api/ApiBaseTest.php +++ b/tests/phpunit/includes/api/ApiBaseTest.php @@ -1,5 +1,6 @@ <?php +use MediaWiki\Block\DatabaseBlock; use MediaWiki\MediaWikiServices; use Wikimedia\TestingAccessWrapper; @@ -1325,7 +1326,7 @@ class ApiBaseTest extends ApiTestCase { // Has a blocked $user, so special block handling $user = $this->getMutableTestUser()->getUser(); - $block = new \Block( [ + $block = new DatabaseBlock( [ 'address' => $user->getName(), 'user' => $user->getID(), 'by' => $this->getTestSysop()->getUser()->getId(), @@ -1383,7 +1384,7 @@ class ApiBaseTest extends ApiTestCase { // Has a blocked $user, so special block handling $user = $this->getMutableTestUser()->getUser(); - $block = new \Block( [ + $block = new DatabaseBlock( [ 'address' => $user->getName(), 'user' => $user->getID(), 'by' => $this->getTestSysop()->getUser()->getId(), diff --git a/tests/phpunit/includes/api/ApiBlockInfoTraitTest.php b/tests/phpunit/includes/api/ApiBlockInfoTraitTest.php index a6e2d0de0b31..ba5c00377661 100644 --- a/tests/phpunit/includes/api/ApiBlockInfoTraitTest.php +++ b/tests/phpunit/includes/api/ApiBlockInfoTraitTest.php @@ -1,6 +1,7 @@ <?php use Wikimedia\TestingAccessWrapper; +use MediaWiki\Block\DatabaseBlock; use MediaWiki\Block\SystemBlock; /** @@ -26,11 +27,11 @@ class ApiBlockInfoTraitTest extends MediaWikiTestCase { public static function provideGetBlockDetails() { return [ 'Sitewide block' => [ - new Block(), + new DatabaseBlock(), [ 'blockpartial' => false ], ], 'Partial block' => [ - new Block( [ 'sitewide' => false ] ), + new DatabaseBlock( [ 'sitewide' => false ] ), [ 'blockpartial' => true ], ], 'System block' => [ diff --git a/tests/phpunit/includes/api/ApiBlockTest.php b/tests/phpunit/includes/api/ApiBlockTest.php index 1c5314773a73..060834fef095 100644 --- a/tests/phpunit/includes/api/ApiBlockTest.php +++ b/tests/phpunit/includes/api/ApiBlockTest.php @@ -1,5 +1,6 @@ <?php +use MediaWiki\Block\DatabaseBlock; use MediaWiki\Block\Restriction\PageRestriction; use MediaWiki\Block\Restriction\NamespaceRestriction; @@ -57,7 +58,7 @@ class ApiBlockTest extends ApiTestCase { $ret = $this->doApiRequest( array_merge( $params, $extraParams ), null, false, $blocker ); - $block = Block::newFromTarget( $this->mUser->getName() ); + $block = DatabaseBlock::newFromTarget( $this->mUser->getName() ); $this->assertTrue( !is_null( $block ), 'Block is valid' ); @@ -89,7 +90,7 @@ class ApiBlockTest extends ApiTestCase { 'You cannot block or unblock other users because you are yourself blocked.' ); $blocked = $this->getMutableTestUser( [ 'sysop' ] )->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => $blocked->getName(), 'by' => self::$users['sysop']->getUser()->getId(), 'reason' => 'Capriciousness', @@ -237,7 +238,7 @@ class ApiBlockTest extends ApiTestCase { $this->doBlock(); - $block = Block::newFromTarget( $this->mUser->getName() ); + $block = DatabaseBlock::newFromTarget( $this->mUser->getName() ); $this->assertTrue( $block->isSitewide() ); $this->assertCount( 0, $block->getRestrictions() ); @@ -258,7 +259,7 @@ class ApiBlockTest extends ApiTestCase { 'namespacerestrictions' => $namespace, ] ); - $block = Block::newFromTarget( $this->mUser->getName() ); + $block = DatabaseBlock::newFromTarget( $this->mUser->getName() ); $this->assertFalse( $block->isSitewide() ); $this->assertCount( 2, $block->getRestrictions() ); diff --git a/tests/phpunit/includes/api/ApiEditPageTest.php b/tests/phpunit/includes/api/ApiEditPageTest.php index aeb829dd621b..2045a1317bd4 100644 --- a/tests/phpunit/includes/api/ApiEditPageTest.php +++ b/tests/phpunit/includes/api/ApiEditPageTest.php @@ -1,5 +1,7 @@ <?php +use MediaWiki\Block\DatabaseBlock; + /** * Tests for MediaWiki api.php?action=edit. * @@ -1474,9 +1476,9 @@ class ApiEditPageTest extends ApiTestCase { public function testEditWhileBlocked() { $name = 'Help:' . ucfirst( __FUNCTION__ ); - $this->assertNull( Block::newFromTarget( '127.0.0.1' ), 'Sanity check' ); + $this->assertNull( DatabaseBlock::newFromTarget( '127.0.0.1' ), 'Sanity check' ); - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => self::$users['sysop']->getUser()->getName(), 'by' => self::$users['sysop']->getUser()->getId(), 'reason' => 'Capriciousness', @@ -1495,7 +1497,7 @@ class ApiEditPageTest extends ApiTestCase { $this->fail( 'Expected exception not thrown' ); } catch ( ApiUsageException $ex ) { $this->assertSame( 'You have been blocked from editing.', $ex->getMessage() ); - $this->assertNotNull( Block::newFromTarget( '127.0.0.1' ), 'Autoblock spread' ); + $this->assertNotNull( DatabaseBlock::newFromTarget( '127.0.0.1' ), 'Autoblock spread' ); } finally { $block->delete(); self::$users['sysop']->getUser()->clearInstanceCache(); diff --git a/tests/phpunit/includes/api/ApiMoveTest.php b/tests/phpunit/includes/api/ApiMoveTest.php index d437a525a068..d880923d3fd1 100644 --- a/tests/phpunit/includes/api/ApiMoveTest.php +++ b/tests/phpunit/includes/api/ApiMoveTest.php @@ -1,5 +1,7 @@ <?php +use MediaWiki\Block\DatabaseBlock; + /** * @group API * @group Database @@ -132,9 +134,9 @@ class ApiMoveTest extends ApiTestCase { } public function testMoveWhileBlocked() { - $this->assertNull( Block::newFromTarget( '127.0.0.1' ), 'Sanity check' ); + $this->assertNull( DatabaseBlock::newFromTarget( '127.0.0.1' ), 'Sanity check' ); - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => self::$users['sysop']->getUser()->getName(), 'by' => self::$users['sysop']->getUser()->getId(), 'reason' => 'Capriciousness', @@ -156,7 +158,7 @@ class ApiMoveTest extends ApiTestCase { $this->fail( 'Expected exception not thrown' ); } catch ( ApiUsageException $ex ) { $this->assertSame( 'You have been blocked from editing.', $ex->getMessage() ); - $this->assertNotNull( Block::newFromTarget( '127.0.0.1' ), 'Autoblock spread' ); + $this->assertNotNull( DatabaseBlock::newFromTarget( '127.0.0.1' ), 'Autoblock spread' ); } finally { $block->delete(); self::$users['sysop']->getUser()->clearInstanceCache(); diff --git a/tests/phpunit/includes/api/ApiQueryBlocksTest.php b/tests/phpunit/includes/api/ApiQueryBlocksTest.php index 6e0084276fcd..e2816799261b 100644 --- a/tests/phpunit/includes/api/ApiQueryBlocksTest.php +++ b/tests/phpunit/includes/api/ApiQueryBlocksTest.php @@ -1,5 +1,6 @@ <?php +use MediaWiki\Block\DatabaseBlock; use MediaWiki\Block\Restriction\PageRestriction; use MediaWiki\Block\Restriction\NamespaceRestriction; @@ -29,7 +30,7 @@ class ApiQueryBlocksTest extends ApiTestCase { $badActor = $this->getTestUser()->getUser(); $sysop = $this->getTestSysop()->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => $badActor->getName(), 'user' => $badActor->getId(), 'by' => $sysop->getId(), @@ -57,7 +58,7 @@ class ApiQueryBlocksTest extends ApiTestCase { $badActor = $this->getTestUser()->getUser(); $sysop = $this->getTestSysop()->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => $badActor->getName(), 'user' => $badActor->getId(), 'by' => $sysop->getId(), @@ -87,7 +88,7 @@ class ApiQueryBlocksTest extends ApiTestCase { $badActor = $this->getTestUser()->getUser(); $sysop = $this->getTestSysop()->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => $badActor->getName(), 'user' => $badActor->getId(), 'by' => $sysop->getId(), diff --git a/tests/phpunit/includes/api/ApiQueryInfoTest.php b/tests/phpunit/includes/api/ApiQueryInfoTest.php index 3aaad486e9ad..5da618e56354 100644 --- a/tests/phpunit/includes/api/ApiQueryInfoTest.php +++ b/tests/phpunit/includes/api/ApiQueryInfoTest.php @@ -1,5 +1,7 @@ <?php +use MediaWiki\Block\DatabaseBlock; + /** * @group API * @group medium @@ -102,7 +104,7 @@ class ApiQueryInfoTest extends ApiTestCase { $badActor = $this->getTestUser()->getUser(); $sysop = $this->getTestSysop()->getUser(); - $block = new \Block( [ + $block = new DatabaseBlock( [ 'address' => $badActor->getName(), 'user' => $badActor->getId(), 'by' => $sysop->getId(), diff --git a/tests/phpunit/includes/api/ApiQueryUserInfoTest.php b/tests/phpunit/includes/api/ApiQueryUserInfoTest.php index 703c1508d905..556818e85e16 100644 --- a/tests/phpunit/includes/api/ApiQueryUserInfoTest.php +++ b/tests/phpunit/includes/api/ApiQueryUserInfoTest.php @@ -1,5 +1,7 @@ <?php +use MediaWiki\Block\DatabaseBlock; + /** * @group medium * @covers ApiQueryUserInfo @@ -13,7 +15,7 @@ class ApiQueryUserInfoTest extends ApiTestCase { 'userinfo' ); - $block = new Block(); + $block = new DatabaseBlock(); $info = $apiQueryUserInfo->getBlockInfo( $block ); $subset = [ 'blockid' => null, @@ -34,7 +36,7 @@ class ApiQueryUserInfoTest extends ApiTestCase { 'userinfo' ); - $block = new Block( [ + $block = new DatabaseBlock( [ 'sitewide' => false, ] ); $info = $apiQueryUserInfo->getBlockInfo( $block ); diff --git a/tests/phpunit/includes/api/ApiUnblockTest.php b/tests/phpunit/includes/api/ApiUnblockTest.php index ea39da70b22e..a1754faa5877 100644 --- a/tests/phpunit/includes/api/ApiUnblockTest.php +++ b/tests/phpunit/includes/api/ApiUnblockTest.php @@ -1,5 +1,7 @@ <?php +use MediaWiki\Block\DatabaseBlock; + /** * @group API * @group Database @@ -26,24 +28,24 @@ class ApiUnblockTest extends ApiTestCase { $this->blockee = $this->getMutableTestUser()->getUser(); // Initialize a blocked user (used by most tests, although not all) - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => $this->blockee->getName(), 'by' => $this->blocker->getId(), ] ); $result = $block->insert(); $this->assertNotFalse( $result, 'Could not insert block' ); - $blockFromDB = Block::newFromID( $result['id'] ); + $blockFromDB = DatabaseBlock::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'] ); + return DatabaseBlock::newFromTarget( $params['user'] ); } if ( array_key_exists( 'userid', $params ) ) { - return Block::newFromTarget( User::newFromId( $params['userid'] ) ); + return DatabaseBlock::newFromTarget( User::newFromId( $params['userid'] ) ); } - return Block::newFromId( $params['id'] ); + return DatabaseBlock::newFromId( $params['id'] ); } /** @@ -64,7 +66,7 @@ class ApiUnblockTest extends ApiTestCase { // 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->assertInstanceOf( DatabaseBlock::class, $originalBlock, 'Block should initially exist' ); $this->assertNull( $this->getBlockFromParams( $params ), 'Block should have been removed' ); } @@ -94,7 +96,7 @@ class ApiUnblockTest extends ApiTestCase { public function testUnblockWhenBlocked() { $this->setExpectedApiException( 'ipbblocked' ); - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => $this->blocker->getName(), 'by' => $this->getTestUser( 'sysop' )->getUser()->getId(), ] ); @@ -104,7 +106,7 @@ class ApiUnblockTest extends ApiTestCase { } public function testUnblockSelfWhenBlocked() { - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => $this->blocker->getName(), 'by' => $this->getTestUser( 'sysop' )->getUser()->getId(), ] ); diff --git a/tests/phpunit/includes/api/ApiUserrightsTest.php b/tests/phpunit/includes/api/ApiUserrightsTest.php index 5889f8265ac2..a1bafed78ca4 100644 --- a/tests/phpunit/includes/api/ApiUserrightsTest.php +++ b/tests/phpunit/includes/api/ApiUserrightsTest.php @@ -1,5 +1,7 @@ <?php +use MediaWiki\Block\DatabaseBlock; + /** * @group API * @group Database @@ -128,7 +130,7 @@ class ApiUserrightsTest extends ApiTestCase { public function testBlockedWithUserrights() { global $wgUser; - $block = new Block( [ 'address' => $wgUser, 'by' => $wgUser->getId(), ] ); + $block = new DatabaseBlock( [ 'address' => $wgUser, 'by' => $wgUser->getId(), ] ); $block->insert(); try { @@ -144,7 +146,7 @@ class ApiUserrightsTest extends ApiTestCase { $this->setPermissions( true, true ); - $block = new Block( [ 'address' => $user, 'by' => $user->getId() ] ); + $block = new DatabaseBlock( [ 'address' => $user, 'by' => $user->getId() ] ); $block->insert(); try { diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php b/tests/phpunit/includes/auth/AuthManagerTest.php index 5cf93c9e2bc4..e6a1d3886c5c 100644 --- a/tests/phpunit/includes/auth/AuthManagerTest.php +++ b/tests/phpunit/includes/auth/AuthManagerTest.php @@ -3,6 +3,7 @@ namespace MediaWiki\Auth; use Config; +use MediaWiki\Block\DatabaseBlock; use MediaWiki\Session\SessionInfo; use MediaWiki\Session\UserInfo; use Psr\Log\LoggerInterface; @@ -1430,7 +1431,7 @@ class AuthManagerTest extends \MediaWikiTestCase { \TestUser::setPasswordForUser( $user, 'UTBlockeePassword' ); $user->saveSettings(); } - $oldBlock = \Block::newFromTarget( 'UTBlockee' ); + $oldBlock = DatabaseBlock::newFromTarget( 'UTBlockee' ); if ( $oldBlock ) { // An old block will prevent our new one from saving. $oldBlock->delete(); @@ -1443,7 +1444,7 @@ class AuthManagerTest extends \MediaWikiTestCase { 'expiry' => time() + 100500, 'createAccount' => true, ]; - $block = new \Block( $blockOptions ); + $block = new DatabaseBlock( $blockOptions ); $block->insert(); $status = $this->manager->checkAccountCreatePermissions( $user ); $this->assertFalse( $status->isOK() ); @@ -1456,7 +1457,7 @@ class AuthManagerTest extends \MediaWikiTestCase { 'expiry' => time() + 100500, 'createAccount' => true, ]; - $block = new \Block( $blockOptions ); + $block = new DatabaseBlock( $blockOptions ); $block->insert(); $scopeVariable = new ScopedCallback( [ $block, 'delete' ] ); $status = $this->manager->checkAccountCreatePermissions( new \User ); diff --git a/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php index 14d7f09b96d4..c38003660a00 100644 --- a/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php @@ -2,6 +2,7 @@ namespace MediaWiki\Auth; +use MediaWiki\Block\DatabaseBlock; use Wikimedia\TestingAccessWrapper; /** @@ -68,7 +69,7 @@ class CheckBlocksSecondaryAuthenticationProviderTest extends \MediaWikiTestCase \TestUser::setPasswordForUser( $user, 'UTBlockeePassword' ); $user->saveSettings(); } - $oldBlock = \Block::newFromTarget( 'UTBlockee' ); + $oldBlock = DatabaseBlock::newFromTarget( 'UTBlockee' ); if ( $oldBlock ) { // An old block will prevent our new one from saving. $oldBlock->delete(); @@ -81,7 +82,7 @@ class CheckBlocksSecondaryAuthenticationProviderTest extends \MediaWikiTestCase 'expiry' => time() + 100500, 'createAccount' => true, ]; - $block = new \Block( $blockOptions ); + $block = new DatabaseBlock( $blockOptions ); $block->insert(); return $user; } @@ -154,7 +155,7 @@ class CheckBlocksSecondaryAuthenticationProviderTest extends \MediaWikiTestCase 'expiry' => time() + 100500, 'createAccount' => true, ]; - $block = new \Block( $blockOptions ); + $block = new DatabaseBlock( $blockOptions ); $block->insert(); $scopeVariable = new \Wikimedia\ScopedCallback( [ $block, 'delete' ] ); diff --git a/tests/phpunit/includes/block/BlockManagerTest.php b/tests/phpunit/includes/block/BlockManagerTest.php index ec6eea99c90b..aec25c18c0a1 100644 --- a/tests/phpunit/includes/block/BlockManagerTest.php +++ b/tests/phpunit/includes/block/BlockManagerTest.php @@ -1,6 +1,7 @@ <?php use MediaWiki\Block\BlockManager; +use MediaWiki\Block\DatabaseBlock; /** * @group Blocking @@ -51,7 +52,7 @@ class BlockManagerTest extends MediaWikiTestCase { 'wgCookieSetOnIpBlock' => true, ] ); - $block = new Block( array_merge( [ + $block = new DatabaseBlock( array_merge( [ 'address' => $options[ 'target' ] ?: $this->user, 'by' => $this->sysopId, ], $options[ 'blockOptions' ] ) ); diff --git a/tests/phpunit/includes/block/BlockRestrictionStoreTest.php b/tests/phpunit/includes/block/BlockRestrictionStoreTest.php index 4eef45733952..ebbfde27c0ae 100644 --- a/tests/phpunit/includes/block/BlockRestrictionStoreTest.php +++ b/tests/phpunit/includes/block/BlockRestrictionStoreTest.php @@ -3,6 +3,7 @@ namespace MediaWiki\Tests\Block; use MediaWiki\Block\BlockRestrictionStore; +use MediaWiki\Block\DatabaseBlock; use MediaWiki\Block\Restriction\NamespaceRestriction; use MediaWiki\Block\Restriction\PageRestriction; use MediaWiki\Block\Restriction\Restriction; @@ -583,7 +584,7 @@ class BlockRestrictionStoreTest extends \MediaWikiLangTestCase { $badActor = $this->getTestUser()->getUser(); $sysop = $this->getTestSysop()->getUser(); - $block = new \Block( [ + $block = new DatabaseBlock( [ 'address' => $badActor->getName(), 'user' => $badActor->getId(), 'by' => $sysop->getId(), diff --git a/tests/phpunit/includes/BlockTest.php b/tests/phpunit/includes/block/DatabaseBlockTest.php index 3dc5e7843338..0ef571db739c 100644 --- a/tests/phpunit/includes/BlockTest.php +++ b/tests/phpunit/includes/block/DatabaseBlockTest.php @@ -1,6 +1,7 @@ <?php use MediaWiki\Block\BlockRestrictionStore; +use MediaWiki\Block\DatabaseBlock; use MediaWiki\Block\Restriction\PageRestriction; use MediaWiki\Block\Restriction\NamespaceRestriction; use MediaWiki\MediaWikiServices; @@ -8,8 +9,9 @@ use MediaWiki\MediaWikiServices; /** * @group Database * @group Blocking + * @coversDefaultClass \MediaWiki\Block\DatabaseBlock */ -class BlockTest extends MediaWikiLangTestCase { +class DatabaseBlockTest extends MediaWikiLangTestCase { /** * @return User @@ -26,12 +28,12 @@ class BlockTest extends MediaWikiLangTestCase { /** * @param User $user * - * @return Block + * @return DatabaseBlock * @throws MWException */ private function addBlockForUser( User $user ) { // Delete the last round's block if it's still there - $oldBlock = Block::newFromTarget( $user->getName() ); + $oldBlock = DatabaseBlock::newFromTarget( $user->getName() ); if ( $oldBlock ) { // An old block will prevent our new one from saving. $oldBlock->delete(); @@ -44,7 +46,7 @@ class BlockTest extends MediaWikiLangTestCase { 'reason' => 'Parce que', 'expiry' => time() + 100500, ]; - $block = new Block( $blockOptions ); + $block = new DatabaseBlock( $blockOptions ); $block->insert(); // save up ID for use in assertion. Since ID is an autoincrement, @@ -60,34 +62,34 @@ class BlockTest extends MediaWikiLangTestCase { } /** - * @covers Block::newFromTarget + * @covers ::newFromTarget */ public function testINewFromTargetReturnsCorrectBlock() { $user = $this->getUserForBlocking(); $block = $this->addBlockForUser( $user ); $this->assertTrue( - $block->equals( Block::newFromTarget( $user->getName() ) ), + $block->equals( DatabaseBlock::newFromTarget( $user->getName() ) ), "newFromTarget() returns the same block as the one that was made" ); } /** - * @covers Block::newFromID + * @covers ::newFromID */ public function testINewFromIDReturnsCorrectBlock() { $user = $this->getUserForBlocking(); $block = $this->addBlockForUser( $user ); $this->assertTrue( - $block->equals( Block::newFromID( $block->getId() ) ), + $block->equals( DatabaseBlock::newFromID( $block->getId() ) ), "newFromID() returns the same block as the one that was made" ); } /** * per T28425 - * @covers Block::__construct + * @covers ::__construct */ public function testT28425BlockTimestampDefaultsToTime() { $user = $this->getUserForBlocking(); @@ -104,17 +106,17 @@ class BlockTest extends MediaWikiLangTestCase { } /** - * CheckUser since being changed to use Block::newFromTarget started failing - * because the new function didn't accept empty strings like Block::load() + * CheckUser since being changed to use DatabaseBlock::newFromTarget started failing + * because the new function didn't accept empty strings like DatabaseBlock::load() * had. Regression T31116. * * @dataProvider provideT31116Data - * @covers Block::newFromTarget + * @covers ::newFromTarget */ public function testT31116NewFromTargetWithEmptyIp( $vagueTarget ) { $user = $this->getUserForBlocking(); $initialBlock = $this->addBlockForUser( $user ); - $block = Block::newFromTarget( $user->getName(), $vagueTarget ); + $block = DatabaseBlock::newFromTarget( $user->getName(), $vagueTarget ); $this->assertTrue( $initialBlock->equals( $block ), @@ -133,27 +135,27 @@ class BlockTest extends MediaWikiLangTestCase { /** * @dataProvider provideNewFromTargetRangeBlocks - * @covers Block::newFromTarget + * @covers ::newFromTarget */ public function testNewFromTargetRangeBlocks( $targets, $ip, $expectedTarget ) { $blocker = $this->getTestSysop()->getUser(); foreach ( $targets as $target ) { - $block = new Block(); + $block = new DatabaseBlock(); $block->setTarget( $target ); $block->setBlocker( $blocker ); $block->insert(); } // Should find the block with the narrowest range - $blockTarget = Block::newFromTarget( $this->getTestUser()->getUser(), $ip )->getTarget(); + $blockTarget = DatabaseBlock::newFromTarget( $this->getTestUser()->getUser(), $ip )->getTarget(); $this->assertSame( $blockTarget instanceof User ? $blockTarget->getName() : $blockTarget, $expectedTarget ); foreach ( $targets as $target ) { - $block = Block::newFromTarget( $target ); + $block = DatabaseBlock::newFromTarget( $target ); $block->delete(); } } @@ -204,7 +206,7 @@ class BlockTest extends MediaWikiLangTestCase { } /** - * @covers Block::appliesToRight + * @covers ::appliesToRight */ public function testBlockedUserCanNotCreateAccount() { $username = 'BlockedUserToCreateAccountWith'; @@ -217,7 +219,7 @@ class BlockTest extends MediaWikiLangTestCase { // Sanity check $this->assertNull( - Block::newFromTarget( $username ), + DatabaseBlock::newFromTarget( $username ), "$username should not be blocked" ); @@ -241,18 +243,18 @@ class BlockTest extends MediaWikiLangTestCase { 'blockEmail' => true, 'byText' => 'm>MetaWikiUser', ]; - $block = new Block( $blockOptions ); + $block = new DatabaseBlock( $blockOptions ); $block->insert(); // Reload block from DB - $userBlock = Block::newFromTarget( $username ); + $userBlock = DatabaseBlock::newFromTarget( $username ); $this->assertTrue( (bool)$block->appliesToRight( 'createaccount' ), "Block object in DB should block right 'createaccount'" ); $this->assertInstanceOf( - Block::class, + DatabaseBlock::class, $userBlock, "'$username' block block object should be existent" ); @@ -266,11 +268,11 @@ class BlockTest extends MediaWikiLangTestCase { } /** - * @covers Block::insert + * @covers ::insert */ public function testCrappyCrossWikiBlocks() { // Delete the last round's block if it's still there - $oldBlock = Block::newFromTarget( 'UserOnForeignWiki' ); + $oldBlock = DatabaseBlock::newFromTarget( 'UserOnForeignWiki' ); if ( $oldBlock ) { // An old block will prevent our new one from saving. $oldBlock->delete(); @@ -295,14 +297,14 @@ class BlockTest extends MediaWikiLangTestCase { 'blockEmail' => true, 'byText' => 'Meta>MetaWikiUser', ]; - $block = new Block( $blockOptions ); + $block = new DatabaseBlock( $blockOptions ); $res = $block->insert( $this->db ); $this->assertTrue( (bool)$res['id'], 'Block succeeded' ); $user = null; // clear - $block = Block::newFromID( $res['id'] ); + $block = DatabaseBlock::newFromID( $res['id'] ); $this->assertEquals( 'UserOnForeignWiki', $block->getTarget()->getName(), @@ -326,35 +328,35 @@ class BlockTest extends MediaWikiLangTestCase { $blockList = [ [ 'target' => '70.2.0.0/16', - 'type' => Block::TYPE_RANGE, + 'type' => DatabaseBlock::TYPE_RANGE, 'desc' => 'Range Hardblock', 'ACDisable' => false, 'isHardblock' => true, 'isAutoBlocking' => false, ], [ 'target' => '2001:4860:4001::/48', - 'type' => Block::TYPE_RANGE, + 'type' => DatabaseBlock::TYPE_RANGE, 'desc' => 'Range6 Hardblock', 'ACDisable' => false, 'isHardblock' => true, 'isAutoBlocking' => false, ], [ 'target' => '60.2.0.0/16', - 'type' => Block::TYPE_RANGE, + 'type' => DatabaseBlock::TYPE_RANGE, 'desc' => 'Range Softblock with AC Disabled', 'ACDisable' => true, 'isHardblock' => false, 'isAutoBlocking' => false, ], [ 'target' => '50.2.0.0/16', - 'type' => Block::TYPE_RANGE, + 'type' => DatabaseBlock::TYPE_RANGE, 'desc' => 'Range Softblock', 'ACDisable' => false, 'isHardblock' => false, 'isAutoBlocking' => false, ], [ 'target' => '50.1.1.1', - 'type' => Block::TYPE_IP, + 'type' => DatabaseBlock::TYPE_IP, 'desc' => 'Exact Softblock', 'ACDisable' => false, 'isHardblock' => false, @@ -366,13 +368,13 @@ class BlockTest extends MediaWikiLangTestCase { foreach ( $blockList as $insBlock ) { $target = $insBlock['target']; - if ( $insBlock['type'] === Block::TYPE_IP ) { + if ( $insBlock['type'] === DatabaseBlock::TYPE_IP ) { $target = User::newFromName( IP::sanitizeIP( $target ), false )->getName(); - } elseif ( $insBlock['type'] === Block::TYPE_RANGE ) { + } elseif ( $insBlock['type'] === DatabaseBlock::TYPE_RANGE ) { $target = IP::sanitizeRange( $target ); } - $block = new Block(); + $block = new DatabaseBlock(); $block->setTarget( $target ); $block->setBlocker( $blocker ); $block->setReason( $insBlock['desc'] ); @@ -431,30 +433,30 @@ class BlockTest extends MediaWikiLangTestCase { /** * @dataProvider providerXff - * @covers Block::getBlocksForIPList - * @covers Block::chooseBlock + * @covers ::getBlocksForIPList + * @covers ::chooseBlock */ public function testBlocksOnXff( $xff, $exCount, $exResult ) { $user = $this->getUserForBlocking(); $this->addBlockForUser( $user ); $list = array_map( 'trim', explode( ',', $xff ) ); - $xffblocks = Block::getBlocksForIPList( $list, true ); + $xffblocks = DatabaseBlock::getBlocksForIPList( $list, true ); $this->assertEquals( $exCount, count( $xffblocks ), 'Number of blocks for ' . $xff ); - $block = Block::chooseBlock( $xffblocks, $list ); + $block = DatabaseBlock::chooseBlock( $xffblocks, $list ); $this->assertEquals( $exResult, $block->getReason(), 'Correct block type for XFF header ' . $xff ); } /** - * @covers Block::newFromRow + * @covers ::newFromRow */ public function testNewFromRow() { $badActor = $this->getTestUser()->getUser(); $sysop = $this->getTestSysop()->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => $badActor->getName(), 'user' => $badActor->getId(), 'by' => $sysop->getId(), @@ -462,7 +464,7 @@ class BlockTest extends MediaWikiLangTestCase { ] ); $block->insert(); - $blockQuery = Block::getQueryInfo(); + $blockQuery = DatabaseBlock::getQueryInfo(); $row = $this->db->select( $blockQuery['tables'], $blockQuery['fields'], @@ -474,45 +476,45 @@ class BlockTest extends MediaWikiLangTestCase { $blockQuery['joins'] )->fetchObject(); - $block = Block::newFromRow( $row ); - $this->assertInstanceOf( Block::class, $block ); + $block = DatabaseBlock::newFromRow( $row ); + $this->assertInstanceOf( DatabaseBlock::class, $block ); $this->assertEquals( $block->getBy(), $sysop->getId() ); $this->assertEquals( $block->getTarget()->getName(), $badActor->getName() ); $block->delete(); } /** - * @covers Block::equals + * @covers ::equals */ public function testEquals() { - $block = new Block(); + $block = new DatabaseBlock(); $this->assertTrue( $block->equals( $block ) ); - $partial = new Block( [ + $partial = new DatabaseBlock( [ 'sitewide' => false, ] ); $this->assertFalse( $block->equals( $partial ) ); } /** - * @covers Block::isSitewide + * @covers ::isSitewide */ public function testIsSitewide() { - $block = new Block(); + $block = new DatabaseBlock(); $this->assertTrue( $block->isSitewide() ); - $block = new Block( [ + $block = new DatabaseBlock( [ 'sitewide' => true, ] ); $this->assertTrue( $block->isSitewide() ); - $block = new Block( [ + $block = new DatabaseBlock( [ 'sitewide' => false, ] ); $this->assertFalse( $block->isSitewide() ); - $block = new Block( [ + $block = new DatabaseBlock( [ 'sitewide' => false, ] ); $block->isSitewide( true ); @@ -520,11 +522,11 @@ class BlockTest extends MediaWikiLangTestCase { } /** - * @covers Block::getRestrictions - * @covers Block::setRestrictions + * @covers ::getRestrictions + * @covers ::setRestrictions */ public function testRestrictions() { - $block = new Block(); + $block = new DatabaseBlock(); $restrictions = [ new PageRestriction( 0, 1 ) ]; @@ -534,14 +536,14 @@ class BlockTest extends MediaWikiLangTestCase { } /** - * @covers Block::getRestrictions - * @covers Block::insert + * @covers ::getRestrictions + * @covers ::insert */ public function testRestrictionsFromDatabase() { $badActor = $this->getTestUser()->getUser(); $sysop = $this->getTestSysop()->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => $badActor->getName(), 'user' => $badActor->getId(), 'by' => $sysop->getId(), @@ -553,7 +555,7 @@ class BlockTest extends MediaWikiLangTestCase { $block->insert(); // Refresh the block from the database. - $block = Block::newFromID( $block->getId() ); + $block = DatabaseBlock::newFromID( $block->getId() ); $restrictions = $block->getRestrictions(); $this->assertCount( 1, $restrictions ); $this->assertTrue( $restriction->equals( $restrictions[0] ) ); @@ -561,13 +563,13 @@ class BlockTest extends MediaWikiLangTestCase { } /** - * @covers Block::insert + * @covers ::insert */ public function testInsertExistingBlock() { $badActor = $this->getTestUser()->getUser(); $sysop = $this->getTestSysop()->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => $badActor->getName(), 'user' => $badActor->getId(), 'by' => $sysop->getId(), @@ -596,14 +598,14 @@ class BlockTest extends MediaWikiLangTestCase { } /** - * @covers Block::appliesToTitle + * @covers ::appliesToTitle */ public function testAppliesToTitleReturnsTrueOnSitewideBlock() { $this->setMwGlobals( [ 'wgBlockDisablesLogin' => false, ] ); $user = $this->getTestUser()->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ), 'allowUsertalk' => true, 'sitewide' => true @@ -625,14 +627,14 @@ class BlockTest extends MediaWikiLangTestCase { } /** - * @covers Block::appliesToTitle + * @covers ::appliesToTitle */ public function testAppliesToTitleOnPartialBlock() { $this->setMwGlobals( [ 'wgBlockDisablesLogin' => false, ] ); $user = $this->getTestUser()->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ), 'allowUsertalk' => true, 'sitewide' => false @@ -658,15 +660,15 @@ class BlockTest extends MediaWikiLangTestCase { } /** - * @covers Block::appliesToNamespace - * @covers Block::appliesToPage + * @covers ::appliesToNamespace + * @covers ::appliesToPage */ public function testAppliesToReturnsTrueOnSitewideBlock() { $this->setMwGlobals( [ 'wgBlockDisablesLogin' => false, ] ); $user = $this->getTestUser()->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ), 'allowUsertalk' => true, 'sitewide' => true @@ -686,14 +688,14 @@ class BlockTest extends MediaWikiLangTestCase { } /** - * @covers Block::appliesToPage + * @covers ::appliesToPage */ public function testAppliesToPageOnPartialPageBlock() { $this->setMwGlobals( [ 'wgBlockDisablesLogin' => false, ] ); $user = $this->getTestUser()->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ), 'allowUsertalk' => true, 'sitewide' => false @@ -717,14 +719,14 @@ class BlockTest extends MediaWikiLangTestCase { } /** - * @covers Block::appliesToNamespace + * @covers ::appliesToNamespace */ public function testAppliesToNamespaceOnPartialNamespaceBlock() { $this->setMwGlobals( [ 'wgBlockDisablesLogin' => false, ] ); $user = $this->getTestUser()->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ), 'allowUsertalk' => true, 'sitewide' => false @@ -744,13 +746,13 @@ class BlockTest extends MediaWikiLangTestCase { } /** - * @covers Block::appliesToRight + * @covers ::appliesToRight */ public function testBlockAllowsPurge() { $this->setMwGlobals( [ 'wgBlockDisablesLogin' => false, ] ); - $block = new Block(); + $block = new DatabaseBlock(); $this->assertFalse( $block->appliesToRight( 'purge' ) ); } diff --git a/tests/phpunit/includes/specialpage/FormSpecialPageTestCase.php b/tests/phpunit/includes/specialpage/FormSpecialPageTestCase.php index a3b5adb85887..a09fd7c6935f 100644 --- a/tests/phpunit/includes/specialpage/FormSpecialPageTestCase.php +++ b/tests/phpunit/includes/specialpage/FormSpecialPageTestCase.php @@ -1,4 +1,7 @@ <?php + +use MediaWiki\Block\DatabaseBlock; + /** * Factory for handling the special page list and generating SpecialPage objects. * @@ -30,7 +33,7 @@ abstract class FormSpecialPageTestCase extends SpecialPageTestBase { $user = clone $this->getTestUser()->getUser(); $user->mBlockedby = $user->getName(); - $user->mBlock = new Block( [ + $user->mBlock = new DatabaseBlock( [ 'address' => '127.0.8.1', 'by' => $user->getId(), 'reason' => 'sitewide block', @@ -52,7 +55,7 @@ abstract class FormSpecialPageTestCase extends SpecialPageTestBase { $user = clone $this->getTestUser()->getUser(); $user->mBlockedby = $user->getName(); - $user->mBlock = new Block( [ + $user->mBlock = new DatabaseBlock( [ 'address' => '127.0.8.1', 'by' => $user->getId(), 'reason' => 'partial block', diff --git a/tests/phpunit/includes/specials/SpecialBlockTest.php b/tests/phpunit/includes/specials/SpecialBlockTest.php index c1f2e4206475..86e3295eb8e5 100644 --- a/tests/phpunit/includes/specials/SpecialBlockTest.php +++ b/tests/phpunit/includes/specials/SpecialBlockTest.php @@ -1,6 +1,7 @@ <?php use MediaWiki\Block\BlockRestrictionStore; +use MediaWiki\Block\DatabaseBlock; use MediaWiki\Block\Restriction\PageRestriction; use MediaWiki\Block\Restriction\NamespaceRestriction; use Wikimedia\TestingAccessWrapper; @@ -79,7 +80,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $block = $this->insertBlock(); // Refresh the block from the database. - $block = Block::newFromTarget( $block->getTarget() ); + $block = DatabaseBlock::newFromTarget( $block->getTarget() ); $page = $this->newSpecialPage(); @@ -109,7 +110,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $pageSaturn = $this->getExistingTestPage( 'Saturn' ); $pageMars = $this->getExistingTestPage( 'Mars' ); - $block = new \Block( [ + $block = new DatabaseBlock( [ 'address' => $badActor->getName(), 'user' => $badActor->getId(), 'by' => $sysop->getId(), @@ -129,7 +130,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $block->insert(); // Refresh the block from the database. - $block = Block::newFromTarget( $block->getTarget() ); + $block = DatabaseBlock::newFromTarget( $block->getTarget() ); $page = $this->newSpecialPage(); @@ -179,7 +180,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); - $block = Block::newFromTarget( $badActor ); + $block = DatabaseBlock::newFromTarget( $badActor ); $this->assertSame( $reason, $block->getReason() ); $this->assertSame( $expiry, $block->getExpiry() ); } @@ -196,7 +197,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $context = RequestContext::getMain(); // Create a block that will be updated. - $block = new \Block( [ + $block = new DatabaseBlock( [ 'address' => $badActor->getName(), 'user' => $badActor->getId(), 'by' => $sysop->getId(), @@ -228,7 +229,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); - $block = Block::newFromTarget( $badActor ); + $block = DatabaseBlock::newFromTarget( $badActor ); $this->assertSame( $reason, $block->getReason() ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertSame( '1', $block->isAutoblocking() ); @@ -277,7 +278,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); - $block = Block::newFromTarget( $badActor ); + $block = DatabaseBlock::newFromTarget( $badActor ); $this->assertSame( $reason, $block->getReason() ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertCount( 2, $block->getRestrictions() ); @@ -331,7 +332,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); - $block = Block::newFromTarget( $badActor ); + $block = DatabaseBlock::newFromTarget( $badActor ); $this->assertSame( $reason, $block->getReason() ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertFalse( $block->isSitewide() ); @@ -347,7 +348,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); - $block = Block::newFromTarget( $badActor ); + $block = DatabaseBlock::newFromTarget( $badActor ); $this->assertSame( $reason, $block->getReason() ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertFalse( $block->isSitewide() ); @@ -362,7 +363,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); - $block = Block::newFromTarget( $badActor ); + $block = DatabaseBlock::newFromTarget( $badActor ); $this->assertSame( $reason, $block->getReason() ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertFalse( $block->isSitewide() ); @@ -374,7 +375,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $this->assertTrue( $result ); - $block = Block::newFromTarget( $badActor ); + $block = DatabaseBlock::newFromTarget( $badActor ); $this->assertSame( $reason, $block->getReason() ); $this->assertSame( $expiry, $block->getExpiry() ); $this->assertTrue( $block->isSitewide() ); @@ -420,7 +421,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $$var = $users[$$var]; } - $block = new \Block( [ + $block = new DatabaseBlock( [ 'address' => $blockedUser->getName(), 'user' => $blockedUser->getId(), 'by' => $blockPerformer->getId(), @@ -454,7 +455,7 @@ class SpecialBlockTest extends SpecialPageTestBase { $badActor = $this->getTestUser()->getUser(); $sysop = $this->getTestSysop()->getUser(); - $block = new \Block( [ + $block = new DatabaseBlock( [ 'address' => $badActor->getName(), 'user' => $badActor->getId(), 'by' => $sysop->getId(), diff --git a/tests/phpunit/includes/specials/pagers/BlockListPagerTest.php b/tests/phpunit/includes/specials/pagers/BlockListPagerTest.php index bd37c04cd5d5..c0eadac56ebf 100644 --- a/tests/phpunit/includes/specials/pagers/BlockListPagerTest.php +++ b/tests/phpunit/includes/specials/pagers/BlockListPagerTest.php @@ -1,5 +1,6 @@ <?php +use MediaWiki\Block\DatabaseBlock; use MediaWiki\Block\Restriction\PageRestriction; use MediaWiki\Block\Restriction\NamespaceRestriction; use MediaWiki\MediaWikiServices; @@ -222,7 +223,7 @@ class BlockListPagerTest extends MediaWikiTestCase { $target = '127.0.0.1'; // Test Partial Blocks Blocks. - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => $target, 'by' => $this->getTestSysop()->getUser()->getId(), 'reason' => 'Parce que', diff --git a/tests/phpunit/includes/user/LocalIdLookupTest.php b/tests/phpunit/includes/user/LocalIdLookupTest.php index 58441f095f55..e38d77b72be4 100644 --- a/tests/phpunit/includes/user/LocalIdLookupTest.php +++ b/tests/phpunit/includes/user/LocalIdLookupTest.php @@ -1,5 +1,7 @@ <?php +use MediaWiki\Block\DatabaseBlock; + /** * @covers LocalIdLookup * @group Database @@ -20,7 +22,7 @@ class LocalIdLookupTest extends MediaWikiTestCase { $sysop = static::getTestSysop()->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => $this->localUsers[2]->getName(), 'by' => $sysop->getId(), 'reason' => __METHOD__, @@ -29,7 +31,7 @@ class LocalIdLookupTest extends MediaWikiTestCase { ] ); $block->insert(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'address' => $this->localUsers[3]->getName(), 'by' => $sysop->getId(), 'reason' => __METHOD__, diff --git a/tests/phpunit/includes/user/PasswordResetTest.php b/tests/phpunit/includes/user/PasswordResetTest.php index ca57c10b6f5a..55a29e364e69 100644 --- a/tests/phpunit/includes/user/PasswordResetTest.php +++ b/tests/phpunit/includes/user/PasswordResetTest.php @@ -1,6 +1,7 @@ <?php use MediaWiki\Auth\AuthManager; +use MediaWiki\Block\DatabaseBlock; use MediaWiki\Block\SystemBlock; /** @@ -85,7 +86,7 @@ class PasswordResetTest extends MediaWikiTestCase { 'enableEmail' => true, 'allowsAuthenticationDataChange' => true, 'canEditPrivate' => true, - 'block' => new Block( [ 'createAccount' => true ] ), + 'block' => new DatabaseBlock( [ 'createAccount' => true ] ), 'globalBlock' => null, 'isAllowed' => false, ], @@ -94,7 +95,7 @@ class PasswordResetTest extends MediaWikiTestCase { 'enableEmail' => true, 'allowsAuthenticationDataChange' => true, 'canEditPrivate' => true, - 'block' => new Block( [] ), + 'block' => new DatabaseBlock( [] ), 'globalBlock' => null, 'isAllowed' => true, ], diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php index c90e98890e13..aa6ae48ca136 100644 --- a/tests/phpunit/includes/user/UserTest.php +++ b/tests/phpunit/includes/user/UserTest.php @@ -3,6 +3,7 @@ define( 'NS_UNITTEST', 5600 ); define( 'NS_UNITTEST_TALK', 5601 ); +use MediaWiki\Block\DatabaseBlock; use MediaWiki\Block\Restriction\PageRestriction; use MediaWiki\Block\Restriction\NamespaceRestriction; use MediaWiki\Block\SystemBlock; @@ -602,7 +603,7 @@ class UserTest extends MediaWikiTestCase { $request1 = new FauxRequest(); $request1->getSession()->setUser( $user1tmp ); $expiryFiveHours = wfTimestamp() + ( 5 * 60 * 60 ); - $block = new Block( [ + $block = new DatabaseBlock( [ 'enableAutoblock' => true, 'expiry' => wfTimestamp( TS_MW, $expiryFiveHours ), ] ); @@ -616,8 +617,8 @@ class UserTest extends MediaWikiTestCase { // Confirm that the block has been applied as required. $this->assertTrue( $user1->isLoggedIn() ); - $this->assertInstanceOf( Block::class, $user1->getBlock() ); - $this->assertEquals( Block::TYPE_USER, $block->getType() ); + $this->assertInstanceOf( DatabaseBlock::class, $user1->getBlock() ); + $this->assertEquals( DatabaseBlock::TYPE_USER, $block->getType() ); $this->assertTrue( $block->isAutoblocking() ); $this->assertGreaterThanOrEqual( 1, $block->getId() ); @@ -625,7 +626,7 @@ class UserTest extends MediaWikiTestCase { $cookies = $request1->response()->getCookies(); $this->assertArrayHasKey( 'wmsitetitleBlockID', $cookies ); $this->assertEquals( $expiryFiveHours, $cookies['wmsitetitleBlockID']['expire'] ); - $cookieValue = Block::getIdFromCookieValue( $cookies['wmsitetitleBlockID']['value'] ); + $cookieValue = DatabaseBlock::getIdFromCookieValue( $cookies['wmsitetitleBlockID']['value'] ); $this->assertEquals( $block->getId(), $cookieValue ); // 2. Create a new request, set the cookies, and see if the (anon) user is blocked. @@ -637,7 +638,7 @@ class UserTest extends MediaWikiTestCase { $this->assertNotEquals( $user1->getToken(), $user2->getToken() ); $this->assertTrue( $user2->isAnon() ); $this->assertFalse( $user2->isLoggedIn() ); - $this->assertInstanceOf( Block::class, $user2->getBlock() ); + $this->assertInstanceOf( DatabaseBlock::class, $user2->getBlock() ); // Non-strict type-check. $this->assertEquals( true, $user2->getBlock()->isAutoblocking(), 'Autoblock does not work' ); // Can't directly compare the objects because of member type differences. @@ -653,7 +654,7 @@ class UserTest extends MediaWikiTestCase { $user3 = User::newFromSession( $request3 ); $user3->load(); $this->assertTrue( $user3->isLoggedIn() ); - $this->assertInstanceOf( Block::class, $user3->getBlock() ); + $this->assertInstanceOf( DatabaseBlock::class, $user3->getBlock() ); $this->assertEquals( true, $user3->getBlock()->isAutoblocking() ); // Non-strict type-check. // Clean up. @@ -682,7 +683,7 @@ class UserTest extends MediaWikiTestCase { $testUser = $this->getTestUser()->getUser(); $request1 = new FauxRequest(); $request1->getSession()->setUser( $testUser ); - $block = new Block( [ 'enableAutoblock' => true ] ); + $block = new DatabaseBlock( [ 'enableAutoblock' => true ] ); $block->setBlocker( $this->getTestSysop()->getUser() ); $block->setTarget( $testUser ); $res = $block->insert(); @@ -693,8 +694,8 @@ class UserTest extends MediaWikiTestCase { // 2. Test that the cookie IS NOT present. $this->assertTrue( $user->isLoggedIn() ); - $this->assertInstanceOf( Block::class, $user->getBlock() ); - $this->assertEquals( Block::TYPE_USER, $block->getType() ); + $this->assertInstanceOf( DatabaseBlock::class, $user->getBlock() ); + $this->assertEquals( DatabaseBlock::TYPE_USER, $block->getType() ); $this->assertTrue( $block->isAutoblocking() ); $this->assertGreaterThanOrEqual( 1, $user->getBlockId() ); $this->assertGreaterThanOrEqual( $block->getId(), $user->getBlockId() ); @@ -727,7 +728,7 @@ class UserTest extends MediaWikiTestCase { $user1Tmp = $this->getTestUser()->getUser(); $request1 = new FauxRequest(); $request1->getSession()->setUser( $user1Tmp ); - $block = new Block( [ 'enableAutoblock' => true, 'expiry' => 'infinity' ] ); + $block = new DatabaseBlock( [ 'enableAutoblock' => true, 'expiry' => 'infinity' ] ); $block->setBlocker( $this->getTestSysop()->getUser() ); $block->setTarget( $user1Tmp ); $res = $block->insert(); @@ -738,8 +739,8 @@ class UserTest extends MediaWikiTestCase { // 2. Test the cookie's expiry timestamp. $this->assertTrue( $user1->isLoggedIn() ); - $this->assertInstanceOf( Block::class, $user1->getBlock() ); - $this->assertEquals( Block::TYPE_USER, $block->getType() ); + $this->assertInstanceOf( DatabaseBlock::class, $user1->getBlock() ); + $this->assertEquals( DatabaseBlock::TYPE_USER, $block->getType() ); $this->assertTrue( $block->isAutoblocking() ); $this->assertGreaterThanOrEqual( 1, $user1->getBlockId() ); $cookies = $request1->response()->getCookies(); @@ -832,7 +833,7 @@ class UserTest extends MediaWikiTestCase { $user1tmp = $this->getTestUser()->getUser(); $request1 = new FauxRequest(); $request1->getSession()->setUser( $user1tmp ); - $block = new Block( [ 'enableAutoblock' => true ] ); + $block = new DatabaseBlock( [ 'enableAutoblock' => true ] ); $block->setBlocker( $this->getTestSysop()->getUser() ); $block->setTarget( $user1tmp ); $res = $block->insert(); @@ -877,7 +878,7 @@ class UserTest extends MediaWikiTestCase { $user1tmp = $this->getTestUser()->getUser(); $request1 = new FauxRequest(); $request1->getSession()->setUser( $user1tmp ); - $block = new Block( [ 'enableAutoblock' => true ] ); + $block = new DatabaseBlock( [ 'enableAutoblock' => true ] ); $block->setBlocker( $this->getTestSysop()->getUser() ); $block->setTarget( $user1tmp ); $res = $block->insert(); @@ -885,7 +886,7 @@ class UserTest extends MediaWikiTestCase { $user1 = User::newFromSession( $request1 ); $user1->mBlock = $block; $user1->load(); - $this->assertInstanceOf( Block::class, $user1->getBlock() ); + $this->assertInstanceOf( DatabaseBlock::class, $user1->getBlock() ); // 2. Create a new request, set the cookie to just the block ID, and the user should // still get blocked when they log in again. @@ -897,7 +898,7 @@ class UserTest extends MediaWikiTestCase { $this->assertNotEquals( $user1->getToken(), $user2->getToken() ); $this->assertTrue( $user2->isAnon() ); $this->assertFalse( $user2->isLoggedIn() ); - $this->assertInstanceOf( Block::class, $user2->getBlock() ); + $this->assertInstanceOf( DatabaseBlock::class, $user2->getBlock() ); $this->assertEquals( true, $user2->getBlock()->isAutoblocking() ); // Non-strict type-check. // Clean up. @@ -1283,7 +1284,7 @@ class UserTest extends MediaWikiTestCase { // Block the user $blocker = $this->getTestSysop()->getUser(); - $block = new Block( [ + $block = new DatabaseBlock( [ 'hideName' => true, 'allowUsertalk' => false, 'reason' => 'Because', @@ -1295,7 +1296,7 @@ class UserTest extends MediaWikiTestCase { // Clear cache and confirm it loaded the block properly $user->clearInstanceCache(); - $this->assertInstanceOf( Block::class, $user->getBlock( false ) ); + $this->assertInstanceOf( DatabaseBlock::class, $user->getBlock( false ) ); $this->assertSame( $blocker->getName(), $user->blockedBy() ); $this->assertSame( 'Because', $user->blockedFor() ); $this->assertTrue( (bool)$user->isHidden() ); @@ -1320,7 +1321,7 @@ class UserTest extends MediaWikiTestCase { * @param bool $expect Expected result from User::isBlockedFrom() * @param array $options Additional test options: * - 'blockAllowsUTEdit': (bool, default true) Value for $wgBlockAllowsUTEdit - * - 'allowUsertalk': (bool, default false) Passed to Block::__construct() + * - 'allowUsertalk': (bool, default false) Passed to DatabaseBlock::__construct() * - 'pageRestrictions': (array|null) If non-empty, page restriction titles for the block. */ public function testIsBlockedFrom( $title, $expect, array $options = [] ) { @@ -1347,7 +1348,7 @@ class UserTest extends MediaWikiTestCase { $restrictions[] = new NamespaceRestriction( 0, $ns ); } - $block = new Block( [ + $block = new DatabaseBlock( [ 'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ), 'allowUsertalk' => $options['allowUsertalk'] ?? false, 'sitewide' => !$restrictions, @@ -1456,7 +1457,7 @@ class UserTest extends MediaWikiTestCase { ] ); // setup block - $block = new Block( [ + $block = new DatabaseBlock( [ 'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 5 * 60 * 60 ) ), ] ); $block->setTarget( '1.2.3.4' ); @@ -1492,7 +1493,7 @@ class UserTest extends MediaWikiTestCase { ] ); // setup block - $block = new Block( [ + $block = new DatabaseBlock( [ 'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 5 * 60 * 60 ) ), ] ); $block->setTarget( '1.2.3.4' ); @@ -1529,7 +1530,7 @@ class UserTest extends MediaWikiTestCase { ] ); // setup block - $block = new Block( [ + $block = new DatabaseBlock( [ 'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ), ] ); $block->setTarget( '1.2.3.4' ); |