diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Specials/Admin/DisposeJobTaskHandlerTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Specials/Admin/DisposeJobTaskHandlerTest.php | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Specials/Admin/DisposeJobTaskHandlerTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Specials/Admin/DisposeJobTaskHandlerTest.php new file mode 100644 index 00000000..de961220 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Specials/Admin/DisposeJobTaskHandlerTest.php @@ -0,0 +1,152 @@ +<?php + +namespace SMW\Tests\MediaWiki\Specials\Admin; + +use SMW\MediaWiki\Specials\Admin\DisposeJobTaskHandler; +use SMW\Tests\TestEnvironment; + +/** + * @covers \SMW\MediaWiki\Specials\Admin\DisposeJobTaskHandler + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 2.5 + * + * @author mwjames + */ +class DisposeJobTaskHandlerTest extends \PHPUnit_Framework_TestCase { + + private $testEnvironment; + private $htmlFormRenderer; + private $outputFormatter; + private $jobQueue; + + protected function setUp() { + parent::setUp(); + + $this->testEnvironment = new TestEnvironment(); + + $this->htmlFormRenderer = $this->getMockBuilder( '\SMW\MediaWiki\Renderer\HtmlFormRenderer' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->outputFormatter = $this->getMockBuilder( '\SMW\MediaWiki\Specials\Admin\OutputFormatter' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->jobQueue = $this->getMockBuilder( '\SMW\MediaWiki\JobQueue' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->testEnvironment->registerObject( 'JobQueue', $this->jobQueue ); + } + + protected function tearDown() { + $this->testEnvironment->tearDown(); + parent::tearDown(); + } + + public function testCanConstruct() { + + $this->assertInstanceOf( + '\SMW\MediaWiki\Specials\Admin\DisposeJobTaskHandler', + new DisposeJobTaskHandler( $this->htmlFormRenderer, $this->outputFormatter ) + ); + } + + public function testGetHtml() { + + $methods = [ + 'setName', + 'setMethod', + 'addHiddenField', + 'addHeader', + 'addParagraph', + 'addSubmitButton' + ]; + + foreach ( $methods as $method ) { + $this->htmlFormRenderer->expects( $this->any() ) + ->method( $method ) + ->will( $this->returnSelf() ); + } + + $this->htmlFormRenderer->expects( $this->atLeastOnce() ) + ->method( 'getForm' ); + + $instance = new DisposeJobTaskHandler( + $this->htmlFormRenderer, + $this->outputFormatter + ); + + $instance->getHtml(); + } + + public function testHandleRequestOnNonPendingJob() { + + $this->jobQueue->expects( $this->once() ) + ->method( 'hasPendingJob' ) + ->with( $this->equalTo( 'smw.entityIdDisposer' ) ) + ->will( $this->returnValue( false ) ); + + $entityIdDisposerJob = $this->getMockBuilder( '\SMW\MediaWiki\Jobs\EntityIdDisposerJob' ) + ->disableOriginalConstructor() + ->getMock(); + + $entityIdDisposerJob->expects( $this->once() ) + ->method( 'insert' ); + + $jobFactory = $this->getMockBuilder( '\SMW\MediaWiki\JobFactory' ) + ->disableOriginalConstructor() + ->getMock(); + + $jobFactory->expects( $this->once() ) + ->method( 'newByType' ) + ->will( $this->returnValue( $entityIdDisposerJob ) ); + + $this->testEnvironment->registerObject( 'JobFactory', $jobFactory ); + + $webRequest = $this->getMockBuilder( '\WebRequest' ) + ->disableOriginalConstructor() + ->getMock(); + + $instance = new DisposeJobTaskHandler( + $this->htmlFormRenderer, + $this->outputFormatter + ); + + $instance->isApiTask = false; + $instance->setEnabledFeatures( SMW_ADM_DISPOSAL ); + $instance->handleRequest( $webRequest ); + } + + public function testHandleRequestOnPendingJob() { + + $this->jobQueue->expects( $this->once() ) + ->method( 'hasPendingJob' ) + ->with( $this->equalTo( 'smw.entityIdDisposer' ) ) + ->will( $this->returnValue( true ) ); + + $jobFactory = $this->getMockBuilder( '\SMW\MediaWiki\JobFactory' ) + ->disableOriginalConstructor() + ->getMock(); + + $jobFactory->expects( $this->never() ) + ->method( 'newByType' ); + + $this->testEnvironment->registerObject( 'JobFactory', $jobFactory ); + + $webRequest = $this->getMockBuilder( '\WebRequest' ) + ->disableOriginalConstructor() + ->getMock(); + + $instance = new DisposeJobTaskHandler( + $this->htmlFormRenderer, + $this->outputFormatter + ); + + $instance->setEnabledFeatures( SMW_ADM_DISPOSAL ); + $instance->handleRequest( $webRequest ); + } + +} |