Validate sort order in Special:Search
[lhc/web/wiklou.git] / tests / phpunit / includes / specials / SpecialBlockTest.php
index 182ca0d..86e3295 100644 (file)
@@ -1,9 +1,11 @@
 <?php
 
-use MediaWiki\Block\BlockRestriction;
+use MediaWiki\Block\BlockRestrictionStore;
+use MediaWiki\Block\DatabaseBlock;
 use MediaWiki\Block\Restriction\PageRestriction;
 use MediaWiki\Block\Restriction\NamespaceRestriction;
 use Wikimedia\TestingAccessWrapper;
+use Wikimedia\Rdbms\LoadBalancer;
 
 /**
  * @group Blocking
@@ -78,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();
 
@@ -108,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(),
@@ -128,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();
 
@@ -178,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() );
        }
@@ -195,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(),
@@ -227,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() );
@@ -276,11 +278,11 @@ 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() );
-               $this->assertTrue( BlockRestriction::equals( $block->getRestrictions(), [
+               $this->assertTrue( $this->getBlockRestrictionStore()->equals( $block->getRestrictions(), [
                        new PageRestriction( $block->getId(), $pageMars->getId() ),
                        new PageRestriction( $block->getId(), $pageSaturn->getId() ),
                ] ) );
@@ -330,12 +332,12 @@ 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() );
                $this->assertCount( 2, $block->getRestrictions() );
-               $this->assertTrue( BlockRestriction::equals( $block->getRestrictions(), [
+               $this->assertTrue( $this->getBlockRestrictionStore()->equals( $block->getRestrictions(), [
                        new PageRestriction( $block->getId(), $pageMars->getId() ),
                        new PageRestriction( $block->getId(), $pageSaturn->getId() ),
                ] ) );
@@ -346,12 +348,12 @@ 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() );
                $this->assertCount( 1, $block->getRestrictions() );
-               $this->assertTrue( BlockRestriction::equals( $block->getRestrictions(), [
+               $this->assertTrue( $this->getBlockRestrictionStore()->equals( $block->getRestrictions(), [
                        new PageRestriction( $block->getId(), $pageMars->getId() ),
                ] ) );
 
@@ -361,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() );
@@ -373,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() );
@@ -419,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(),
@@ -453,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(),
@@ -471,4 +473,17 @@ class SpecialBlockTest extends SpecialPageTestBase {
                $this->db->delete( 'ipblocks', '*', __METHOD__ );
                $this->db->delete( 'ipblocks_restrictions', '*', __METHOD__ );
        }
+
+       /**
+        * Get a BlockRestrictionStore instance
+        *
+        * @return BlockRestrictionStore
+        */
+       private function getBlockRestrictionStore() : BlockRestrictionStore {
+               $loadBalancer = $this->getMockBuilder( LoadBalancer::class )
+                                          ->disableOriginalConstructor()
+                                          ->getMock();
+
+               return new BlockRestrictionStore( $loadBalancer );
+       }
 }