|
4 | 4 |
|
5 | 5 | namespace Cortex\JsonSchema\Tests\Unit\Types; |
6 | 6 |
|
| 7 | +use ReflectionClass; |
7 | 8 | use Cortex\JsonSchema\Schema; |
8 | 9 | use Cortex\JsonSchema\Enums\SchemaFormat; |
9 | 10 | use Cortex\JsonSchema\Types\StringSchema; |
10 | 11 | use Cortex\JsonSchema\Enums\SchemaVersion; |
| 12 | +use Cortex\JsonSchema\Enums\SchemaFeature; |
11 | 13 | use Cortex\JsonSchema\Exceptions\SchemaException; |
12 | 14 |
|
13 | 15 | covers(StringSchema::class); |
|
275 | 277 | 'Feature "Schema for decoded content" is not supported in Draft 7. Minimum version required: Draft 2019-09.', |
276 | 278 | ); |
277 | 279 | }); |
| 280 | + |
| 281 | +it('detects content features correctly', function (): void { |
| 282 | + $stringSchema = Schema::string('payload', SchemaVersion::Draft_2019_09); |
| 283 | + $stringSchema->contentEncoding('base64') |
| 284 | + ->contentMediaType('application/json') |
| 285 | + ->contentSchema(Schema::object()); |
| 286 | + |
| 287 | + $reflection = new ReflectionClass($stringSchema); |
| 288 | + $contentFeaturesMethod = $reflection->getMethod('getContentFeatures'); |
| 289 | + |
| 290 | + $contentFeatures = $contentFeaturesMethod->invoke($stringSchema); |
| 291 | + |
| 292 | + expect($contentFeatures)->toContain(SchemaFeature::ContentEncoding); |
| 293 | + expect($contentFeatures)->toContain(SchemaFeature::ContentMediaType); |
| 294 | + expect($contentFeatures)->toContain(SchemaFeature::ContentSchema); |
| 295 | + |
| 296 | + // Test that features are included in overall feature detection |
| 297 | + $getUsedMethod = $reflection->getMethod('getUsedFeatures'); |
| 298 | + |
| 299 | + $allFeatures = $getUsedMethod->invoke($stringSchema); |
| 300 | + expect($allFeatures)->toContain(SchemaFeature::ContentEncoding); |
| 301 | + expect($allFeatures)->toContain(SchemaFeature::ContentMediaType); |
| 302 | + expect($allFeatures)->toContain(SchemaFeature::ContentSchema); |
| 303 | +}); |
0 commit comments