lockmanager: disable internal QuorumLockManager methods that should never be reached
[lhc/web/wiklou.git] / tests / phpunit / includes / block / BlockManagerTest.php
index ec6eea9..40fe4c8 100644 (file)
@@ -1,6 +1,8 @@
 <?php
 
 use MediaWiki\Block\BlockManager;
+use MediaWiki\Block\DatabaseBlock;
+use MediaWiki\Block\SystemBlock;
 
 /**
  * @group Blocking
@@ -28,6 +30,7 @@ class BlockManagerTest extends MediaWikiTestCase {
                        'wgEnableDnsBlacklist' => true,
                        'wgProxyList' => [],
                        'wgProxyWhitelist' => [],
+                       'wgSecretKey' => false,
                        'wgSoftBlockRanges' => [],
                ];
        }
@@ -51,7 +54,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' ] ) );
@@ -286,4 +289,38 @@ class BlockManagerTest extends MediaWikiTestCase {
                        ],
                ];
        }
+
+       /**
+        * @covers ::getUniqueBlocks
+        */
+       public function testGetUniqueBlocks() {
+               $blockId = 100;
+
+               $class = new ReflectionClass( BlockManager::class );
+               $method = $class->getMethod( 'getUniqueBlocks' );
+               $method->setAccessible( true );
+
+               $blockManager = $this->getBlockManager( [] );
+
+               $block = $this->getMockBuilder( DatabaseBlock::class )
+                       ->setMethods( [ 'getId' ] )
+                       ->getMock();
+               $block->expects( $this->any() )
+                       ->method( 'getId' )
+                       ->willReturn( $blockId );
+
+               $autoblock = $this->getMockBuilder( DatabaseBlock::class )
+                       ->setMethods( [ 'getParentBlockId', 'getType' ] )
+                       ->getMock();
+               $autoblock->expects( $this->any() )
+                       ->method( 'getParentBlockId' )
+                       ->willReturn( $blockId );
+               $autoblock->expects( $this->any() )
+                       ->method( 'getType' )
+                       ->willReturn( DatabaseBlock::TYPE_AUTO );
+
+               $blocks = [ $block, $block, $autoblock, new SystemBlock() ];
+
+               $this->assertSame( 2, count( $method->invoke( $blockManager, $blocks ) ) );
+       }
 }