public function run($manifests) { /* Manifest format: { name: <optional manifest name>, sequence: [{ 'name': <test name>, '@type': ["test:TestCase", "jld:<type of test>"], 'input': <input file for test>, 'context': <context file for add context test type>, 'frame': <frame file for frame test type>, 'expect': <expected result file>, }] } */ global $eol; foreach ($manifests as $manifest) { if (property_exists($manifest, 'name')) { $this->group($manifest->name); } $filepath = $manifest->filepath; foreach ($manifest->sequence as $test) { // read test input files $type = $test->{'@type'}; $options = array('base' => 'http://json-ld.org/test-suite/tests/' . $test->input); try { if (in_array('jld:NormalizeTest', $type)) { $this->test($test->name); $input = read_test_json($test->input, $filepath); $test->expect = read_test_nquads($test->expect, $filepath); $options['format'] = 'application/nquads'; $result = jsonld_normalize($input, $options); } else { if (in_array('jld:ExpandTest', $type)) { $this->test($test->name); $input = read_test_json($test->input, $filepath); $test->expect = read_test_json($test->expect, $filepath); $result = jsonld_expand($input, $options); } else { if (in_array('jld:CompactTest', $type)) { $this->test($test->name); $input = read_test_json($test->input, $filepath); $test->context = read_test_json($test->context, $filepath); $test->expect = read_test_json($test->expect, $filepath); $result = jsonld_compact($input, $test->context, $options); } else { if (in_array('jld:FrameTest', $type)) { $this->test($test->name); $input = read_test_json($test->input, $filepath); $test->frame = read_test_json($test->frame, $filepath); $test->expect = read_test_json($test->expect, $filepath); $result = jsonld_frame($input, $test->frame, $options); } else { if (in_array('jld:FromRDFTest', $type)) { $this->test($test->name); $input = read_test_nquads($test->input, $filepath); $test->expect = read_test_json($test->expect, $filepath); $result = jsonld_from_rdf($input, $options); } else { if (in_array('jld:ToRDFTest', $type)) { $this->test($test->name); $input = read_test_json($test->input, $filepath); $test->expect = read_test_nquads($test->expect, $filepath); $options['format'] = 'application/nquads'; $result = jsonld_to_rdf($input, $options); } else { echo "Skipping test \"{$test->name}\" of type: " . json_encode($type) . $eol; continue; } } } } } } // check results $this->check($test, $test->expect, $result); } catch (JsonLdException $e) { echo $eol . $e; $this->failed += 1; echo "FAIL{$eol}"; } } if (property_exists($manifest, 'name')) { $this->ungroup(); } } }
/** * **Experimental** * * Links a JSON-LD document's nodes in memory. * * @param mixed $input the JSON-LD document to link. * @param mixed $ctx the JSON-LD context to apply or null. * @param assoc [$options] the options to use: * [base] the base IRI to use. * [expandContext] a context to expand with. * [documentLoader(url)] the document loader. * * @return the linked JSON-LD output. */ function jsonld_link($input, $ctx, $options) { // API matches running frame with a wildcard frame and embed: '@link' // get arguments $frame = new stdClass(); if ($ctx) { $frame->{'@context'} = $ctx; } $frame->{'@embed'} = '@link'; return jsonld_frame($input, $frame, $options); }