/** * Set up the test suite before each test */ public function setUp() { $this->graph = new EasyRdf_Graph(); $this->resource = $this->graph->resource('http://www.example.com/'); $this->parser = new MockParser(); $this->data = readFixture('foaf.json'); }
public function testGetDefault() { $this->client->addMock('GET', 'http://localhost:8080/data/?default', readFixture('foaf.json')); $graph = $this->graphStore->getDefault(); $this->assertClass('EasyRdf_Graph', $graph); $this->assertSame(null, $graph->getUri()); $this->assertStringEquals('Joe Bloggs', $graph->get('http://www.example.com/joe#me', 'foaf:name')); }
public function testQueryConstructJson() { $this->_client->addMock('GET', '/sparql?query=CONSTRUCT+%7B%3Fs+%3Fp+%3Fo%7D+WHERE+%7B%3Fs+%3Fp+%3Fo%7D', readFixture('foaf.json')); $graph = $this->_sparql->query("CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}"); $this->assertType('EasyRdf_Graph', $graph); $name = $graph->get('http://www.example.com/joe#me', 'foaf:name'); $this->assertStringEquals('Joe Bloggs', $name); }
public function testParseQuery() { $graph = new EasyRdf_Graph(); $graph->parse(readFixture('query/construct.ttl'), 'turtle'); $query = $graph->resource('test:construct'); $this->assertClass('EasySpinRdf_Query_Construct', $query); $this->assertStringEquals("CONSTRUCT { ?this test:grandParent ?grandParent } WHERE { ?parent test:child ?this. ?grandParent test:child ?parent }", $query->getSparql()); }
public function testGetIndirect() { $this->_client->addMock('GET', 'http://localhost:8080/data/?graph=http%3A%2F%2Ffoo.com%2Fbar.rdf', readFixture('foaf.json')); $graph = $this->_graphStore->get('http://foo.com/bar.rdf'); $this->assertType('EasyRdf_Graph', $graph); $this->assertEquals('http://foo.com/bar.rdf', $graph->getUri()); $this->assertStringEquals('Joe Bloggs', $graph->get('http://www.example.com/joe#me', 'foaf:name')); }
public function testParseQuery() { $graph = new EasyRdf_Graph(); $graph->parse(readFixture('query/ask.ttl'), 'turtle'); $query = $graph->resource('test:ask'); $this->assertClass('EasySpinRdf_Query_Ask', $query); $this->assertStringEquals("# must be 18 years old\nASK WHERE { ?this test:age 18 }", $query->getSparql()); }
public function testGetHeaders() { $response = EasyRdf_Http_Response::fromString(readFixture('http_response_200')); $this->assertEquals(8, count($response->getHeaders()), 'Header count is not as expected'); $this->assertEquals('Apache/2.2.9 (Unix) PHP/5.2.6', $response->getHeader('Server'), 'Server header is not as expected'); $this->assertEquals('text/plain', $response->getHeader('Content-Type'), 'Content-type header is not as expected'); $this->assertEquals(array('foo', 'bar'), $response->getHeader('X-Multiple'), 'Header with multiple values is not as expected'); }
public function testParseQuery() { $graph = new EasyRdf_Graph(); $graph->parse(readFixture('query/describe.ttl'), 'turtle'); $query = $graph->resource('test:describe'); $this->assertClass('EasySpinRdf_Query_Describe', $query); $this->assertStringEquals("DESCRIBE ?value WHERE { ?this test:uncle ?value }", $query->getSparql()); }
public function testParseWithFormatObject() { $data = readFixture('foaf.jsonld'); $format = EasyRdf_Format::getFormat('jsonld'); $count = $this->parser->parse($this->graph, $data, $format, null); $this->assertSame(14, $count); $joe = $this->graph->resource('http://www.example.com/joe#me'); $this->assertStringEquals('Joe Bloggs', $joe->get('foaf:name')); }
public function setUp() { if (extension_loaded('redland')) { $this->_parser = new EasyRdf_Parser_Redland(); $this->_graph = new EasyRdf_Graph(); $this->_data = readFixture('foaf.rdf'); } else { $this->markTestSkipped("Redland PHP extension is not available."); } }
public function setUp() { if (requireExists('arc/ARC2.php')) { $this->_parser = new EasyRdf_Parser_Arc(); $this->_graph = new EasyRdf_Graph(); $this->_data = readFixture('foaf.rdf'); } else { $this->markTestSkipped("ARC2 library is not available."); } }
public function testParseSeq() { $count = $this->parser->parse($this->graph, readFixture('rdf-seq.rdf'), 'rdfxml', 'http://www.w3.org/TR/REC-rdf-syntax/'); $this->assertSame(5, $count); $favourites = $this->graph->resource('http://example.org/favourite-fruit'); $this->assertSame('rdf:Seq', $favourites->type()); $this->assertStringEquals('http://example.org/banana', $favourites->get('rdf:_1')); $this->assertStringEquals('http://example.org/apple', $favourites->get('rdf:_2')); $this->assertStringEquals('http://example.org/pear', $favourites->get('rdf:_3')); $this->assertStringEquals('http://example.org/pear', $favourites->get('rdf:_4')); }
public function setUp() { // FIXME: suppress stderr // FIXME: check for rapper version 1.4.17 exec('which rapper', $output, $retval); if ($retval == 0) { $this->_parser = new EasyRdf_Parser_Rapper(); $this->_graph = new EasyRdf_Graph(); $this->_data = readFixture('foaf.rdf'); } else { $this->markTestSkipped("The rapper command is not available on this system."); } }
public function setUp() { $this->graph = new EasyRdf_Graph(); $this->graph->parse(readFixture('element/triple_path.ttl'), 'turtle'); }
public function testLoad() { EasyRdf_Http::setDefaultHttpClient($client = new EasyRdf_Http_MockClient()); $client->addMock('GET', 'http://example.com/foaf.json', readFixture('foaf.json')); $graph = new EasyRdf_Graph('http://example.com/'); $resource = $graph->resource('http://example.com/foaf.json'); $resource->load(); $this->assertStringEquals('Joe Bloggs', $graph->get('http://www.example.com/joe#me', 'foaf:name')); }
/** * @see https://github.com/njh/easyrdf/issues/115 */ public function testIssue115() { $triples = <<<RDF <http://example.com/id/1> <http://www.w3.org/2000/01/rdf-schema#type> <http://example.com/ns/animals/dog> . <http://example.com/id/2> <http://www.w3.org/2000/01/rdf-schema#type> <http://example.com/ns/animals/cat> . <http://example.com/id/3> <http://www.w3.org/2000/01/rdf-schema#type> <http://example.com/ns/animals/bird> . <http://example.com/id/4> <http://www.w3.org/2000/01/rdf-schema#type> <http://example.com/ns/animals/reptiles/snake> . RDF; EasyRdf_Namespace::set('id', 'http://example.com/id/'); EasyRdf_Namespace::set('animals', 'http://example.com/ns/animals/'); // parse graph $graph = new EasyRdf_Graph(); $graph->parse($triples, 'ntriples'); // dump as text/turtle $turtle = $graph->serialise('turtle'); $this->assertEquals(readFixture('turtle/gh115-nested-namespaces.ttl'), $turtle); }
public function setUp() { $this->graph = new EasyRdf_Graph(); $this->parser = new EasyRdf_Parser_Ntriples(); $this->data = readFixture('foaf.nt'); }
/** * Set up the test suite before each test */ public function setUp() { $this->_graph = new EasyRdf_Graph(); $this->_parser = new MockParser(); $this->_data = readFixture('foaf.json'); }
public function testArrayOffsetGet() { $count = $this->graph->parse(readFixture('rdf-collection.rdf'), 'rdfxml'); $owner = $this->graph->resource('ex:owner'); $pets = $owner->get('ex:pets'); $this->assertStringEquals('http://example.org/rat', $pets[1]); $this->assertStringEquals('http://example.org/cat', $pets[2]); $this->assertStringEquals('http://example.org/goat', $pets[3]); }
public function testPrimaryTopic() { $data = readFixture('foaf.json'); $graph = new EasyRdf_Graph('http://www.example.com/joe/foaf.rdf', $data); $this->assertEquals('http://www.example.com/joe#me', $graph->primaryTopic()->getUri()); }
public function testToStringSelectAll() { $result = new EasyRdf_Sparql_Result(readFixture('sparql_select_all.xml'), 'application/sparql-results+xml'); $string = strval($result); $this->assertContains('+-------------------------------------+', $string); $this->assertContains('| http://www.example.com/joe#me |', $string); }
public function testArrayOffsetGet() { $this->graph->parse(readFixture('rdf-seq.rdf'), 'rdfxml', 'http://www.w3.org/TR/REC-rdf-syntax/'); $favourites = $this->graph->resource('ex:favourite-fruit'); $this->assertStringEquals('http://example.org/banana', $favourites[1]); $this->assertStringEquals('http://example.org/apple', $favourites[2]); $this->assertStringEquals('http://example.org/pear', $favourites[3]); $this->assertStringEquals('http://example.org/pear', $favourites[4]); }
public function testAsString() { $responseStr = readFixture('http_response_404'); $response = EasyRdf_Http_Response::fromString($responseStr); $this->assertSame(strtolower($responseStr), strtolower($response->asString()), 'Response convertion to string does not match original string'); $this->assertSame(strtolower($responseStr), strtolower((string) $response), 'Response convertion to string does not match original string'); }
public function testQueryConstructJsonWithCharset() { $this->_client->addMock('GET', '/sparql?query=CONSTRUCT+%7B%3Fs+%3Fp+%3Fo%7D+WHERE+%7B%3Fs+%3Fp+%3Fo%7D', readFixture('foaf.json'), array('headers' => array('Content-Type' => 'application/json; charset=utf-8'))); $graph = $this->_sparql->query("CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}"); $this->assertClass('EasyRdf_Graph', $graph); $name = $graph->get('http://www.example.com/joe#me', 'foaf:name'); $this->assertStringEquals('Joe Bloggs', $name); }
protected function parseNtriples($filename) { $graph = new EasyRdf_Graph(); $this->_ntriplesParser->parse($graph, readFixture($filename), 'ntriples', $this->_baseUri . basename($filename)); return $graph->serialise('ntriples-array'); }
public function testInstantiate() { EasyRdf_TypeMapper::set('foaf:Person', 'MyType_Class'); $data = readFixture('foaf.json'); $graph = new EasyRdf_Graph('http://www.example.com/joe/foaf.rdf', $data, 'json'); $joe = $graph->resource('http://www.example.com/joe#me'); $this->assertClass('MyType_Class', $joe); $this->assertTrue($joe->myMethod()); }
public function testListNamedGraphsWithLimit() { $this->client->addMock('GET', '/sparql?query=SELECT+DISTINCT+%3Fg+WHERE+%7BGRAPH+%3Fg+%7B%3Fs+%3Fp+%3Fo%7D%7D+LIMIT+10', readFixture('sparql_select_named_graphs.json'), array('headers' => array('Content-Type' => 'application/sparql-results+json; charset=utf-8'))); $list = $this->sparql->listNamedGraphs(10); $this->assertCount(3, $list); $this->assertEquals(new EasyRdf_Resource('http://example.org/0'), $list[0]); $this->assertEquals(new EasyRdf_Resource('http://example.org/1'), $list[1]); $this->assertEquals(new EasyRdf_Resource('http://example.org/2'), $list[2]); }
public function testParseXMLLiteral() { $count = $this->parser->parse($this->graph, readFixture('xml_literal.rdf'), 'rdfxml', 'http://www.example.com/'); $this->assertSame(2, $count); $doc = $this->graph->resource('http://www.example.com/'); $this->assertSame('foaf:Document', $doc->type()); $description = $doc->get('dc:description'); $this->assertSame('rdf:XMLLiteral', $description->getDataType()); $this->assertSame("\n <p>Here is a block of <em>HTML text</em></p>\n ", $description->getValue()); }
public function setUp() { $this->_graph = new EasyRdf_Graph(); $this->_parser = new EasyRdf_Parser_RdfXml(); $this->_data = readFixture('foaf.rdf'); }
public function testGuessFormatRdfa() { $data = readFixture('foaf.html'); $this->assertEquals('rdfa', EasyRdf_Format::guessFormat($data)); }