Daniel Werner has submitted this change and it was merged.

Change subject: Added getArrayValue to SortOptions and QueryOptions
......................................................................


Added getArrayValue to SortOptions and QueryOptions

Change-Id: I21027d0ddf3aed2350b81f769568252974acd720
---
M Ask.mw.php
M includes/Ask/Language/Description/DescriptionCollection.php
M includes/Ask/Language/Option/QueryOptions.php
M includes/Ask/Language/Option/SortOptions.php
A tests/phpunit/Language/Option/QueryOptionsTest.php
A tests/phpunit/Language/Option/SortOptionsTest.php
6 files changed, 207 insertions(+), 2 deletions(-)

Approvals:
  Daniel Werner: Verified; Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Ask.mw.php b/Ask.mw.php
index 582002c..4d39924 100644
--- a/Ask.mw.php
+++ b/Ask.mw.php
@@ -80,6 +80,8 @@
                'Language/Description/ValueDescription',
 
                'Language/Option/PropertyValueSortExpression',
+               'Language/Option/QueryOptions',
+               'Language/Option/SortOptions',
 
                'Language/Selection/PropertySelection',
                'Language/Selection/SubjectSelection',
diff --git a/includes/Ask/Language/Description/DescriptionCollection.php 
b/includes/Ask/Language/Description/DescriptionCollection.php
index 6bdd45b..ea5142f 100644
--- a/includes/Ask/Language/Description/DescriptionCollection.php
+++ b/includes/Ask/Language/Description/DescriptionCollection.php
@@ -120,6 +120,10 @@
        /**
         * @see Comparable::equals
         *
+        * Note: it is possible this method provides false negatives due to
+        * equivalent expressions being expressed in different structures.
+        * This is however likely not important.
+        *
         * @since 0.1
         *
         * @param mixed $mixed
diff --git a/includes/Ask/Language/Option/QueryOptions.php 
b/includes/Ask/Language/Option/QueryOptions.php
index b6ff251..a41c2e1 100644
--- a/includes/Ask/Language/Option/QueryOptions.php
+++ b/includes/Ask/Language/Option/QueryOptions.php
@@ -28,7 +28,7 @@
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
  */
-class QueryOptions implements \Ask\Immutable {
+class QueryOptions implements \Ask\Immutable, \Ask\ArrayValueProvider {
 
        /**
         * The query limit. At most this many results will be selected.
@@ -105,4 +105,19 @@
                return $this->sort;
        }
 
+       /**
+        * @see ArrayValueProvider::getArrayValue
+        *
+        * @since 0.1
+        *
+        * @return array|null|bool|int|float|string
+        */
+       public function getArrayValue() {
+               return array(
+                       'limit' => $this->limit,
+                       'offset' => $this->offset,
+                       'sort' => $this->sort->getArrayValue(),
+               );
+       }
+
 }
diff --git a/includes/Ask/Language/Option/SortOptions.php 
b/includes/Ask/Language/Option/SortOptions.php
index edcad1c..39bd4de 100644
--- a/includes/Ask/Language/Option/SortOptions.php
+++ b/includes/Ask/Language/Option/SortOptions.php
@@ -28,7 +28,7 @@
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < [email protected] >
  */
-class SortOptions implements \Ask\Immutable {
+class SortOptions implements \Ask\Immutable, \Ask\ArrayValueProvider {
 
        /**
         * The sort expressions that make up these sort options.
@@ -61,4 +61,23 @@
                return $this->expressions;
        }
 
+       /**
+        * @see ArrayValueProvider::getArrayValue
+        *
+        * @since 0.1
+        *
+        * @return array|null|bool|int|float|string
+        */
+       public function getArrayValue() {
+               return array(
+                       // TODO: order of expressions is relevant
+                       'expressions' => array_map(
+                               function( SortExpression $expression ) {
+                                       return $expression->toArray();
+                               },
+                               $this->expressions
+                       )
+               );
+       }
+
 }
diff --git a/tests/phpunit/Language/Option/QueryOptionsTest.php 
b/tests/phpunit/Language/Option/QueryOptionsTest.php
new file mode 100644
index 0000000..1f4229a
--- /dev/null
+++ b/tests/phpunit/Language/Option/QueryOptionsTest.php
@@ -0,0 +1,86 @@
+<?php
+
+namespace Ask\Tests\Language\Option;
+
+use Ask\Language\Option\QueryOptions;
+
+/**
+ * Tests for the Ask\Language\Option\QueryOptions class.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since 0.1
+ *
+ * @file
+ * @ingroup AskTests
+ *
+ * @group Ask
+ * @group AskOption
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class QueryOptionsTest extends \Ask\Tests\AskTestCase {
+
+       /**
+        * @since 0.1
+        *
+        * @return QueryOptions[]
+        */
+       protected function getInstances() {
+               $instances = array();
+
+               $instances[] = new QueryOptions(
+                       100,
+                       0
+               );
+
+               $instances[] = new QueryOptions(
+                       5,
+                       100
+               );
+
+               $instances[] = new QueryOptions(
+                       9000,
+                       42,
+                       new \Ask\Language\Option\SortOptions( array() )
+               );
+
+               return $instances;
+       }
+
+       /**
+        * @since 0.1
+        *
+        * @return QueryOptions[][]
+        */
+       public function instanceProvider() {
+               return $this->arrayWrap( $this->getInstances() );
+       }
+
+       /**
+        * @dataProvider instanceProvider
+        *
+        * @since 0.1
+        *
+        * @param QueryOptions $object
+        */
+       public function testReturnTypeOfGetArrayValue( QueryOptions $object ) {
+               $array = $object->getArrayValue();
+               $this->assertPrimitiveStructure( $array );
+       }
+
+}
diff --git a/tests/phpunit/Language/Option/SortOptionsTest.php 
b/tests/phpunit/Language/Option/SortOptionsTest.php
new file mode 100644
index 0000000..963d4a5
--- /dev/null
+++ b/tests/phpunit/Language/Option/SortOptionsTest.php
@@ -0,0 +1,79 @@
+<?php
+
+namespace Ask\Tests\Language\Option;
+
+use Ask\Language\Option\SortOptions;
+
+/**
+ * Tests for the Ask\Language\Option\QueryOptions class.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @since 0.1
+ *
+ * @file
+ * @ingroup AskTests
+ *
+ * @group Ask
+ * @group AskOption
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class SortOptionsTest extends \Ask\Tests\AskTestCase {
+
+       /**
+        * @since 0.1
+        *
+        * @return SortOptions[]
+        */
+       protected function getInstances() {
+               $instances = array();
+
+               $instances[] = new SortOptions( array() );
+
+               $instances[] = new SortOptions( array(
+                       new \Ask\Language\Option\PropertyValueSortExpression(
+                               new \DataValues\PropertyValue( 'foo' ),
+                               \Ask\Language\Option\SortExpression::ASCENDING
+                       )
+               ) );
+               
+               return $instances;
+       }
+
+       /**
+        * @since 0.1
+        *
+        * @return SortOptions[][]
+        */
+       public function instanceProvider() {
+               return $this->arrayWrap( $this->getInstances() );
+       }
+
+       /**
+        * @dataProvider instanceProvider
+        *
+        * @since 0.1
+        *
+        * @param SortOptions $object
+        */
+       public function testReturnTypeOfGetArrayValue( SortOptions $object ) {
+               $array = $object->getArrayValue();
+               $this->assertPrimitiveStructure( $array );
+       }
+
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I21027d0ddf3aed2350b81f769568252974acd720
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Ask
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Daniel Werner <[email protected]>
Gerrit-Reviewer: John Erling Blad <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to