Daniel Kinzler has uploaded a new change for review. https://gerrit.wikimedia.org/r/81214
Change subject: Use original DV type when serializing bad values. ...................................................................... Use original DV type when serializing bad values. UnDeserializableValue is used to represent values that could not be unserialized. When re-serializing them, we should restore the original type and data as it were, instead of saving "bad" as the type. Change-Id: Ic75833eca87677c65d7f9b6500f6dcfca80aedfb --- M DataModel/Snak/PropertyValueSnak.php M tests/phpunit/Snak/PropertyValueSnakTest.php 2 files changed, 35 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseDataModel refs/changes/14/81214/1 diff --git a/DataModel/Snak/PropertyValueSnak.php b/DataModel/Snak/PropertyValueSnak.php index c45f37a..c7f0f94 100644 --- a/DataModel/Snak/PropertyValueSnak.php +++ b/DataModel/Snak/PropertyValueSnak.php @@ -88,7 +88,15 @@ public function toArray() { $data = parent::toArray(); - $data[] = $this->dataValue->getType(); + // Would be nice to have a generic way to do this, e.g. by using toArray() + // instead of getArrayValue() and getType(). + if ( $this->dataValue instanceof UnDeserializableValue ) { + $type = $this->dataValue->getTargetType(); + } else { + $type = $this->dataValue->getType(); + } + + $data[] = $type; $data[] = $this->dataValue->getArrayValue(); return $data; diff --git a/tests/phpunit/Snak/PropertyValueSnakTest.php b/tests/phpunit/Snak/PropertyValueSnakTest.php index 69dc6f0..61afcb8 100644 --- a/tests/phpunit/Snak/PropertyValueSnakTest.php +++ b/tests/phpunit/Snak/PropertyValueSnakTest.php @@ -3,6 +3,9 @@ namespace Wikibase\Test; use DataValues\StringValue; +use DataValues\UnDeserializableValue; +use Wikibase\EntityId; +use Wikibase\Property; use Wikibase\PropertyValueSnak; /** @@ -73,4 +76,27 @@ return $argLists; } + /** + * @dataProvider toArrayProvider + */ + public function testToArray( PropertyValueSnak $snak, array $expected ) { + $actual = $snak->toArray(); + + $this->assertEquals( $expected, $actual ); + } + + public static function toArrayProvider() { + $q1 = new EntityId( Property::ENTITY_TYPE, 1 ); + + return array( + 'string-value' => array( + new PropertyValueSnak( $q1, new StringValue( 'boo' ) ), + array( 'value', $q1->getNumericId(), 'string', 'boo' ) + ), + 'bad-value' => array( + new PropertyValueSnak( $q1, new UnDeserializableValue( 77, 'string', 'not a string' ) ), + array( 'value', $q1->getNumericId(), 'string', 77 ) + ), + ); + } } -- To view, visit https://gerrit.wikimedia.org/r/81214 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic75833eca87677c65d7f9b6500f6dcfca80aedfb Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikibaseDataModel Gerrit-Branch: master Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits