summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Specials/Admin/EntityLookupTaskHandlerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Specials/Admin/EntityLookupTaskHandlerTest.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Specials/Admin/EntityLookupTaskHandlerTest.php222
1 files changed, 222 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Specials/Admin/EntityLookupTaskHandlerTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Specials/Admin/EntityLookupTaskHandlerTest.php
new file mode 100644
index 00000000..65927031
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Specials/Admin/EntityLookupTaskHandlerTest.php
@@ -0,0 +1,222 @@
+<?php
+
+namespace SMW\Tests\MediaWiki\Specials\Admin;
+
+use SMW\MediaWiki\Specials\Admin\EntityLookupTaskHandler;
+use SMW\Tests\TestEnvironment;
+
+/**
+ * @covers \SMW\MediaWiki\Specials\Admin\EntityLookupTaskHandler
+ * @group semantic-mediawiki
+ *
+ * @license GNU GPL v2+
+ * @since 2.5
+ *
+ * @author mwjames
+ */
+class EntityLookupTaskHandlerTest extends \PHPUnit_Framework_TestCase {
+
+ private $testEnvironment;
+ private $store;
+ private $connection;
+ private $htmlFormRenderer;
+ private $outputFormatter;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->testEnvironment = new TestEnvironment();
+
+ $this->connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->store = $this->getMockBuilder( '\SMW\Store' )
+ ->disableOriginalConstructor()
+ ->setMethods( [ 'getConnection' ] )
+ ->getMockForAbstractClass();
+
+ $this->store->expects( $this->any() )
+ ->method( 'getConnection' )
+ ->will( $this->returnValue( $this->connection ) );
+
+ $this->htmlFormRenderer = $this->getMockBuilder( '\SMW\MediaWiki\Renderer\HtmlFormRenderer' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->outputFormatter = $this->getMockBuilder( '\SMW\MediaWiki\Specials\Admin\OutputFormatter' )
+ ->disableOriginalConstructor()
+ ->getMock();
+ }
+
+ protected function tearDown() {
+ $this->testEnvironment->tearDown();
+ parent::tearDown();
+ }
+
+ public function testCanConstruct() {
+
+ $this->assertInstanceOf(
+ '\SMW\MediaWiki\Specials\Admin\EntityLookupTaskHandler',
+ new EntityLookupTaskHandler( $this->store, $this->htmlFormRenderer, $this->outputFormatter )
+ );
+ }
+
+ public function testGetHml() {
+
+ $this->outputFormatter->expects( $this->any() )
+ ->method( 'getSpecialPageLinkWith' )
+ ->with(
+ $this->anything(),
+ $this->equalTo( [ 'action' => 'lookup' ] ) );
+
+ $instance = new EntityLookupTaskHandler(
+ $this->store,
+ $this->htmlFormRenderer,
+ $this->outputFormatter
+ );
+
+ $this->assertInternalType(
+ 'string',
+ $instance->getHtml()
+ );
+ }
+
+ public function testPerformAction() {
+
+ $methods = [
+ 'setName',
+ 'setMethod',
+ 'addHiddenField',
+ 'addHeader',
+ 'addParagraph',
+ 'addInputField',
+ 'addSubmitButton',
+ 'addNonBreakingSpace',
+ 'addCheckbox'
+ ];
+
+ foreach ( $methods as $method ) {
+ $this->htmlFormRenderer->expects( $this->any() )
+ ->method( $method )
+ ->will( $this->returnSelf() );
+ }
+
+ $this->htmlFormRenderer->expects( $this->atLeastOnce() )
+ ->method( 'getForm' );
+
+ $instance = new EntityLookupTaskHandler(
+ $this->store,
+ $this->htmlFormRenderer,
+ $this->outputFormatter
+ );
+
+ $user = $this->getMockBuilder( '\User' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $user->expects( $this->atLeastOnce() )
+ ->method( 'matchEditToken' )
+ ->will( $this->returnValue( true ) );
+
+ $instance->setUser(
+ $user
+ );
+
+ $webRequest = $this->getMockBuilder( '\WebRequest' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $instance->handleRequest( $webRequest );
+ }
+
+ public function testPerformActionWithId() {
+
+ $this->connection->expects( $this->any() )
+ ->method( 'select' )
+ ->will( $this->returnValue( [] ) );
+
+ $manualEntryLogger = $this->getMockBuilder( '\SMW\MediaWiki\ManualEntryLogger' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $manualEntryLogger->expects( $this->once() )
+ ->method( 'log' );
+
+ $this->testEnvironment->registerObject( 'ManualEntryLogger', $manualEntryLogger );
+
+ $entityIdDisposerJob = $this->getMockBuilder( '\SMW\MediaWiki\Jobs\EntityIdDisposerJob' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $jobFactory = $this->getMockBuilder( '\SMW\MediaWiki\JobFactory' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $jobFactory->expects( $this->atLeastOnce() )
+ ->method( 'newEntityIdDisposerJob' )
+ ->will( $this->returnValue( $entityIdDisposerJob ) );
+
+ $this->testEnvironment->registerObject( 'JobFactory', $jobFactory );
+
+ $methods = [
+ 'setName',
+ 'setMethod',
+ 'addHiddenField',
+ 'addHeader',
+ 'addParagraph',
+ 'addInputField',
+ 'addSubmitButton',
+ 'addNonBreakingSpace',
+ 'addCheckbox'
+ ];
+
+ foreach ( $methods as $method ) {
+ $this->htmlFormRenderer->expects( $this->any() )
+ ->method( $method )
+ ->will( $this->returnSelf() );
+ }
+
+ $this->htmlFormRenderer->expects( $this->atLeastOnce() )
+ ->method( 'getForm' );
+
+ $user = $this->getMockBuilder( '\User' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $user->expects( $this->atLeastOnce() )
+ ->method( 'matchEditToken' )
+ ->will( $this->returnValue( true ) );
+
+ $webRequest = $this->getMockBuilder( '\WebRequest' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $webRequest->expects( $this->at( 1 ) )
+ ->method( 'getText' )
+ ->with( $this->equalTo( 'id' ) )
+ ->will( $this->returnValue( 42 ) );
+
+ $webRequest->expects( $this->at( 2 ) )
+ ->method( 'getText' )
+ ->with( $this->equalTo( 'dispose' ) )
+ ->will( $this->returnValue( 'yes' ) );
+
+ $webRequest->expects( $this->at( 3 ) )
+ ->method( 'getText' )
+ ->with( $this->equalTo( 'action' ) )
+ ->will( $this->returnValue( 'lookup' ) );
+
+ $instance = new EntityLookupTaskHandler(
+ $this->store,
+ $this->htmlFormRenderer,
+ $this->outputFormatter
+ );
+
+ $instance->setEnabledFeatures( SMW_ADM_DISPOSAL );
+ $instance->setUser( $user );
+
+ $instance->handleRequest( $webRequest );
+ }
+
+}