outputFormatter = $this->getMockBuilder( '\SMW\MediaWiki\Specials\Admin\OutputFormatter' ) ->disableOriginalConstructor() ->getMock(); $this->webRequest = $this->getMockBuilder( '\MediaWiki\Request\WebRequest' ) ->disableOriginalConstructor() ->getMock(); $this->store = $this->getMockBuilder( '\SMW\Store' ) ->disableOriginalConstructor() ->setMethods( [ 'getConnection' ] ) ->getMockForAbstractClass(); $this->store->expects( $this->any() ) ->method( 'getConnection' ) ->willReturn( new DummyClient() ); } public function testCanConstruct() { $this->assertInstanceOf( ElasticClientTaskHandler::class, new ElasticClientTaskHandler( $this->outputFormatter ) ); } public function testIsTask() { $task = $this->getMockBuilder( '\SMW\MediaWiki\Specials\Admin\ActionableTask' ) ->disableOriginalConstructor() ->getMock(); $task->expects( $this->once() ) ->method( 'getTask' ) ->willReturn( 'Foo' ); $instance = new ElasticClientTaskHandler( $this->outputFormatter, [ $task ] ); $this->assertTrue( $instance->isTaskFor( 'Foo' ) ); } public function testGetHtml_OnAvailableNodes() { $this->outputFormatter->expects( $this->once() ) ->method( 'createSpecialPageLink' ); $client = $this->getMockBuilder( '\SMW\Elastic\Connection\DummyClient' ) ->disableOriginalConstructor() ->getMock(); $client->expects( $this->any() ) ->method( 'ping' ) ->willReturn( true ); $store = $this->getMockBuilder( '\SMW\Store' ) ->disableOriginalConstructor() ->setMethods( [ 'getConnection' ] ) ->getMockForAbstractClass(); $store->expects( $this->any() ) ->method( 'getConnection' ) ->willReturn( $client ); $instance = new ElasticClientTaskHandler( $this->outputFormatter ); $instance->setStore( $store ); $this->assertIsString( $instance->getHtml() ); } public function testHandleRequest_OnNoAvailableNodes() { $this->outputFormatter->expects( $this->once() ) ->method( 'addParentLink' ) ->with( [ 'tab' => 'supplement' ] ); $instance = new ElasticClientTaskHandler( $this->outputFormatter ); $instance->setStore( $this->store ); $instance->handleRequest( $this->webRequest ); } }