Jeroen De Dauw has uploaded a new change for review.

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


Change subject: Added StringHandler
......................................................................

Added StringHandler

Change-Id: I5a7d4187a7e9df674faf44fecca01a46f7b56444
---
M repo/config/Wikibase.experimental.php
A repo/includes/Query/SQLStore/DVHandler/StringHandler.php
M repo/tests/phpunit/includes/Query/SQLStore/DVHandler/EntityIdHandlerTest.php
A repo/tests/phpunit/includes/Query/SQLStore/DVHandler/StringHandlerTest.php
4 files changed, 222 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/99/52199/1

diff --git a/repo/config/Wikibase.experimental.php 
b/repo/config/Wikibase.experimental.php
index 66daa07..13ee295 100644
--- a/repo/config/Wikibase.experimental.php
+++ b/repo/config/Wikibase.experimental.php
@@ -61,6 +61,7 @@
 
        'Wikibase\Repo\Query\SQLStore\DVHandler\EntityIdHandler',
        'Wikibase\Repo\Query\SQLStore\DVHandler\GeoCoordinateHandler',
+       'Wikibase\Repo\Query\SQLStore\DVHandler\StringHandler',
 
        'Wikibase\Repo\Query\SQLStore\DataValueHandler',
        'Wikibase\Repo\Query\SQLStore\Engine',
@@ -132,6 +133,7 @@
 
                'Query/SQLStore/DVHandler/EntityIdHandler',
                'Query/SQLStore/DVHandler/GeoCoordinateHandler',
+               'Query/SQLStore/DVHandler/StringHandler',
 
                'Query/SQLStore/DataValueHandler',
                'Query/SQLStore/Engine',
