44
55use DataValues \Geo \Values \GlobeCoordinateValue ;
66use DataValues \Geo \Values \LatLongValue ;
7+ use DataValues \MonolingualTextValue ;
78use DataValues \StringValue ;
89use Generator ;
910use GraphQL \GraphQL ;
@@ -48,6 +49,7 @@ class GraphQLServiceTest extends MediaWikiIntegrationTestCase {
4849 private static Property $ stringTypeProperty ;
4950 private static Property $ itemTypeProperty ;
5051 private static Property $ globeCoordinateTypeProperty ;
52+ private static Property $ monolingualTextProperty ;
5153 private static Property $ qualifierProperty ;
5254 private static MediaWikiSite $ sitelinkSite ;
5355 private const ALLOWED_SITELINK_SITES = [ 'examplewiki ' , 'otherwiki ' ];
@@ -78,10 +80,15 @@ public function testQuery( string $query, array $expectedResult ): void {
7880 ] );
7981
8082 $ dataTypeLookup = new InMemoryDataTypeLookup ();
81- $ dataTypeLookup ->setDataTypeForProperty ( self ::$ stringTypeProperty ->getId (), 'string ' );
82- $ dataTypeLookup ->setDataTypeForProperty ( self ::$ qualifierProperty ->getId (), 'string ' );
83- $ dataTypeLookup ->setDataTypeForProperty ( self ::$ itemTypeProperty ->getId (), 'wikibase-item ' );
84- $ dataTypeLookup ->setDataTypeForProperty ( self ::$ globeCoordinateTypeProperty ->getId (), 'globe-coordinate ' );
83+ foreach ( [
84+ self ::$ qualifierProperty ,
85+ self ::$ stringTypeProperty ,
86+ self ::$ itemTypeProperty ,
87+ self ::$ globeCoordinateTypeProperty ,
88+ self ::$ monolingualTextProperty ,
89+ ] as $ property ) {
90+ $ dataTypeLookup ->setDataTypeForProperty ( $ property ->getId (), $ property ->getDataTypeId () );
91+ }
8592
8693 $ this ->assertEquals (
8794 $ expectedResult ,
@@ -122,6 +129,7 @@ public function queryProvider(): Generator {
122129 $ statementWithNoReferencesPropertyId = $ statementWithNoValuePropertyId ;
123130 $ statementWithSomeValuePropertyId = 'P5 ' ;
124131 $ statementWithGlobeCoordinateValuePropertyId = 'P6 ' ;
132+ $ statementWithMonolingualTextValuePropertyId = 'P7 ' ;
125133 $ statementWithItemValueQualifierPropertyId = $ statementWithItemValuePropertyId ; // also type wikibase-item so we can just reuse it.
126134 $ statementReferencePropertyId = 'P11 ' ;
127135 $ unusedPropertyId = 'P9999 ' ;
@@ -145,6 +153,11 @@ public function queryProvider(): Generator {
145153 ->withGuid ( "$ itemId \$a82559b1-da8f-4e02-9f72-e304b90a9bde " )
146154 ->withValue ( $ globeCoordinateValue )
147155 ->build ();
156+ $ monolingualTextValue = new MonolingualTextValue ( 'en ' , 'potato ' );
157+ $ statementWithMonolingualTextValue = NewStatement::forProperty ( $ statementWithMonolingualTextValuePropertyId )
158+ ->withGuid ( "$ itemId \$a82559b1-da8f-4e02-9f72-e304b90a9bde " )
159+ ->withValue ( $ monolingualTextValue )
160+ ->build ();
148161
149162 $ statementWithNoValue = NewStatement::noValueFor ( ( $ statementWithNoValuePropertyId ) )
150163 ->withGuid ( "$ itemId \$bed933b7-4207-d679-7571-3630cfb49d9f " )
@@ -169,6 +182,11 @@ public function queryProvider(): Generator {
169182 null ,
170183 'globe-coordinate ' ,
171184 );
185+ self ::$ monolingualTextProperty = new Property (
186+ new NumericPropertyId ( $ statementWithMonolingualTextValuePropertyId ),
187+ null ,
188+ 'monolingualtext ' ,
189+ );
172190 self ::$ qualifierProperty = new Property (
173191 new NumericPropertyId ( $ qualifierPropertyId ),
174192 new Fingerprint ( new TermList ( [ new Term ( 'en ' , 'qualifier prop ' ) ] ) ),
@@ -183,6 +201,7 @@ public function queryProvider(): Generator {
183201 ->andStatement ( $ statementWithStringValue )
184202 ->andStatement ( $ statementWithItemValue )
185203 ->andStatement ( $ statementWithGlobeCoordinateValue )
204+ ->andStatement ( $ statementWithMonolingualTextValue )
186205 ->andStatement ( $ statementWithNoValue )
187206 ->andStatement ( $ statementWithSomeValue )
188207 ->build ();
@@ -394,6 +413,29 @@ public function queryProvider(): Generator {
394413 ],
395414 ],
396415 ];
416+ yield 'statement with monolingualtext value ' => [
417+ "{ item(id: \"$ itemId \") {
418+ statements(propertyId: \"$ statementWithMonolingualTextValuePropertyId \") {
419+ value {
420+ ... on MonolingualTextValue { language text }
421+ }
422+ }
423+ } } " ,
424+ [
425+ 'data ' => [
426+ 'item ' => [
427+ 'statements ' => [
428+ [
429+ 'value ' => [
430+ 'language ' => $ monolingualTextValue ->getLanguageCode (),
431+ 'text ' => $ monolingualTextValue ->getText (),
432+ ],
433+ ],
434+ ],
435+ ],
436+ ],
437+ ],
438+ ];
397439 yield 'statements with novalue and somevalue ' => [
398440 "{ item(id: \"$ itemId \") {
399441 $ statementWithSomeValuePropertyId: statements(propertyId: \"$ statementWithSomeValuePropertyId \") {
0 commit comments