summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SPARQLStore/QueryEngine/DescriptionInterpreters/ThingDescriptionInterpreterTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SPARQLStore/QueryEngine/DescriptionInterpreters/ThingDescriptionInterpreterTest.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SPARQLStore/QueryEngine/DescriptionInterpreters/ThingDescriptionInterpreterTest.php128
1 files changed, 128 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SPARQLStore/QueryEngine/DescriptionInterpreters/ThingDescriptionInterpreterTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SPARQLStore/QueryEngine/DescriptionInterpreters/ThingDescriptionInterpreterTest.php
new file mode 100644
index 00000000..cab64703
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/SPARQLStore/QueryEngine/DescriptionInterpreters/ThingDescriptionInterpreterTest.php
@@ -0,0 +1,128 @@
+<?php
+
+namespace SMW\Tests\SPARQLStore\QueryEngine\DescriptionInterpreters;
+
+use SMW\DIProperty;
+use SMW\Query\Language\ThingDescription;
+use SMW\SPARQLStore\QueryEngine\ConditionBuilder;
+use SMW\SPARQLStore\QueryEngine\DescriptionInterpreterFactory;
+use SMW\SPARQLStore\QueryEngine\DescriptionInterpreters\ThingDescriptionInterpreter;
+use SMW\Tests\Utils\UtilityFactory;
+
+/**
+ * @covers \SMW\SPARQLStore\QueryEngine\DescriptionInterpreters\ThingDescriptionInterpreter
+ * @group semantic-mediawiki
+ *
+ * @license GNU GPL v2+
+ * @since 2.1
+ *
+ * @author mwjames
+ */
+class ThingDescriptionInterpreterTest extends \PHPUnit_Framework_TestCase {
+
+ private $descriptionInterpreterFactory;
+
+ protected function setUp() {
+ parent::setUp();
+
+ $this->descriptionInterpreterFactory = new DescriptionInterpreterFactory();
+ }
+
+ public function testCanConstruct() {
+
+ $conditionBuilder = $this->getMockBuilder( '\SMW\SPARQLStore\QueryEngine\ConditionBuilder' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->assertInstanceOf(
+ '\SMW\SPARQLStore\QueryEngine\DescriptionInterpreters\ThingDescriptionInterpreter',
+ new ThingDescriptionInterpreter( $conditionBuilder )
+ );
+ }
+
+ public function testCanBuildConditionFor() {
+
+ $description = $this->getMockBuilder( '\SMW\Query\Language\ThingDescription' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $conditionBuilder = $this->getMockBuilder( '\SMW\SPARQLStore\QueryEngine\ConditionBuilder' )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $instance = new ThingDescriptionInterpreter( $conditionBuilder );
+
+ $this->assertTrue(
+ $instance->canInterpretDescription( $description )
+ );
+ }
+
+ /**
+ * @dataProvider descriptionProvider
+ */
+ public function testThingDescriptionInterpreter( $description, $orderByProperty, $expectedConditionType, $expectedConditionString ) {
+
+ $resultVariable = 'result';
+
+ $conditionBuilder = new ConditionBuilder( $this->descriptionInterpreterFactory );
+ $conditionBuilder->setResultVariable( $resultVariable );
+ $conditionBuilder->setJoinVariable( $resultVariable );
+ $conditionBuilder->setOrderByProperty( $orderByProperty );
+
+ $instance = new ThingDescriptionInterpreter( $conditionBuilder );
+
+ $condition = $instance->interpretDescription( $description );
+
+ $this->assertInstanceOf(
+ $expectedConditionType,
+ $condition
+ );
+
+ $this->assertEquals(
+ $expectedConditionString,
+ $conditionBuilder->convertConditionToString( $condition )
+ );
+ }
+
+ public function descriptionProvider() {
+
+ $stringBuilder = UtilityFactory::getInstance()->newStringBuilder();
+
+ # 0
+ $conditionType = '\SMW\SPARQLStore\QueryEngine\Condition\TrueCondition';
+
+ $description = new ThingDescription();
+ $orderByProperty = null;
+
+ $expected = $stringBuilder
+ ->addString( '?result swivt:page ?url .' )->addNewLine()
+ ->getString();
+
+ $provider[] = [
+ $description,
+ $orderByProperty,
+ $conditionType,
+ $expected
+ ];
+
+ # 1
+ $conditionType = '\SMW\SPARQLStore\QueryEngine\Condition\TrueCondition';
+
+ $description = new ThingDescription();
+ $orderByProperty = new DIProperty( 'Foo' );
+
+ $expected = $stringBuilder
+ ->addString( '?result swivt:wikiPageSortKey ?resultsk .' )->addNewLine()
+ ->getString();
+
+ $provider[] = [
+ $description,
+ $orderByProperty,
+ $conditionType,
+ $expected
+ ];
+
+ return $provider;
+ }
+
+}