Jeroen De Dauw has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/54024


Change subject: Work on unserialization [DO NOT MERGE]
......................................................................

Work on unserialization [DO NOT MERGE]

Change-Id: I389976b7edd56bfeedbe1fdb49df10c29e483d8d
---
M includes/Ask/Language/Option/PropertyValueSortExpression.php
A includes/Ask/Language/Option/SortExpressionFactory.php
A tests/phpunit/Language/Option/SortExpressionFactoryTest.php
3 files changed, 131 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Ask 
refs/changes/24/54024/1

diff --git a/includes/Ask/Language/Option/PropertyValueSortExpression.php 
b/includes/Ask/Language/Option/PropertyValueSortExpression.php
index 71d958e..a1a7b68 100644
--- a/includes/Ask/Language/Option/PropertyValueSortExpression.php
+++ b/includes/Ask/Language/Option/PropertyValueSortExpression.php
@@ -94,6 +94,7 @@
        public function getArrayValue() {
                return array(
                        'property' => $this->property->toArray(),
+                       'direction' => $this->direction,
                );
        }
 
diff --git a/includes/Ask/Language/Option/SortExpressionFactory.php 
b/includes/Ask/Language/Option/SortExpressionFactory.php
new file mode 100644
index 0000000..781abe7
--- /dev/null
+++ b/includes/Ask/Language/Option/SortExpressionFactory.php
@@ -0,0 +1,75 @@
+<?php
+
+namespace Ask\Language\Option;
+
+use DataValues\PropertyValue;
+use InvalidArgumentException;
+use OutOfRangeException;
+
+/**
+ * Factory for constructing SortExpression objects.
+ *
+ * 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 Ask
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+final class SortExpressionFactory implements \Ask\Immutable {
+
+       /**
+        * @since 0.1
+        *
+        * @param array $array
+        *
+        * @return SortExpression
+        * @throws InvalidArgumentException
+        */
+       public function newExpressionFromArray( array $array ) {
+               if ( !array_key_exists( 'type', $array ) || !array_key_exists( 
'value', $array ) ) {
+                       throw new InvalidArgumentException( 'Invalid 
SortExpression array value provided' );
+               }
+
+               return $this->newExpressionFromArrayValue( $array['type'], 
$array['value'] );
+       }
+
+       /**
+        * @since 0.1
+        *
+        * @param string $expressionType
+        * @param mixed $value
+        *
+        * @return SortExpression
+        * @throws OutOfRangeException
+        */
+       public function newExpressionFromArrayValue( $expressionType, $value ) {
+               switch ( $expressionType ) {
+                       case SortExpression::PROPERTY_VALUE:
+                               return new PropertyValueSortExpression(
+                                       PropertyValue::newFromArray( 
$value['property'] ),
+                                       $value['direction']
+                               );
+                               break;
+                       default:
+                               throw new OutOfRangeException( 'Unknown sort 
expression type provided' );
+               }
+       }
+
+}
\ No newline at end of file
diff --git a/tests/phpunit/Language/Option/SortExpressionFactoryTest.php 
b/tests/phpunit/Language/Option/SortExpressionFactoryTest.php
new file mode 100644
index 0000000..2add8db
--- /dev/null
+++ b/tests/phpunit/Language/Option/SortExpressionFactoryTest.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace Ask\Tests\Language\Option;
+
+use Ask\Language\Option\PropertyValueSortExpression;
+use Ask\Language\Option\SortExpression;
+use Ask\Language\Option\SortExpressionFactory;
+use DataValues\PropertyValue;
+
+/**
+ * Unit tests for the Ask\Language\Option\SortExpressionFactory 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
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class SortExpressionFactoryTest extends \Ask\Tests\AskTestCase {
+
+       public function expressionProvider() {
+               $expressions = array();
+
+               $expressions[] = new PropertyValueSortExpression( new 
PropertyValue( 'foobar' ), SortExpression::ASCENDING );
+               $expressions[] = new PropertyValueSortExpression( new 
PropertyValue( 'p42' ), SortExpression::DESCENDING );
+
+               return $this->arrayWrap( $expressions );
+       }
+
+       public function testNewExpressionFromArrayValue() {
+
+       }
+
+       public function testNewExpressionFromArray() {
+
+       }
+
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I389976b7edd56bfeedbe1fdb49df10c29e483d8d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Ask
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>

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

Reply via email to