function test_to_html_renders_bnodes_as_anchors() { $g = new SimpleGraph(); $g->from_rdfxml($this->_single_triple); $g->add_resource_triple('http://example.org/subj', 'http://example.org/pred', '_:bn123'); $g->add_resource_triple('_:bn123', 'http://example.org/pred', 'http://example.org/obj'); $html = $g->to_html(); $this->assertContains('<a href="http://example.org/subj">subj</a>', $html, "html should contain links to bnode anchors"); $this->assertContains('<a href="#bn123">_:bn123</a>', $html, "html should contain links to bnode anchors"); $this->assertContains('<a id="bn123" href="#bn123">_:bn123</a>', $html, "html should contain anchors for bnodes"); }
function test_add_rdfxml_ignores_duplicate_triples() { $g = new SimpleGraph(); $g->from_rdfxml($this->_single_triple); $g->add_rdfxml($this->_single_triple); $this->assertEquals(1, count($g->get_triples())); }
function test_update_adds_bnode() { $fake_request_factory = new FakeRequestFactory(); $fake_response = new HttpResponse(); $fake_response->status_code = 200; $fake_response->body = $this->_select_result2; $query = "select ?_uri ?name where { optional {?_uri <http://example.org/name> ?name. } }"; $fake_request = new FakeHttpRequest($fake_response); $fake_request_factory->register('GET', "http://example.org/store/services/sparql?query=" . urlencode($query) . '&output=json', $fake_request); $fake_request_cs = new FakeHttpRequest(new HttpResponse()); $fake_request_factory->register('POST', "http://example.org/store/meta", $fake_request_cs); $dt = new DataTable("http://example.org/store", null, $fake_request_factory); $dt->map('http://example.org/name', 'name'); $dt->set('name', 'foo', 'bnode'); $dt->update(); $cs = new SimpleGraph(); $cs->from_rdfxml($fake_request_cs->get_body()); $changesets = $cs->get_subjects_of_type(CS_CHANGESET); $this->assertEquals(1, count($changesets)); $additions = $cs->get_resource_triple_values($changesets[0], CS_ADDITION); $this->assertEquals(1, count($additions)); $this->assertTrue($cs->has_resource_triple($additions[0], RDF_OBJECT, "_:foo")); }
/** * Execute a graph type sparql query and obtain the result as a SimpleGraph. An empty SimpleGraph is returned if any HTTP errors occur. * @param string query the describe or construct query to execute * @return SimpleGraph */ function graph_to_simple_graph($query) { $graph = new SimpleGraph(); $response = $this->graph($query); if ($response->is_success()) { $graph->from_rdfxml($response->body); } return $graph; }
function test_store_data_sends_simple_graph_as_turtle() { $fake_request_factory = new FakeRequestFactory(); $fake_request = new FakeHttpRequest(new HttpResponse()); $fake_request_factory->register('POST', "http://example.org/store/meta", $fake_request); $g = new SimpleGraph(); $g->from_rdfxml($this->_rdfxml_doc); $store = new Store("http://example.org/store", new FakeCredentials(), $fake_request_factory); $response = $store->store_data($g); $this->assertTrue(in_array('Content-Type: text/turtle', $fake_request->get_headers())); }