@@ -130,6 +130,42 @@ public function testNormalize($test) {
130
130
$ test ->run ('jsonld_normalize ' , array ($ input , $ options ));
131
131
}
132
132
133
+ /**
134
+ * Tests URGNA2012 normalization.
135
+ *
136
+ * @param JsonLdTest $test the test to run.
137
+ *
138
+ * @group normalize
139
+ * @dataProvider urgna2012Provider
140
+ */
141
+ public function testUrgna2012 ($ test ) {
142
+ $ this ->test = $ test ;
143
+ $ input = $ test ->readProperty ('action ' );
144
+ $ options = $ test ->createOptions (array (
145
+ 'algorithm ' => 'URGNA2012 ' ,
146
+ 'inputFormat ' => 'application/nquads ' ,
147
+ 'format ' => 'application/nquads ' ));
148
+ $ test ->run ('jsonld_normalize ' , array ($ input , $ options ));
149
+ }
150
+
151
+ /**
152
+ * Tests URDNA2015 normalization.
153
+ *
154
+ * @param JsonLdTest $test the test to run.
155
+ *
156
+ * @group normalize
157
+ * @dataProvider urdna2015Provider
158
+ */
159
+ public function testUrdna2015 ($ test ) {
160
+ $ this ->test = $ test ;
161
+ $ input = $ test ->readProperty ('action ' );
162
+ $ options = $ test ->createOptions (array (
163
+ 'algorithm ' => 'URDNA2015 ' ,
164
+ 'inputFormat ' => 'application/nquads ' ,
165
+ 'format ' => 'application/nquads ' ));
166
+ $ test ->run ('jsonld_normalize ' , array ($ input , $ options ));
167
+ }
168
+
133
169
public function expandProvider () {
134
170
return new JsonLdTestIterator ('jld:ExpandTest ' );
135
171
}
@@ -157,6 +193,14 @@ public function normalizeProvider() {
157
193
public function frameProvider () {
158
194
return new JsonLdTestIterator ('jld:FrameTest ' );
159
195
}
196
+
197
+ public function urgna2012Provider () {
198
+ return new JsonLdTestIterator ('rdfn:Urgna2012EvalTest ' );
199
+ }
200
+
201
+ public function urdna2015Provider () {
202
+ return new JsonLdTestIterator ('rdfn:Urdna2015EvalTest ' );
203
+ }
160
204
}
161
205
162
206
class JsonLdManifest {
@@ -167,8 +211,14 @@ public function __construct($data, $filename) {
167
211
}
168
212
169
213
public function load (&$ tests ) {
170
- $ sequence = JsonLdProcessor::getValues ($ this ->data , 'sequence ' );
171
- foreach ($ sequence as $ entry ) {
214
+ $ entries = array_merge (
215
+ JsonLdProcessor::getValues ($ this ->data , 'sequence ' ),
216
+ JsonLdProcessor::getValues ($ this ->data , 'entries ' ));
217
+ $ includes = JsonLdProcessor::getValues ($ this ->data , 'include ' );
218
+ foreach ($ includes as $ include ) {
219
+ array_push ($ entries , $ include . '.jsonld ' );
220
+ }
221
+ foreach ($ entries as $ entry ) {
172
222
if (is_string ($ entry )) {
173
223
$ filename = join (
174
224
DIRECTORY_SEPARATOR , array ($ this ->dirname , $ entry ));
@@ -177,14 +227,17 @@ public function load(&$tests) {
177
227
$ filename = $ this ->filename ;
178
228
}
179
229
180
- if (JsonLdProcessor::hasValue ($ entry , '@type ' , 'mf:Manifest ' )) {
230
+ if (JsonLdProcessor::hasValue ($ entry , '@type ' , 'mf:Manifest ' ) ||
231
+ JsonLdProcessor::hasValue ($ entry , 'type ' , 'mf:Manifest ' )) {
181
232
// entry is another manifest
182
233
$ manifest = new JsonLdManifest ($ entry , $ filename );
183
234
$ manifest ->load ($ tests );
184
235
} else {
185
236
// assume entry is a test
186
237
$ test = new JsonLdTest ($ this , $ entry , $ filename );
187
- $ types = JsonLdProcessor::getValues ($ test ->data , '@type ' );
238
+ $ types = array_merge (
239
+ JsonLdProcessor::getValues ($ test ->data , '@type ' ),
240
+ JsonLdProcessor::getValues ($ test ->data , 'type ' ));
188
241
foreach ($ types as $ type ) {
189
242
if (!isset ($ tests [$ type ])) {
190
243
$ tests [$ type ] = array ();
@@ -202,27 +255,64 @@ public function __construct($manifest, $data, $filename) {
202
255
$ this ->data = $ data ;
203
256
$ this ->filename = $ filename ;
204
257
$ this ->dirname = dirname ($ filename );
205
- $ this ->isPositive = JsonLdProcessor::hasValue (
206
- $ data , '@type ' , 'jld:PositiveEvaluationTest ' );
207
- $ this ->isNegative = JsonLdProcessor::hasValue (
208
- $ data , '@type ' , 'jld:NegativeEvaluationTest ' );
258
+ $ this ->isPositive =
259
+ JsonLdProcessor::hasValue (
260
+ $ data , '@type ' , 'jld:PositiveEvaluationTest ' ) ||
261
+ JsonLdProcessor::hasValue (
262
+ $ data , 'type ' , 'jld:PositiveEvaluationTest ' );
263
+ $ this ->isNegative =
264
+ JsonLdProcessor::hasValue (
265
+ $ data , '@type ' , 'jld:NegativeEvaluationTest ' ) ||
266
+ JsonLdProcessor::hasValue (
267
+ $ data , 'type ' , 'jld:NegativeEvaluationTest ' );
209
268
210
269
// generate test name
211
- $ this ->name = $ manifest ->data ->name . ' ' . substr ($ data ->{'@id ' }, 2 ) .
212
- ' - ' . $ this ->data ->name ;
270
+ if (isset ($ manifest ->data ->name )) {
271
+ $ manifestLabel = $ manifest ->data ->name ;
272
+ } else if (isset ($ manifest ->data ->label )) {
273
+ $ manifestLabel = $ manifest ->data ->label ;
274
+ } else {
275
+ $ manifestLabel = 'UNNAMED ' ;
276
+ }
277
+ if (isset ($ this ->data ->id )) {
278
+ $ testId = $ this ->data ->id ;
279
+ } else {
280
+ $ testId = $ this ->data ->{'@id ' };
281
+ }
282
+ if (isset ($ this ->data ->name )) {
283
+ $ testLabel = $ this ->data ->name ;
284
+ } else if (isset ($ this ->data ->label )) {
285
+ $ testLabel = $ this ->data ->label ;
286
+ } else {
287
+ $ testLabel = 'UNNAMED ' ;
288
+ }
289
+
290
+ $ this ->name = $ manifestLabel . ' ' . $ testId . ' - ' . $ testLabel ;
213
291
214
292
// expand @id and input base
215
- $ data ->{'@id ' } = ($ manifest ->data ->baseIri .
216
- basename ($ manifest ->filename ) . $ data ->{'@id ' });
217
- $ this ->base = $ manifest ->data ->baseIri . $ data ->input ;
293
+ if (isset ($ manifest ->data ->baseIri )) {
294
+ $ data ->{'@id ' } = ($ manifest ->data ->baseIri .
295
+ basename ($ manifest ->filename ) . $ data ->{'@id ' });
296
+ $ this ->base = $ manifest ->data ->baseIri . $ data ->input ;
297
+ }
298
+ }
299
+
300
+ private function _getResultProperty () {
301
+ if (isset ($ this ->data ->expect )) {
302
+ return 'expect ' ;
303
+ } else if (isset ($ this ->data ->result )) {
304
+ return 'result ' ;
305
+ } else {
306
+ throw new Exception ('No test result property found. ' );
307
+ }
218
308
}
219
309
220
310
public function run ($ fn , $ params ) {
221
311
// read expected data
222
312
if ($ this ->isNegative ) {
223
313
$ this ->expected = $ this ->data ->expect ;
224
314
} else {
225
- $ this ->expected = $ this ->readProperty (' expect ' );
315
+ $ this ->expected = $ this ->readProperty ($ this -> _getResultProperty () );
226
316
}
227
317
228
318
try {
@@ -232,11 +322,14 @@ public function run($fn, $params) {
232
322
}
233
323
PHPUnit_Framework_TestCase::assertEquals ($ this ->expected , $ this ->actual );
234
324
} catch (Exception $ e ) {
235
- if ($ this ->isPositive ) {
325
+ // assume positive test
326
+ if ($ this ->isNegative ) {
327
+ $ this ->actual = $ this ->getJsonLdErrorCode ($ e );
328
+ PHPUnit_Framework_TestCase::assertEquals (
329
+ $ this ->expected , $ this ->actual );
330
+ } else {
236
331
throw $ e ;
237
332
}
238
- $ this ->actual = $ this ->getJsonLdErrorCode ($ e );
239
- PHPUnit_Framework_TestCase::assertEquals ($ this ->expected , $ this ->actual );
240
333
}
241
334
}
242
335
@@ -541,8 +634,16 @@ public function addFailure(
541
634
PHPUnit_Framework_AssertionFailedError $ e , $ time ) {
542
635
$ this ->addAssertion ($ test ->test , false );
543
636
if ($ test ->result ->shouldStop ()) {
637
+ if (isset ($ test ->test ->name )) {
638
+ $ name = $ test ->test ->name ;
639
+ } else if (isset ($ test ->test ->label )) {
640
+ $ name = $ test ->test ->label ;
641
+ } else {
642
+ $ name = 'UNNAMED ' ;
643
+ }
644
+ // FIXME
544
645
printf ("\n\nFAILED \n" );
545
- printf ("Test: %s \n" , $ test -> test -> name );
646
+ printf ("Test: %s \n" , $ name );
546
647
printf ("Purpose: %s \n" , $ test ->test ->data ->purpose );
547
648
printf ("EXPECTED: %s \n" , Util::jsonldEncode ($ test ->test ->expected ));
548
649
printf ("ACTUAL: %s \n" , Util::jsonldEncode ($ test ->test ->actual ));
0 commit comments