jenkins-bot has submitted this change and it was merged. 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, 36 insertions(+), 1 deletion(-) Approvals: Aude: Looks good to me, approved jenkins-bot: Verified diff --git a/DataModel/Snak/PropertyValueSnak.php b/DataModel/Snak/PropertyValueSnak.php index c45f37a..2e5a886 100644 --- a/DataModel/Snak/PropertyValueSnak.php +++ b/DataModel/Snak/PropertyValueSnak.php @@ -88,7 +88,16 @@ public function toArray() { $data = parent::toArray(); - $data[] = $this->dataValue->getType(); + // Since we use getArrayValue() and getType() directly instead of + // the generic toArray() method, we need to handle the special case + // of "bad" values separately, to restore the original type info. + 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: merged Gerrit-Change-Id: Ic75833eca87677c65d7f9b6500f6dcfca80aedfb Gerrit-PatchSet: 2 Gerrit-Project: mediawiki/extensions/WikibaseDataModel Gerrit-Branch: master Gerrit-Owner: Daniel Kinzler <daniel.kinz...@wikimedia.de> Gerrit-Reviewer: Addshore <addshorew...@gmail.com> Gerrit-Reviewer: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits