diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/DescriptionInterpreters/NamespaceDescriptionInterpreterTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/DescriptionInterpreters/NamespaceDescriptionInterpreterTest.php | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/DescriptionInterpreters/NamespaceDescriptionInterpreterTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/DescriptionInterpreters/NamespaceDescriptionInterpreterTest.php new file mode 100644 index 00000000..2bcceb92 --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SQLStore/QueryEngine/DescriptionInterpreters/NamespaceDescriptionInterpreterTest.php @@ -0,0 +1,83 @@ +<?php + +namespace SMW\Tests\SQLStore\QueryEngine\DescriptionInterpreters; + +use SMW\Query\DescriptionFactory; +use SMW\SQLStore\QueryEngine\DescriptionInterpreters\NamespaceDescriptionInterpreter; +use SMW\SQLStore\QueryEngineFactory; +use SMW\Tests\TestEnvironment; + +/** + * @covers \SMW\SQLStore\QueryEngine\DescriptionInterpreters\NamespaceDescriptionInterpreter + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 2.2 + * + * @author mwjames + */ +class NamespaceDescriptionInterpreterTest extends \PHPUnit_Framework_TestCase { + + private $querySegmentValidator; + private $descriptionFactory; + + protected function setUp() { + parent::setUp(); + + $this->descriptionFactory = new DescriptionFactory(); + + $testEnvironment = new TestEnvironment(); + $this->querySegmentValidator = $testEnvironment->getUtilityFactory()->newValidatorFactory()->newQuerySegmentValidator(); + } + + public function testCanConstruct() { + + $querySegmentListBuilder = $this->getMockBuilder( '\SMW\SQLStore\QueryEngine\QuerySegmentListBuilder' ) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $this->assertInstanceOf( + '\SMW\SQLStore\QueryEngine\DescriptionInterpreters\NamespaceDescriptionInterpreter', + new NamespaceDescriptionInterpreter( $querySegmentListBuilder ) + ); + } + + public function testInterpretDescription() { + + $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 ) ); + + $queryEngineFactory = new QueryEngineFactory( $store ); + + $description = $this->descriptionFactory->newNamespaceDescription( + NS_HELP + ); + + $expected = new \stdClass; + $expected->type = 1; + $expected->where = "t0.smw_namespace="; + + $instance = new NamespaceDescriptionInterpreter( + $queryEngineFactory->newQuerySegmentListBuilder() + ); + + $this->assertTrue( + $instance->canInterpretDescription( $description ) + ); + + $this->querySegmentValidator->assertThatContainerHasProperties( + $expected, + $instance->interpretDescription( $description ) + ); + } + +} |