function test_get_subjects_of_type() { $g = new SimpleGraph(); $g->add_resource_triple('http://example.org/subj1', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://example.org/type_1'); $g->add_resource_triple('http://example.org/subj2', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://example.org/type_2'); $g->add_resource_triple('http://example.org/subj3', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://example.org/type_1'); $g->add_literal_triple('http://example.org/subj4', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'http://example.org/type_1'); $subjects = $g->get_subjects_of_type('http://example.org/type_1'); $this->assertEquals(2, count($subjects), 'The returned subjects should be exactly 2'); $this->assertContains('http://example.org/subj1', $subjects, 'subj1 matches and should be returned'); $this->assertContains('http://example.org/subj3', $subjects, 'subj3 matches and should be returned'); $this->assertNotContains('http://example.org/subj2', $subjects, 'subj2 does not match and should not be returned'); $this->assertNotContains('http://example.org/subj4', $subjects, 'subj4 does not match and should not be returned'); }
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")); }