@@ -32,7 +32,9 @@ def containers
32
32
"homepage": {"@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id"},
33
33
"avatar": {"@id": "http://xmlns.com/foaf/0.1/avatar", "@type": "@id"}
34
34
}
35
- }) , base_uri : "http://example.com/context" )
35
+ }) ,
36
+ base_uri : "http://example.com/context" ,
37
+ headers : { content_type : "application/ld+json" } )
36
38
end
37
39
subject { context }
38
40
@@ -78,6 +80,90 @@ def containers
78
80
} , logger )
79
81
end
80
82
83
+ it "retrieves and parses a remote context document in HTML using the context profile" do
84
+ remote_doc =
85
+ RDF ::Util ::File ::RemoteDocument . new ( %q(
86
+ <html><head>
87
+ <script>Not This</script>
88
+ <script type="application/ld+json">
89
+ {
90
+ "@context": {
91
+ "homepage": {"@id": "http://example.com/this-would-be-wrong", "@type": "@id"},
92
+ "avatar": {"@id": "http://example.com/this-would-be-wrong", "@type": "@id"}
93
+ }
94
+ }
95
+ </script>
96
+ <script type="application/ld+json;profile=http://www.w3.org/ns/json-ld#context">
97
+ {
98
+ "@context": {
99
+ "xsd": "http://www.w3.org/2001/XMLSchema#",
100
+ "name": "http://xmlns.com/foaf/0.1/name",
101
+ "homepage": {"@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id"},
102
+ "avatar": {"@id": "http://xmlns.com/foaf/0.1/avatar", "@type": "@id"}
103
+ }
104
+ }
105
+ </script>
106
+ <script type="application/ld+json;profile=http://www.w3.org/ns/json-ld#context">
107
+ {
108
+ "@context": {
109
+ "homepage": {"@id": "http://example.com/this-would-also-be-wrong", "@type": "@id"},
110
+ "avatar": {"@id": "http://example.com/this-would-also-be-wrong", "@type": "@id"}
111
+ }
112
+ }
113
+ </script>
114
+ </head></html>
115
+ ) ,
116
+ base_uri : "http://example.com/context" ,
117
+ headers : { content_type : "text/html" } )
118
+ JSON ::LD ::Context ::PRELOADED . clear
119
+ expect ( JSON ::LD ::API ) . to receive ( :documentLoader ) . with ( "http://example.com/context" , anything ) . and_yield ( remote_doc )
120
+ ec = subject . parse ( "http://example.com/context" )
121
+ expect ( ec . send ( :mappings ) ) . to produce ( {
122
+ "xsd" => "http://www.w3.org/2001/XMLSchema#" ,
123
+ "name" => "http://xmlns.com/foaf/0.1/name" ,
124
+ "homepage" => "http://xmlns.com/foaf/0.1/homepage" ,
125
+ "avatar" => "http://xmlns.com/foaf/0.1/avatar"
126
+ } , logger )
127
+ end
128
+
129
+ it "retrieves and parses a remote context document in HTML" do
130
+ remote_doc =
131
+ RDF ::Util ::File ::RemoteDocument . new ( %q(
132
+ <html><head>
133
+ <script>Not This</script>
134
+ <script type="application/ld+json">
135
+ {
136
+ "@context": {
137
+ "xsd": "http://www.w3.org/2001/XMLSchema#",
138
+ "name": "http://xmlns.com/foaf/0.1/name",
139
+ "homepage": {"@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id"},
140
+ "avatar": {"@id": "http://xmlns.com/foaf/0.1/avatar", "@type": "@id"}
141
+ }
142
+ }
143
+ </script>
144
+ <script type="application/ld+json">
145
+ {
146
+ "@context": {
147
+ "homepage": {"@id": "http://example.com/this-would-also-be-wrong", "@type": "@id"},
148
+ "avatar": {"@id": "http://example.com/this-would-also-be-wrong", "@type": "@id"}
149
+ }
150
+ }
151
+ </script>
152
+ </head></html>
153
+ ) ,
154
+ base_uri : "http://example.com/context" ,
155
+ headers : { content_type : "text/html" } )
156
+ JSON ::LD ::Context ::PRELOADED . clear
157
+ expect ( JSON ::LD ::API ) . to receive ( :documentLoader ) . with ( "http://example.com/context" , anything ) . and_yield ( remote_doc )
158
+ ec = subject . parse ( "http://example.com/context" )
159
+ expect ( ec . send ( :mappings ) ) . to produce ( {
160
+ "xsd" => "http://www.w3.org/2001/XMLSchema#" ,
161
+ "name" => "http://xmlns.com/foaf/0.1/name" ,
162
+ "homepage" => "http://xmlns.com/foaf/0.1/homepage" ,
163
+ "avatar" => "http://xmlns.com/foaf/0.1/avatar"
164
+ } , logger )
165
+ end
166
+
81
167
it "notes non-existing @context" do
82
168
expect { subject . parse ( StringIO . new ( "{}" ) ) } . to raise_error ( JSON ::LD ::JsonLdError ::InvalidRemoteContext )
83
169
end
@@ -376,6 +462,16 @@ def containers
376
462
"@prefix string" => { "foo" => { "@id" => 'http://example.org/' , "@prefix" => "str" } } ,
377
463
"@prefix array" => { "foo" => { "@id" => 'http://example.org/' , "@prefix" => [ ] } } ,
378
464
"@prefix object" => { "foo" => { "@id" => 'http://example.org/' , "@prefix" => { } } } ,
465
+ "IRI term expands to different IRI" => {
466
+ "ex" => "http://example.com/" ,
467
+ "ex2" => "http://example.com/2/" ,
468
+ "ex:foo" => "ex2:foo"
469
+ } ,
470
+ "IRI term expands to different IRI (reverse)" => {
471
+ "ex" => "http://example.com/" ,
472
+ "ex2" => "http://example.com/2/" ,
473
+ "ex:foo" => { "@reverse" => "ex2:foo" }
474
+ }
379
475
} . each do |title , context |
380
476
it title do
381
477
expect {
0 commit comments