88use DataValues \MonolingualTextValue ;
99use DataValues \QuantityValue ;
1010use DataValues \StringValue ;
11+ use DataValues \TimeValue ;
1112use DataValues \UnboundedQuantityValue ;
1213use Generator ;
1314use GraphQL \GraphQL ;
@@ -54,6 +55,7 @@ class GraphQLServiceTest extends MediaWikiIntegrationTestCase {
5455 private static Property $ globeCoordinateTypeProperty ;
5556 private static Property $ monolingualTextProperty ;
5657 private static Property $ quantityProperty ;
58+ private static Property $ timeProperty ;
5759 private static Property $ qualifierProperty ;
5860 private static MediaWikiSite $ sitelinkSite ;
5961 private const ALLOWED_SITELINK_SITES = [ 'examplewiki ' , 'otherwiki ' ];
@@ -91,6 +93,7 @@ public function testQuery( string $query, array $expectedResult ): void {
9193 self ::$ globeCoordinateTypeProperty ,
9294 self ::$ monolingualTextProperty ,
9395 self ::$ quantityProperty ,
96+ self ::$ timeProperty ,
9497 ] as $ property ) {
9598 $ dataTypeLookup ->setDataTypeForProperty ( $ property ->getId (), $ property ->getDataTypeId () );
9699 }
@@ -136,6 +139,7 @@ public function queryProvider(): Generator {
136139 $ statementWithGlobeCoordinateValuePropertyId = 'P6 ' ;
137140 $ statementWithMonolingualTextValuePropertyId = 'P7 ' ;
138141 $ statementWithQuantityValuePropertyId = 'P8 ' ;
142+ $ statementWithTimeValuePropertyId = 'P9 ' ;
139143 $ statementWithItemValueQualifierPropertyId = $ statementWithItemValuePropertyId ; // also type wikibase-item so we can just reuse it.
140144 $ statementReferencePropertyId = 'P11 ' ;
141145 $ unusedPropertyId = 'P9999 ' ;
@@ -182,6 +186,18 @@ public function queryProvider(): Generator {
182186 ->withGuid ( "$ itemId \$a82559b1-da8f-4e02-9f72-e304b90a9bde " )
183187 ->withValue ( $ unboundedQuantityValue )
184188 ->build ();
189+ $ timeValue = new TimeValue (
190+ timestamp: '+2001-01-01T00:00:00Z ' ,
191+ timezone: 60 ,
192+ before: 0 ,
193+ after: 1 ,
194+ precision: TimeValue::PRECISION_MONTH ,
195+ calendarModel: 'http://www.wikidata.org/entity/Q1985727 ' ,
196+ );
197+ $ statementWithTimeValue = NewStatement::forProperty ( $ statementWithTimeValuePropertyId )
198+ ->withGuid ( "$ itemId \$a82559b1-da8f-4e02-9f72-e304b90a9bde " )
199+ ->withValue ( $ timeValue )
200+ ->build ();
185201
186202 $ statementWithNoValue = NewStatement::noValueFor ( ( $ statementWithNoValuePropertyId ) )
187203 ->withGuid ( "$ itemId \$bed933b7-4207-d679-7571-3630cfb49d9f " )
@@ -216,6 +232,11 @@ public function queryProvider(): Generator {
216232 null ,
217233 'quantity ' ,
218234 );
235+ self ::$ timeProperty = new Property (
236+ new NumericPropertyId ( $ statementWithTimeValuePropertyId ),
237+ null ,
238+ 'time ' ,
239+ );
219240 self ::$ qualifierProperty = new Property (
220241 new NumericPropertyId ( $ qualifierPropertyId ),
221242 new Fingerprint ( new TermList ( [ new Term ( 'en ' , 'qualifier prop ' ) ] ) ),
@@ -233,6 +254,7 @@ public function queryProvider(): Generator {
233254 ->andStatement ( $ statementWithMonolingualTextValue )
234255 ->andStatement ( $ statementWithQuantityValue )
235256 ->andStatement ( $ statementWithUnboundedQuantityValue )
257+ ->andStatement ( $ statementWithTimeValue )
236258 ->andStatement ( $ statementWithNoValue )
237259 ->andStatement ( $ statementWithSomeValue )
238260 ->build ();
@@ -500,6 +522,33 @@ public function queryProvider(): Generator {
500522 ],
501523 ],
502524 ];
525+ yield 'statement with time value ' => [
526+ "{ item(id: \"$ itemId \") {
527+ statements(propertyId: \"$ statementWithTimeValuePropertyId \") {
528+ value {
529+ ... on TimeValue { time timezone before after precision calendarModel }
530+ }
531+ }
532+ } } " ,
533+ [
534+ 'data ' => [
535+ 'item ' => [
536+ 'statements ' => [
537+ [
538+ 'value ' => [
539+ 'time ' => $ timeValue ->getTime (),
540+ 'timezone ' => $ timeValue ->getTimezone (),
541+ 'before ' => $ timeValue ->getBefore (),
542+ 'after ' => $ timeValue ->getAfter (),
543+ 'precision ' => $ timeValue ->getPrecision (),
544+ 'calendarModel ' => $ timeValue ->getCalendarModel (),
545+ ],
546+ ],
547+ ],
548+ ],
549+ ],
550+ ],
551+ ];
503552 yield 'statements with novalue and somevalue ' => [
504553 "{ item(id: \"$ itemId \") {
505554 $ statementWithSomeValuePropertyId: statements(propertyId: \"$ statementWithSomeValuePropertyId \") {
0 commit comments