John Erling Blad has submitted this change and it was merged.

Change subject: Adding query definition to query entity
......................................................................


Adding query definition to query entity

Change-Id: Ide39070bed8262cb5846200137919ea771cdc381
---
M lib/includes/query/Query.php
M lib/tests/phpunit/query/QueryTest.php
2 files changed, 64 insertions(+), 2 deletions(-)

Approvals:
  John Erling Blad: Verified; Looks good to me, approved



diff --git a/lib/includes/query/Query.php b/lib/includes/query/Query.php
index fd8e0d1..1e31712 100644
--- a/lib/includes/query/Query.php
+++ b/lib/includes/query/Query.php
@@ -2,6 +2,9 @@
 
 namespace Wikibase;
 
+use Ask\Language\Query as QueryDefinition;
+use MWException;
+
 /**
  * Represents a single Wikibase query.
  *
@@ -24,6 +27,7 @@
  *
  * @file
  * @ingroup WikibaseLib
+ * @ingroup WikibaseQuery
  *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
@@ -33,6 +37,45 @@
        const ENTITY_TYPE = 'query';
 
        /**
+        * @since 0.4
+        *
+        * @var QueryDefinition|null
+        */
+       protected $queryDefinition = null;
+
+       /**
+        * Returns the QueryDefinition of the query entity.
+        *
+        * @since 0.4
+        *
+        * @return QueryDefinition
+        * @throws MWException
+        */
+       public function getQueryDefinition() {
+               if ( $this->queryDefinition === null ) {
+                       if ( array_key_exists( 'querydefinition', $this->data ) 
) {
+                               // TODO
+                       }
+                       else {
+                               throw new MWException( 'The QueryDefinition of 
the query is not known' );
+                       }
+               }
+
+               return $this->queryDefinition;
+       }
+
+       /**
+        * Sets the QueryDefinition of the query entity.
+        *
+        * @since 0.4
+        *
+        * @param QueryDefinition $queryDefinition
+        */
+       public function setQueryDefinition( QueryDefinition $queryDefinition ) {
+               $this->queryDefinition = $queryDefinition;
+       }
+
+       /**
         * @see Entity::newFromArray
         *
         * @since 0.1
diff --git a/lib/tests/phpunit/query/QueryTest.php 
b/lib/tests/phpunit/query/QueryTest.php
index cca8b6c..7589057 100644
--- a/lib/tests/phpunit/query/QueryTest.php
+++ b/lib/tests/phpunit/query/QueryTest.php
@@ -1,7 +1,8 @@
 <?php
 
 namespace Wikibase\Test;
-use \Wikibase\Query;
+
+use Wikibase\Query;
 
 /**
  * Tests for the Wikibase\Query class.
@@ -59,4 +60,22 @@
        protected function getNewFromArray( array $data ) {
                return Query::newFromArray( $data );
        }
-}
\ No newline at end of file
+
+       public function testSetQueryDefinition() {
+               $query = Query::newEmpty();
+
+               $queryDefinition = new \Ask\Language\Query(
+                       new \Ask\Language\Description\AnyValue(),
+                       array(),
+                       new \Ask\Language\Option\QueryOptions( 1, 0 )
+               );
+
+               $query->setQueryDefinition( $queryDefinition );
+
+               $obtainedDefinition = $query->getQueryDefinition();
+
+               $this->assertInstanceOf( 'Ask\Language\Query', 
$obtainedDefinition );
+               $this->assertEquals( $queryDefinition, $obtainedDefinition );
+       }
+
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/48819
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ide39070bed8262cb5846200137919ea771cdc381
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: John Erling Blad <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to