diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Api/Browse/SubjectLookupTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Api/Browse/SubjectLookupTest.php | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Api/Browse/SubjectLookupTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Api/Browse/SubjectLookupTest.php new file mode 100644 index 00000000..85082f33 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/MediaWiki/Api/Browse/SubjectLookupTest.php @@ -0,0 +1,110 @@ +<?php + +namespace SMW\Tests\MediaWiki\Api\Browse; + +use SMW\DIProperty; +use SMW\MediaWiki\Api\Browse\SubjectLookup; + +/** + * @covers \SMW\MediaWiki\Api\Browse\SubjectLookup + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 3.0 + * + * @author mwjames + */ +class SubjectLookupTest extends \PHPUnit_Framework_TestCase { + + private $store; + + protected function setUp() { + + $this->store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) + ->disableOriginalConstructor() + ->getMock(); + } + + public function testCanConstruct() { + + $this->assertInstanceOf( + SubjectLookup::class, + new SubjectLookup( $this->store ) + ); + } + + public function testLookup_HTML() { + + $semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) + ->disableOriginalConstructor() + ->getMock(); + + $semanticData->expects( $this->any() ) + ->method( 'getProperties' ) + ->will( $this->returnValue( [] ) ); + + $this->store->expects( $this->any() ) + ->method( 'getSemanticData' ) + ->will( $this->returnValue( $semanticData ) ); + + $instance = new SubjectLookup( + $this->store + ); + + $parameters = [ + 'subject' => 'Foo', + 'ns' => NS_MAIN, + 'options' => [], + 'type' => 'html' + ]; + + $res = $instance->lookup( $parameters ); + + $this->assertArrayHasKey( + 'query', + $res + ); + + $this->assertArrayHasKey( + 'meta', + $res + ); + } + + public function testLookup_JSON() { + + $semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) + ->disableOriginalConstructor() + ->getMock(); + + $semanticData->expects( $this->any() ) + ->method( 'getProperties' ) + ->will( $this->returnValue( [] ) ); + + $this->store->expects( $this->any() ) + ->method( 'getSemanticData' ) + ->will( $this->returnValue( $semanticData ) ); + + $instance = new SubjectLookup( + $this->store + ); + + $parameters = [ + 'subject' => 'Foo', + 'ns' => NS_MAIN + ]; + + $res = $instance->lookup( $parameters ); + + $this->assertArrayHasKey( + 'query', + $res + ); + + $this->assertArrayHasKey( + 'meta', + $res + ); + } + +} |