1818use MediaWikiIntegrationTestCase ;
1919use Wikibase \DataAccess \PrefetchingTermLookup ;
2020use Wikibase \DataAccess \Tests \InMemoryPrefetchingTermLookup ;
21+ use Wikibase \DataModel \Entity \EntityIdValue ;
2122use Wikibase \DataModel \Entity \Item ;
2223use Wikibase \DataModel \Entity \ItemId ;
2324use Wikibase \DataModel \Entity \NumericPropertyId ;
@@ -56,6 +57,8 @@ class GraphQLServiceTest extends MediaWikiIntegrationTestCase {
5657 private static Property $ monolingualTextProperty ;
5758 private static Property $ quantityProperty ;
5859 private static Property $ timeProperty ;
60+ private static Property $ propertyTypeProperty ;
61+ private static Property $ propertyUsedAsValue ;
5962 private static Property $ qualifierProperty ;
6063 private static MediaWikiSite $ sitelinkSite ;
6164 private const ALLOWED_SITELINK_SITES = [ 'examplewiki ' , 'otherwiki ' ];
@@ -83,6 +86,7 @@ public function testQuery( string $query, array $expectedResult ): void {
8386 self ::$ qualifierProperty ,
8487 self ::$ statementValueItem ,
8588 self ::$ qualifierValueItem ,
89+ self ::$ propertyUsedAsValue ,
8690 ] );
8791
8892 $ dataTypeLookup = new InMemoryDataTypeLookup ();
@@ -94,6 +98,7 @@ public function testQuery( string $query, array $expectedResult ): void {
9498 self ::$ monolingualTextProperty ,
9599 self ::$ quantityProperty ,
96100 self ::$ timeProperty ,
101+ self ::$ propertyTypeProperty ,
97102 ] as $ property ) {
98103 $ dataTypeLookup ->setDataTypeForProperty ( $ property ->getId (), $ property ->getDataTypeId () );
99104 }
@@ -140,6 +145,7 @@ public function queryProvider(): Generator {
140145 $ statementWithMonolingualTextValuePropertyId = 'P7 ' ;
141146 $ statementWithQuantityValuePropertyId = 'P8 ' ;
142147 $ statementWithTimeValuePropertyId = 'P9 ' ;
148+ $ statementWithPropertyValuePropertyId = 'P10 ' ;
143149 $ statementWithItemValueQualifierPropertyId = $ statementWithItemValuePropertyId ; // also type wikibase-item so we can just reuse it.
144150 $ statementReferencePropertyId = 'P11 ' ;
145151 $ unusedPropertyId = 'P9999 ' ;
@@ -198,6 +204,15 @@ public function queryProvider(): Generator {
198204 ->withGuid ( "$ itemId \$a82559b1-da8f-4e02-9f72-e304b90a9bde " )
199205 ->withValue ( $ timeValue )
200206 ->build ();
207+ self ::$ propertyUsedAsValue = new Property (
208+ new NumericPropertyId ( 'P789 ' ),
209+ new Fingerprint ( new TermList ( [ new Term ( 'en ' , 'property used as value ' ) ] ) ),
210+ 'string ' ,
211+ );
212+ $ statementWithPropertyValue = NewStatement::forProperty ( $ statementWithPropertyValuePropertyId )
213+ ->withGuid ( "$ itemId \$a82559b1-da8f-4e02-9f72-e304b90a9bde " )
214+ ->withValue ( new EntityIdValue ( self ::$ propertyUsedAsValue ->getId () ) )
215+ ->build ();
201216
202217 $ statementWithNoValue = NewStatement::noValueFor ( ( $ statementWithNoValuePropertyId ) )
203218 ->withGuid ( "$ itemId \$bed933b7-4207-d679-7571-3630cfb49d9f " )
@@ -237,6 +252,11 @@ public function queryProvider(): Generator {
237252 null ,
238253 'time ' ,
239254 );
255+ self ::$ propertyTypeProperty = new Property (
256+ new NumericPropertyId ( $ statementWithPropertyValuePropertyId ),
257+ null ,
258+ 'wikibase-property ' ,
259+ );
240260 self ::$ qualifierProperty = new Property (
241261 new NumericPropertyId ( $ qualifierPropertyId ),
242262 new Fingerprint ( new TermList ( [ new Term ( 'en ' , 'qualifier prop ' ) ] ) ),
@@ -255,6 +275,7 @@ public function queryProvider(): Generator {
255275 ->andStatement ( $ statementWithQuantityValue )
256276 ->andStatement ( $ statementWithUnboundedQuantityValue )
257277 ->andStatement ( $ statementWithTimeValue )
278+ ->andStatement ( $ statementWithPropertyValue )
258279 ->andStatement ( $ statementWithNoValue )
259280 ->andStatement ( $ statementWithSomeValue )
260281 ->build ();
@@ -549,6 +570,32 @@ public function queryProvider(): Generator {
549570 ],
550571 ],
551572 ];
573+ yield 'statement with property value ' => [
574+ "{ item(id: \"$ itemId \") {
575+ statements(propertyId: \"$ statementWithPropertyValuePropertyId \") {
576+ value {
577+ ... on PropertyValue {
578+ id
579+ label(languageCode: \"en \")
580+ }
581+ }
582+ }
583+ } } " ,
584+ [
585+ 'data ' => [
586+ 'item ' => [
587+ 'statements ' => [
588+ [
589+ 'value ' => [
590+ 'id ' => self ::$ propertyUsedAsValue ->getId ()->getSerialization (),
591+ 'label ' => self ::$ propertyUsedAsValue ->getLabels ()->getByLanguage ( 'en ' )->getText (),
592+ ],
593+ ],
594+ ],
595+ ],
596+ ],
597+ ],
598+ ];
552599 yield 'statements with novalue and somevalue ' => [
553600 "{ item(id: \"$ itemId \") {
554601 $ statementWithSomeValuePropertyId: statements(propertyId: \"$ statementWithSomeValuePropertyId \") {
0 commit comments