diff --git a/repo/includes/Query/SQLStore/DVHandler/StringHandler.php 
b/repo/includes/Query/SQLStore/DVHandler/StringHandler.php
new file mode 100644
index 0000000..7965876
--- /dev/null
+++ b/repo/includes/Query/SQLStore/DVHandler/StringHandler.php
@@ -0,0 +1,144 @@
+<?php
+
+namespace Wikibase\Repo\Query\SQLStore\DVHandler;
+
+use Wikibase\Repo\Query\SQLStore\DataValueHandler;
+use Wikibase\Repo\Database\TableDefinition;
+use Wikibase\Repo\Database\FieldDefinition;
+use DataValues\DataValue;
+use DataValues\StringValue;
+use InvalidArgumentException;
+
+/**
+ * Represents the mapping between Wikibase\StringValue and
+ * the corresponding table in the store.
+ *
+ * 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 wd.qe
+ *
+ * @file
+ * @ingroup WikibaseSQLStore
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class StringHandler extends DataValueHandler {
+
+       /**
+        * @see DataValueHandler::getTableDefinition
+        *
+        * @since wd.qe
+        *
+        * @return TableDefinition
+        */
+       public function getTableDefinition() {
+               $fields = array(
+                       new FieldDefinition( 'value', 
FieldDefinition::TYPE_TEXT, false ),
+               );
+
+               return new TableDefinition( 'string', $fields );
+       }
+
+       /**
+        * @see DataValueHandler::getValueFieldName
+        *
+        * @since wd.qe
+        *
+        * @return string
+        */
+       public function getValueFieldName() {
+               return 'value';
+       }
+
+       /**
+        * @see DataValueHandler::getSortFieldName
+        *
+        * @since wd.qe
+        *
+        * @return string
+        */
+       public function getSortFieldName() {
+               return 'value';
+       }
+
+       /**
+        * @see DataValueHandler::newDataValueFromValueField
+        *
+        * @since wd.qe
+        *
+        * @param $valueFieldValue // TODO: mixed or string?
+        *
+        * @return DataValue
+        */
+       public function newDataValueFromValueField( $valueFieldValue ) {
+               return new StringValue( $valueFieldValue );
+       }
+
+       /**
+        * @see DataValueHandler::getLabelFieldName
+        *
+        * @since wd.qe
+        *
+        * @return string|null
+        */
+       public function getLabelFieldName() {
+               return null;
+       }
+
+       /**
+        * @see DataValueHandler::getWhereConditions
+        *
+        * @since wd.qe
+        *
+        * @param DataValue $value
+        *
+        * @return array
+        * @throws InvalidArgumentException
+        */
+       public function getWhereConditions( DataValue $value ) {
+               if ( !( $value instanceof StringValue ) ) {
+                       throw new InvalidArgumentException( 'Value is not a 
StringValue' );
+               }
+
+               return array(
+                       'value' => $value->getValue(),
+               );
+       }
+
+       /**
+        * @see DataValueHandler::getInsertValues
+        *
+        * @since wd.qe
+        *
+        * @param DataValue $value
+        *
+        * @return array
+        * @throws InvalidArgumentException
+        */
+       public function getInsertValues( DataValue $value ) {
+               if ( !( $value instanceof StringValue ) ) {
+                       throw new InvalidArgumentException( 'Value is not a 
StringValue' );
+               }
+
+               $values = array(
+                       'value' => $value->getValue(),
+               );
+
+               return $values;
+       }
+
+}
\ No newline at end of file
diff --git 
a/repo/tests/phpunit/includes/Query/SQLStore/DVHandler/EntityIdHandlerTest.php 
b/repo/tests/phpunit/includes/Query/SQLStore/DVHandler/EntityIdHandlerTest.php
index 9d46833..cb7b9d7 100644
--- 
a/repo/tests/phpunit/includes/Query/SQLStore/DVHandler/EntityIdHandlerTest.php
+++ 
b/repo/tests/phpunit/includes/Query/SQLStore/DVHandler/EntityIdHandlerTest.php
@@ -8,7 +8,7 @@
 use Wikibase\EntityId;
 
 /**
- * Unit tests for the Wikibase\Repo\Query\SQLStore\DVHandler\EntityId class.
+ * Unit tests for the Wikibase\Repo\Query\SQLStore\DVHandler\EntityIdHandler 
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
diff --git 
a/repo/tests/phpunit/includes/Query/SQLStore/DVHandler/StringHandlerTest.php 
b/repo/tests/phpunit/includes/Query/SQLStore/DVHandler/StringHandlerTest.php
new file mode 100644
index 0000000..6881196
--- /dev/null
+++ b/repo/tests/phpunit/includes/Query/SQLStore/DVHandler/StringHandlerTest.php
@@ -0,0 +1,75 @@
+<?php
+
+namespace Wikibase\Repo\Test\Query\SQLStore\DVHandler;
+
+use Wikibase\Repo\Query\SQLStore\DataValueHandler;
+use Wikibase\Repo\Query\SQLStore\DVHandler\StringHandler;
+use Wikibase\Repo\Test\Query\SQLStore\DataValueHandlerTest;
+use DataValues\StringValue;
+
+/**
+ * Unit tests for the Wikibase\Repo\Query\SQLStore\DVHandler\StringHandler 
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
+ *
+ * @file
+ * @since wd.qe
+ *
+ * @ingroup WikibaseRepoTest
+ *
+ * @group Wikibase
+ * @group WikibaseRepo
+ * @group WikibaseQuery
+ *
+ * @licence GNU GPL v2+
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class StringHandlerTest extends DataValueHandlerTest {
+
+       /**
+        * @see DataValueHandlerTest::getInstances
+        *
+        * @since wd.qe
+        *
+        * @return DataValueHandler[]
+        */
+       protected function getInstances() {
+               $instances = array();
+
+               $instances[] = new StringHandler();
+
+               return $instances;
+       }
+
+       /**
+        * @see DataValueHandlerTest::getValues
+        *
+        * @since wd.qe
+        *
+        * @return StringValue[]
+        */
+       protected function getValues() {
+               $values = array();
+
+               $values[] = new StringValue( 'foo' );
+               $values[] = new StringValue( '' );
+               $values[] = new StringValue( ' foo ' );
+               $values[] = new StringValue( ' foo bar baz bah! hax 
~=[,,_,,]:3' );
+
+               return $values;
+       }
+
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5a7d4187a7e9df674faf44fecca01a46f7b56444
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
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