Jeroen De Dauw has uploaded a new change for review. https://gerrit.wikimedia.org/r/50013
Change subject: Added getArrayValue to Query object ...................................................................... Added getArrayValue to Query object Change-Id: I7b7cf5e5766f851f1c82e22cb25bbd5283da675f --- M includes/Ask/Language/Option/SortOptions.php M includes/Ask/Language/Query.php M tests/phpunit/AskTestCase.php M tests/phpunit/Language/QueryTest.php 4 files changed, 53 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Ask refs/changes/13/50013/1 diff --git a/includes/Ask/Language/Option/SortOptions.php b/includes/Ask/Language/Option/SortOptions.php index 39bd4de..e2ec3a5 100644 --- a/includes/Ask/Language/Option/SortOptions.php +++ b/includes/Ask/Language/Option/SortOptions.php @@ -70,8 +70,7 @@ */ public function getArrayValue() { return array( - // TODO: order of expressions is relevant - 'expressions' => array_map( + 'expressions' => (object)array_map( function( SortExpression $expression ) { return $expression->toArray(); }, diff --git a/includes/Ask/Language/Query.php b/includes/Ask/Language/Query.php index 6147347..3ae785b 100644 --- a/includes/Ask/Language/Query.php +++ b/includes/Ask/Language/Query.php @@ -32,7 +32,7 @@ * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroended...@gmail.com > */ -class Query implements \Ask\Immutable { +class Query implements \Ask\Immutable, \Ask\ArrayValueProvider { const OPT_LIMIT = 'limit'; const OPT_OFFSET = 'offset'; @@ -117,4 +117,24 @@ return $this->options; } + /** + * @see ArrayValueProvider::getArrayValue + * + * @since 0.1 + * + * @return array|null|bool|int|float|string + */ + public function getArrayValue() { + return array( + 'description' => $this->description->toArray(), + 'options' => $this->options->getArrayValue(), + 'selectionrequests' => (object)array_map( + function( SelectionRequest $selectionRequest ) { + return $selectionRequest->toArray(); + }, + $this->selectionRequests + ), + ); + } + } diff --git a/tests/phpunit/AskTestCase.php b/tests/phpunit/AskTestCase.php index e67e38c..143a408 100644 --- a/tests/phpunit/AskTestCase.php +++ b/tests/phpunit/AskTestCase.php @@ -51,7 +51,10 @@ } protected function assertPrimitiveStructure( $value ) { - if ( is_array( $value ) ) { + if ( is_array( $value ) || is_object( $value ) ) { + // TODO: would be good if we could reject objects that are not simple maps + $value = (array)$value; + if ( empty( $value ) ) { $this->assertTrue( true ); } @@ -61,7 +64,6 @@ } } else { - $this->assertFalse( is_object( $value ), 'Value should not be an object' ); $this->assertFalse( is_resource( $value ), 'Value should not be a resource' ); } } diff --git a/tests/phpunit/Language/QueryTest.php b/tests/phpunit/Language/QueryTest.php index eb46d6a..c606b14 100644 --- a/tests/phpunit/Language/QueryTest.php +++ b/tests/phpunit/Language/QueryTest.php @@ -86,4 +86,31 @@ $this->assertEquals( $selectionRequests, $obtainedRequests ); } + public function instanceProvider() { + $instances = array(); + + $instances[] = new Query( + new \Ask\Language\Description\AnyValue(), + array( + new \Ask\Language\Selection\PropertySelection( new \DataValues\PropertyValue( 'q42' ) ), + new \Ask\Language\Selection\PropertySelection( new \DataValues\PropertyValue( '_geo' ) ), + ), + new QueryOptions( 100, 0 ) + ); + + return $this->arrayWrap( $instances ); + } + + /** + * @dataProvider instanceProvider + * + * @since 0.1 + * + * @param Query $object + */ + public function testReturnTypeOfGetArrayValue( Query $object ) { + $array = $object->getArrayValue(); + $this->assertPrimitiveStructure( $array ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/50013 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7b7cf5e5766f851f1c82e22cb25bbd5283da675f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Ask Gerrit-Branch: master Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits