|
10 | 10 | use DataValues\StringValue; |
11 | 11 | use DataValues\TimeValue; |
12 | 12 | use DataValues\UnboundedQuantityValue; |
| 13 | +use DataValues\UnDeserializableValue; |
13 | 14 | use Generator; |
14 | 15 | use GraphQL\GraphQL; |
15 | 16 | use MediaWiki\Site\HashSiteStore; |
@@ -62,6 +63,7 @@ class GraphQLServiceTest extends MediaWikiIntegrationTestCase { |
62 | 63 | private static Property $propertyUsedAsValue; |
63 | 64 | private static Property $qualifierProperty; |
64 | 65 | private static Property $customEntityIdProperty; |
| 66 | + private static Property $unknownTypeProperty; |
65 | 67 | private static MediaWikiSite $sitelinkSite; |
66 | 68 | private const ALLOWED_SITELINK_SITES = [ 'examplewiki', 'otherwiki' ]; |
67 | 69 | private const CUSTOM_ENTITY_DATA_TYPE = 'test-type'; |
@@ -103,6 +105,7 @@ public function testQuery( string $query, array $expectedResult ): void { |
103 | 105 | self::$timeProperty, |
104 | 106 | self::$propertyTypeProperty, |
105 | 107 | self::$customEntityIdProperty, |
| 108 | + self::$unknownTypeProperty, |
106 | 109 | ] as $property ) { |
107 | 110 | $dataTypeLookup->setDataTypeForProperty( $property->getId(), $property->getDataTypeId() ); |
108 | 111 | } |
@@ -153,6 +156,7 @@ public function queryProvider(): Generator { |
153 | 156 | $statementWithCustomEntityIdValuePropertyId = 'P13'; |
154 | 157 | $statementWithItemValueQualifierPropertyId = $statementWithItemValuePropertyId; // also type wikibase-item so we can just reuse it. |
155 | 158 | $statementReferencePropertyId = 'P11'; |
| 159 | + $unknownTypePropertyId = 'P12'; |
156 | 160 | $unusedPropertyId = 'P9999'; |
157 | 161 | $qualifierStringValue = 'qualifierStringValue'; |
158 | 162 | $statementStringValue = 'statementStringValue'; |
@@ -227,6 +231,22 @@ public function queryProvider(): Generator { |
227 | 231 | ->withValue( new EntityIdValue( self::$propertyUsedAsValue->getId() ) ) |
228 | 232 | ->build(); |
229 | 233 |
|
| 234 | + self::$unknownTypeProperty = new Property( new NumericPropertyId( $unknownTypePropertyId ), null, 'unknown-type' ); |
| 235 | + $unknownValueData = [ 'some' => 'data' ]; |
| 236 | + $statementWithUnknownType = NewStatement::forProperty( $unknownTypePropertyId ) |
| 237 | + ->withSubject( $itemId ) |
| 238 | + ->withSomeGuid() |
| 239 | + // Ideally we would just stub DataValue here, but that's not possible because it extends Serializable, |
| 240 | + // which is deprecated and emits a warning. |
| 241 | + ->withValue( new UnDeserializableValue( $unknownValueData, null, 'test value' ) ); |
| 242 | + |
| 243 | + $deletedProperty = 'P999'; |
| 244 | + $valueUsedInStatementWithDeletedProperty = new StringValue( 'deleted value' ); |
| 245 | + $statementWithDeletedProperty = NewStatement::forProperty( $deletedProperty ) |
| 246 | + ->withSubject( $itemId ) |
| 247 | + ->withSomeGuid() |
| 248 | + ->withValue( $valueUsedInStatementWithDeletedProperty ); |
| 249 | + |
230 | 250 | $statementWithNoValue = NewStatement::noValueFor( ( $statementWithNoValuePropertyId ) ) |
231 | 251 | ->withSubject( $itemId ) |
232 | 252 | ->withSomeGuid() |
@@ -309,6 +329,8 @@ public function queryProvider(): Generator { |
309 | 329 | ->andStatement( $statementWithNoValue ) |
310 | 330 | ->andStatement( $statementWithSomeValue ) |
311 | 331 | ->andStatement( $statementWithCustomEntityIdValue ) |
| 332 | + ->andStatement( $statementWithUnknownType ) |
| 333 | + ->andStatement( $statementWithDeletedProperty ) |
312 | 334 | ->build(); |
313 | 335 |
|
314 | 336 | $item2Id = 'Q321'; |
@@ -655,6 +677,38 @@ public function queryProvider(): Generator { |
655 | 677 | ], |
656 | 678 | ], |
657 | 679 | ]; |
| 680 | + yield 'statement with unknown value type' => [ |
| 681 | + "{ item(id: \"$itemId\") { |
| 682 | + statements(propertyId: \"$unknownTypePropertyId\") { |
| 683 | + value { ...on UnknownValue { content } } |
| 684 | + } |
| 685 | + } }", |
| 686 | + [ |
| 687 | + 'data' => [ |
| 688 | + 'item' => [ |
| 689 | + 'statements' => [ |
| 690 | + [ 'value' => [ 'content' => $unknownValueData ] ], |
| 691 | + ], |
| 692 | + ], |
| 693 | + ], |
| 694 | + ], |
| 695 | + ]; |
| 696 | + yield 'statement with deleted property' => [ |
| 697 | + "{ item(id: \"$itemId\") { |
| 698 | + statements(propertyId: \"$deletedProperty\") { |
| 699 | + value { ...on UnknownValue { content } } |
| 700 | + } |
| 701 | + } }", |
| 702 | + [ |
| 703 | + 'data' => [ |
| 704 | + 'item' => [ |
| 705 | + 'statements' => [ |
| 706 | + [ 'value' => [ 'content' => $valueUsedInStatementWithDeletedProperty->getArrayValue() ] ], |
| 707 | + ], |
| 708 | + ], |
| 709 | + ], |
| 710 | + ], |
| 711 | + ]; |
658 | 712 | yield 'labels of predicate properties' => [ |
659 | 713 | "{ item(id: \"$itemId\") { |
660 | 714 | statements(propertyId: \"{$statementWithStringValuePropertyId}\") { |
|
0 commit comments