maintenance: Script to rename titles for Unicode uppercasing changes
[lhc/web/wiklou.git] / tests / phpunit / includes / BlockTest.php
index f20481b..df3de4a 100644 (file)
@@ -1,8 +1,9 @@
 <?php
 
-use MediaWiki\Block\BlockRestriction;
+use MediaWiki\Block\BlockRestrictionStore;
 use MediaWiki\Block\Restriction\PageRestriction;
 use MediaWiki\Block\Restriction\NamespaceRestriction;
+use MediaWiki\MediaWikiServices;
 
 /**
  * @group Database
@@ -94,7 +95,7 @@ class BlockTest extends MediaWikiLangTestCase {
                $madeAt = wfTimestamp( TS_MW );
 
                // delta to stop one-off errors when things happen to go over a second mark.
-               $delta = abs( $madeAt - $block->mTimestamp );
+               $delta = abs( $madeAt - $block->getTimestamp() );
                $this->assertLessThan(
                        2,
                        $delta,
@@ -131,7 +132,7 @@ class BlockTest extends MediaWikiLangTestCase {
        }
 
        /**
-        * @covers Block::prevents
+        * @covers Block::appliesToRight
         */
        public function testBlockedUserCanNotCreateAccount() {
                $username = 'BlockedUserToCreateAccountWith';
@@ -174,8 +175,8 @@ class BlockTest extends MediaWikiLangTestCase {
                // Reload block from DB
                $userBlock = Block::newFromTarget( $username );
                $this->assertTrue(
-                       (bool)$block->prevents( 'createaccount' ),
-                       "Block object in DB should prevents 'createaccount'"
+                       (bool)$block->appliesToRight( 'createaccount' ),
+                       "Block object in DB should block right 'createaccount'"
                );
 
                $this->assertInstanceOf(
@@ -302,9 +303,9 @@ class BlockTest extends MediaWikiLangTestCase {
                        $block = new Block();
                        $block->setTarget( $target );
                        $block->setBlocker( $blocker );
-                       $block->mReason = $insBlock['desc'];
-                       $block->mExpiry = 'infinity';
-                       $block->prevents( 'createaccount', $insBlock['ACDisable'] );
+                       $block->setReason( $insBlock['desc'] );
+                       $block->setExpiry( 'infinity' );
+                       $block->isCreateAccountBlocked( $insBlock['ACDisable'] );
                        $block->isHardblock( $insBlock['isHardblock'] );
                        $block->isAutoblocking( $insBlock['isAutoBlocking'] );
                        $block->insert();
@@ -369,61 +370,8 @@ class BlockTest extends MediaWikiLangTestCase {
                $xffblocks = Block::getBlocksForIPList( $list, true );
                $this->assertEquals( $exCount, count( $xffblocks ), 'Number of blocks for ' . $xff );
                $block = Block::chooseBlock( $xffblocks, $list );
-               $this->assertEquals( $exResult, $block->mReason, 'Correct block type for XFF header ' . $xff );
-       }
-
-       /**
-        * @covers Block::__construct
-        */
-       public function testDeprecatedConstructor() {
-               $this->hideDeprecated( 'Block::__construct with multiple arguments' );
-               $username = 'UnthinkablySecretRandomUsername';
-               $reason = 'being irrational';
-
-               # Set up the target
-               $u = User::newFromName( $username );
-               if ( $u->getId() == 0 ) {
-                       $u->addToDatabase();
-                       TestUser::setPasswordForUser( $u, 'TotallyObvious' );
-               }
-               unset( $u );
-
-               # Make sure the user isn't blocked
-               $this->assertNull(
-                       Block::newFromTarget( $username ),
-                       "$username should not be blocked"
-               );
-
-               # Perform the block
-               $block = new Block(
-                       /* address */ $username,
-                       /* user */ 0,
-                       /* by */ $this->getTestSysop()->getUser()->getId(),
-                       /* reason */ $reason,
-                       /* timestamp */ 0,
-                       /* auto */ false,
-                       /* expiry */ 0
-               );
-               $block->insert();
-
-               # Check target
-               $this->assertEquals(
-                       $block->getTarget()->getName(),
-                       $username,
-                       "Target should be set properly"
-               );
-
-               # Check supplied parameter
                $this->assertEquals(
-                       $block->mReason,
-                       $reason,
-                       "Reason should be non-default"
-               );
-
-               # Check default parameter
-               $this->assertFalse(
-                       (bool)$block->prevents( 'createaccount' ),
-                       "Account creation should not be blocked by default"
+                       $exResult, $block->getReason(), 'Correct block type for XFF header ' . $xff
                );
        }
 
@@ -665,7 +613,7 @@ class BlockTest extends MediaWikiLangTestCase {
 
                $pageRestriction = new PageRestriction( $block->getId(), $pageFoo->getId() );
                $namespaceRestriction = new NamespaceRestriction( $block->getId(), NS_USER );
-               BlockRestriction::insert( [ $pageRestriction, $namespaceRestriction ] );
+               $this->getBlockRestrictionStore()->insert( [ $pageRestriction, $namespaceRestriction ] );
 
                $this->assertTrue( $block->appliesToTitle( $pageFoo->getTitle() ) );
                $this->assertFalse( $block->appliesToTitle( $pageBar->getTitle() ) );
@@ -726,7 +674,7 @@ class BlockTest extends MediaWikiLangTestCase {
                        $block->getId(),
                        $title->getArticleID()
                );
-               BlockRestriction::insert( [ $pageRestriction ] );
+               $this->getBlockRestrictionStore()->insert( [ $pageRestriction ] );
 
                $this->assertTrue( $block->appliesToPage( $title->getArticleID() ) );
 
@@ -752,7 +700,7 @@ class BlockTest extends MediaWikiLangTestCase {
                $block->insert();
 
                $namespaceRestriction = new NamespaceRestriction( $block->getId(), NS_MAIN );
-               BlockRestriction::insert( [ $namespaceRestriction ] );
+               $this->getBlockRestrictionStore()->insert( [ $namespaceRestriction ] );
 
                $this->assertTrue( $block->appliesToNamespace( NS_MAIN ) );
                $this->assertFalse( $block->appliesToNamespace( NS_USER ) );
@@ -761,14 +709,22 @@ class BlockTest extends MediaWikiLangTestCase {
        }
 
        /**
-        * @covers Block::prevents
+        * @covers Block::appliesToRight
         */
        public function testBlockAllowsPurge() {
                $this->setMwGlobals( [
                        'wgBlockDisablesLogin' => false,
                ] );
                $block = new Block();
-               $this->assertFalse( $block->prevents( 'purge' ) );
+               $this->assertFalse( $block->appliesToRight( 'purge' ) );
        }
 
+       /**
+        * Get an instance of BlockRestrictionStore
+        *
+        * @return BlockRestrictionStore
+        */
+       protected function getBlockRestrictionStore() : BlockRestrictionStore {
+               return MediaWikiServices::getInstance()->getBlockRestrictionStore();
+       }
 }