22
33namespace Wikibase \Repo \Tests \Domains \Reuse \Infrastructure \GraphQL ;
44
5+ use DataValues \DecimalValue ;
56use DataValues \Geo \Values \GlobeCoordinateValue ;
67use DataValues \Geo \Values \LatLongValue ;
78use DataValues \MonolingualTextValue ;
9+ use DataValues \QuantityValue ;
810use DataValues \StringValue ;
11+ use DataValues \UnboundedQuantityValue ;
912use Generator ;
1013use GraphQL \GraphQL ;
1114use MediaWiki \Site \HashSiteStore ;
@@ -50,6 +53,7 @@ class GraphQLServiceTest extends MediaWikiIntegrationTestCase {
5053 private static Property $ itemTypeProperty ;
5154 private static Property $ globeCoordinateTypeProperty ;
5255 private static Property $ monolingualTextProperty ;
56+ private static Property $ quantityProperty ;
5357 private static Property $ qualifierProperty ;
5458 private static MediaWikiSite $ sitelinkSite ;
5559 private const ALLOWED_SITELINK_SITES = [ 'examplewiki ' , 'otherwiki ' ];
@@ -86,6 +90,7 @@ public function testQuery( string $query, array $expectedResult ): void {
8690 self ::$ itemTypeProperty ,
8791 self ::$ globeCoordinateTypeProperty ,
8892 self ::$ monolingualTextProperty ,
93+ self ::$ quantityProperty ,
8994 ] as $ property ) {
9095 $ dataTypeLookup ->setDataTypeForProperty ( $ property ->getId (), $ property ->getDataTypeId () );
9196 }
@@ -130,6 +135,7 @@ public function queryProvider(): Generator {
130135 $ statementWithSomeValuePropertyId = 'P5 ' ;
131136 $ statementWithGlobeCoordinateValuePropertyId = 'P6 ' ;
132137 $ statementWithMonolingualTextValuePropertyId = 'P7 ' ;
138+ $ statementWithQuantityValuePropertyId = 'P8 ' ;
133139 $ statementWithItemValueQualifierPropertyId = $ statementWithItemValuePropertyId ; // also type wikibase-item so we can just reuse it.
134140 $ statementReferencePropertyId = 'P11 ' ;
135141 $ unusedPropertyId = 'P9999 ' ;
@@ -158,6 +164,24 @@ public function queryProvider(): Generator {
158164 ->withGuid ( "$ itemId \$a82559b1-da8f-4e02-9f72-e304b90a9bde " )
159165 ->withValue ( $ monolingualTextValue )
160166 ->build ();
167+ $ quantityValue = new QuantityValue (
168+ new DecimalValue ( '+0.111 ' ),
169+ 'https://wikibase.example/wiki/Q123 ' ,
170+ new DecimalValue ( '+0.1150 ' ),
171+ new DecimalValue ( '+0.1105 ' ),
172+ );
173+ $ unboundedQuantityValue = new UnboundedQuantityValue (
174+ new DecimalValue ( '+321 ' ),
175+ 'https://wikibase.example/wiki/Q321 ' ,
176+ );
177+ $ statementWithQuantityValue = NewStatement::forProperty ( $ statementWithQuantityValuePropertyId )
178+ ->withGuid ( "$ itemId \$a82559b1-da8f-4e02-9f72-e304b90a9bde " )
179+ ->withValue ( $ quantityValue )
180+ ->build ();
181+ $ statementWithUnboundedQuantityValue = NewStatement::forProperty ( $ statementWithQuantityValuePropertyId )
182+ ->withGuid ( "$ itemId \$a82559b1-da8f-4e02-9f72-e304b90a9bde " )
183+ ->withValue ( $ unboundedQuantityValue )
184+ ->build ();
161185
162186 $ statementWithNoValue = NewStatement::noValueFor ( ( $ statementWithNoValuePropertyId ) )
163187 ->withGuid ( "$ itemId \$bed933b7-4207-d679-7571-3630cfb49d9f " )
@@ -187,6 +211,11 @@ public function queryProvider(): Generator {
187211 null ,
188212 'monolingualtext ' ,
189213 );
214+ self ::$ quantityProperty = new Property (
215+ new NumericPropertyId ( $ statementWithQuantityValuePropertyId ),
216+ null ,
217+ 'quantity ' ,
218+ );
190219 self ::$ qualifierProperty = new Property (
191220 new NumericPropertyId ( $ qualifierPropertyId ),
192221 new Fingerprint ( new TermList ( [ new Term ( 'en ' , 'qualifier prop ' ) ] ) ),
@@ -202,6 +231,8 @@ public function queryProvider(): Generator {
202231 ->andStatement ( $ statementWithItemValue )
203232 ->andStatement ( $ statementWithGlobeCoordinateValue )
204233 ->andStatement ( $ statementWithMonolingualTextValue )
234+ ->andStatement ( $ statementWithQuantityValue )
235+ ->andStatement ( $ statementWithUnboundedQuantityValue )
205236 ->andStatement ( $ statementWithNoValue )
206237 ->andStatement ( $ statementWithSomeValue )
207238 ->build ();
@@ -436,6 +467,39 @@ public function queryProvider(): Generator {
436467 ],
437468 ],
438469 ];
470+ yield 'statement with quantity value ' => [
471+ "{ item(id: \"$ itemId \") {
472+ statements(propertyId: \"$ statementWithQuantityValuePropertyId \") {
473+ value {
474+ ... on QuantityValue { amount unit lowerBound upperBound }
475+ }
476+ }
477+ } } " ,
478+ [
479+ 'data ' => [
480+ 'item ' => [
481+ 'statements ' => [
482+ [
483+ 'value ' => [
484+ 'amount ' => $ quantityValue ->getAmount ()->getValue (),
485+ 'unit ' => $ quantityValue ->getUnit (),
486+ 'lowerBound ' => $ quantityValue ->getLowerBound ()->getValue (),
487+ 'upperBound ' => $ quantityValue ->getUpperBound ()->getValue (),
488+ ],
489+ ],
490+ [
491+ 'value ' => [
492+ 'amount ' => $ unboundedQuantityValue ->getAmount ()->getValue (),
493+ 'unit ' => $ unboundedQuantityValue ->getUnit (),
494+ 'lowerBound ' => null ,
495+ 'upperBound ' => null ,
496+ ],
497+ ],
498+ ],
499+ ],
500+ ],
501+ ],
502+ ];
439503 yield 'statements with novalue and somevalue ' => [
440504 "{ item(id: \"$ itemId \") {
441505 $ statementWithSomeValuePropertyId: statements(propertyId: \"$ statementWithSomeValuePropertyId \") {
0 commit comments