diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/DescriptionInterpreters/ClassDescriptionInterpreterTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/DescriptionInterpreters/ClassDescriptionInterpreterTest.php | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/DescriptionInterpreters/ClassDescriptionInterpreterTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/DescriptionInterpreters/ClassDescriptionInterpreterTest.php new file mode 100644 index 00000000..5489db9f --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/DescriptionInterpreters/ClassDescriptionInterpreterTest.php @@ -0,0 +1,132 @@ +<?php + +namespace SMW\Tests\SQLStore\QueryEngine\DescriptionInterpreters; + +use SMW\DataItemFactory; +use SMW\Query\DescriptionFactory; +use SMW\SQLStore\QueryEngine\DescriptionInterpreters\ClassDescriptionInterpreter; +use SMW\SQLStore\QueryEngineFactory; +use SMW\Tests\TestEnvironment; + +/** + * @covers \SMW\SQLStore\QueryEngine\DescriptionInterpreters\ClassDescriptionInterpreter + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 2.2 + * + * @author mwjames + */ +class ClassDescriptionInterpreterTest extends \PHPUnit_Framework_TestCase { + + private $querySegmentValidator; + + protected function setUp() { + parent::setUp(); + + $testEnvironment = new TestEnvironment(); + $this->querySegmentValidator = $testEnvironment->getUtilityFactory()->newValidatorFactory()->newQuerySegmentValidator(); + } + + public function testCanConstruct() { + + $querySegmentListBuilder = $this->getMockBuilder( '\SMW\SQLStore\QueryEngine\QuerySegmentListBuilder' ) + ->disableOriginalConstructor() + ->getMock(); + + $this->assertInstanceOf( + '\SMW\SQLStore\QueryEngine\DescriptionInterpreters\ClassDescriptionInterpreter', + new ClassDescriptionInterpreter( $querySegmentListBuilder ) + ); + } + + /** + * @dataProvider descriptionProvider + */ + public function testCompileDescription( $description, $pageId, $expected ) { + + $objectIds = $this->getMockBuilder( '\stdClass' ) + ->setMethods( [ 'getSMWPageID' ] ) + ->getMock(); + + $objectIds->expects( $this->any() ) + ->method( 'getSMWPageID' ) + ->will( $this->returnValue( $pageId ) ); + + $connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) + ->disableOriginalConstructor() + ->getMock(); + + $store = $this->getMockBuilder( '\SMW\SQLStore\SQLStore' ) + ->disableOriginalConstructor() + ->getMock(); + + $store->expects( $this->any() ) + ->method( 'getConnection' ) + ->will( $this->returnValue( $connection ) ); + + $store->expects( $this->any() ) + ->method( 'getObjectIds' ) + ->will( $this->returnValue( $objectIds ) ); + + $queryEngineFactory = new QueryEngineFactory( $store ); + + $instance = new ClassDescriptionInterpreter( + $queryEngineFactory->newQuerySegmentListBuilder() + ); + + $this->assertTrue( + $instance->canInterpretDescription( $description ) + ); + + $this->querySegmentValidator->assertThatContainerHasProperties( + $expected, + $instance->interpretDescription( $description ) + ); + } + + public function descriptionProvider() { + + $descriptionFactory = new DescriptionFactory(); + $dataItemFactory = new DataItemFactory(); + + #0 + $pageId = 42; + + $description = $descriptionFactory->newClassDescription( + $dataItemFactory->newDIWikiPage( 'Foo', NS_CATEGORY ) + ); + + $expected = new \stdClass; + $expected->type = 1; + $expected->components = [ 1 => "t0.o_id" ]; + $expected->joinfield = "t0.s_id"; + + $provider[] = [ + $description, + $pageId, + $expected + ]; + + #1 Empty + $pageId = 0; + + $description = $descriptionFactory->newClassDescription( + $dataItemFactory->newDIWikiPage( 'Foo', NS_CATEGORY ) + ); + + $expected = new \stdClass; + $expected->type = 2; + $expected->components = []; + $expected->joinfield = ""; + + $provider[] = [ + $description, + $pageId, + $expected + ]; + + return $provider; + } + +} |