Merge "Update ObjectFactory and ConvertibleTimestamp"
[lhc/web/wiklou.git] / tests / phpunit / includes / block / BlockManagerTest.php
index 39a5534..40fe4c8 100644 (file)
@@ -2,6 +2,7 @@
 
 use MediaWiki\Block\BlockManager;
 use MediaWiki\Block\DatabaseBlock;
+use MediaWiki\Block\SystemBlock;
 
 /**
  * @group Blocking
@@ -288,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 ) ) );
+       }
 }