9
9
10
10
namespace JsonSchema \Tests \Drafts ;
11
11
12
+ use JsonSchema \Constraints \Factory ;
13
+ use JsonSchema \SchemaStorage ;
14
+ use JsonSchema \Validator ;
15
+
12
16
/**
13
17
* @package JsonSchema\Tests\Drafts
14
18
*/
@@ -17,6 +21,56 @@ class Draft3Test extends BaseDraftTestCase
17
21
protected $ schemaSpec = 'http://json-schema.org/draft-03/schema# ' ;
18
22
protected $ validateSchema = true ;
19
23
24
+ /**
25
+ * This test is a copy of https://github.com/json-schema-org/JSON-Schema-Test-Suite/blob/main/tests/draft3/ref.json#L203-L225
26
+ *
27
+ * @todo cleanup when #821 gets merged
28
+ *
29
+ * @param mixed $data
30
+ * @dataProvider refPreventsASiblingIdFromChangingTheBaseUriProvider
31
+ */
32
+ public function testRefPreventsASiblingIdFromChangingTheBaseUriProvider ($ data , bool $ expectedResult ): void
33
+ {
34
+ $ schema = json_decode (<<<'JSON'
35
+ {
36
+ "id": "http://localhost:1234/sibling_id/base/",
37
+ "definitions": {
38
+ "foo": {
39
+ "id": "http://localhost:1234/sibling_id/foo.json",
40
+ "type": "string"
41
+ },
42
+ "base_foo": {
43
+ "$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json",
44
+ "id": "foo.json",
45
+ "type": "number"
46
+ }
47
+ },
48
+ "extends": [
49
+ {
50
+ "$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not http://localhost:1234/sibling_id/foo.json",
51
+ "id": "http://localhost:1234/sibling_id/",
52
+ "$ref": "foo.json"
53
+ }
54
+ ]
55
+ }
56
+ JSON
57
+ , false );
58
+
59
+ $ schemaStorage = new SchemaStorage ();
60
+ $ schemaStorage ->addSchema (property_exists ($ schema , 'id ' ) ? $ schema ->id : 'internal://mySchema ' , $ schema );
61
+ $ validator = new Validator (new Factory ($ schemaStorage ));
62
+ $ validator ->validate ($ data , $ schema );
63
+
64
+ self ::assertEquals ($ expectedResult , $ validator ->isValid ());
65
+ }
66
+
67
+ public function refPreventsASiblingIdFromChangingTheBaseUriProvider (): \Generator
68
+ {
69
+ yield '$ref resolves to /definitions/base_foo, data does not validate ' => ['data ' => 'a ' , 'valid ' => false ];
70
+ yield '$ref resolves to /definitions/base_foo, data validate ' => ['data ' => 1 , 'valid ' => true ];
71
+ }
72
+
73
+
20
74
/**
21
75
* {@inheritdoc}
22
76
*/
0 commit comments