function test_get_resource_property_values() { $ex = "http://example.com/"; $turtle = <<<_TTL_ @base <{$ex}> . <s> <has> <a> , <b> , <c> , <d> , <e> . <a> <p> 2 . <b> <p> 3 . <c> <p> 1 . <e> <p> "!" , "_" . _TTL_; $graph = new SimpleGraph(); $graph->from_turtle($turtle); $expected = array($ex . 'd', $ex . 'e', $ex . 'c', $ex . 'a', $ex . 'b'); $actual = $graph->get_resource_triple_values($ex . 's', $ex . 'has', $ex . 'p'); $actual_r = $graph->get_resource_triple_values($ex . 's', $ex . 'has', $ex . 'p', true); $actual_unsorted = $graph->get_resource_triple_values($ex . 's', $ex . 'has'); $this->assertEquals($expected, $actual, "should return the resource values of one property, ordered by a property of those resources"); $this->assertEquals(array_reverse($expected), $actual_r, "should return the resource values of one property, ordered by a property of those resources, sorted in descending order"); $this->assertEquals(count($actual), count($actual_unsorted), "number of results should be the same whether sorted or not"); }
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")); }