Example #1
0
 /**
  * Tests the expansion API
  *
  * @group expansion
  */
 public function testExpansion()
 {
     $path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR;
     $expected = json_decode(file_get_contents($path . 'sample-expanded.jsonld'));
     $input = $path . 'sample-in.jsonld';
     $this->assertJsonEquals($expected, JsonLD::expand($input), 'Passing the file path');
     $input = file_get_contents($input);
     $this->assertJsonEquals($expected, JsonLD::expand($input), 'Passing the raw input (string)');
     $input = json_decode($input);
     $this->assertJsonEquals($expected, JsonLD::expand($input), 'Passing the parsed object');
 }
Example #2
0
 /**
  * Get a certain dataset
  *
  * @param string $id The id of the dataset
  *
  * @return EasyRdf_Resource
  */
 public function get($id)
 {
     $uri = \URL::to('/users/' . $id);
     $collection = $this->getMongoCollection();
     $cursor = $collection->find(['@id' => $uri]);
     if ($cursor->hasNext()) {
         $jsonLd = $cursor->getNext();
         unset($jsonLd['_id']);
         $expand = JsonLD::expand(json_encode($jsonLd));
         $jsonLd = (array) $expand;
         $graph = new \EasyRdf_Graph();
         $json_ld = json_encode($jsonLd);
         $graph->parse($json_ld, 'jsonld');
         return $graph;
     } else {
         return [];
     }
 }
Example #3
0
    }
  ],
  "@embedChildren": false,
  "supportedProperties": {
    "@default": [ ],
    "@embed": true
  },
  "supportedOperations": {
    "@default": [ ],
    "@embed": true,
    "expects": { "@default": null, "@embed": false },
    "statusCodes": { "@default": [], "@embed": true }
  }
}
    ';
        $document = JsonLD::toString(JsonLD::frame(JsonLD::expand($document, $options), $frame));
        $headers['Content-Type'] = 'application/ld+json';
    } catch (Exception $e) {
        $exceptionName = get_class($e);
        if (false !== ($pos = strrpos(get_class($e), '\\'))) {
            $exceptionName = substr($exceptionName, $pos + 1);
        }
        header('HTTP/1.1 400 ' . $exceptionName);
        //Bad Request');
        print htmlspecialchars($e->getMessage());
        die;
    }
};
$proxy = new AjaxProxy();
if ($debug) {
    $proxy->setResponseModifier($debugExpansion);
Example #4
0
 /**
  * Tests remote document loading.
  *
  * @param string $name    The test name.
  * @param object $test    The test definition.
  * @param object $options The options to configure the algorithms.
  *
  * @group remote
  * @dataProvider remoteDocumentLoadingProvider
  */
 public function testRemoteDocumentLoading($name, $test, $options)
 {
     if (in_array('jld:NegativeEvaluationTest', $test->{'@type'})) {
         $this->setExpectedException('ML\\JsonLD\\Exception\\JsonLdException', '', $test->{'expect'});
     } else {
         $expected = json_decode(file_get_contents($this->basedir . $test->{'expect'}));
     }
     unset($options->base);
     $result = JsonLD::expand($this->baseurl . $test->{'input'}, $options);
     if (isset($expected)) {
         $this->assertJsonEquals($expected, $result);
     }
 }