Added:
/trunk/changesetbatch.class.php
Modified:
/trunk
/trunk/augmentservice.class.php
/trunk/build.xml
/trunk/changeset.class.php
/trunk/constants.inc.php
/trunk/contentbox.class.php
/trunk/credentials.class.php
/trunk/curlhttpclient.class.php
/trunk/datatable.class.php
/trunk/datatableresult.class.php
/trunk/etc/phingBootstrap.php
/trunk/examples/helloworld.php
/trunk/facetservice.class.php
/trunk/fieldpredicatemap.class.php
/trunk/graph.class.php
/trunk/graphpath.class.php
/trunk/httpcache.class.php
/trunk/httprequest.class.php
/trunk/httprequestfactory.class.php
/trunk/httpresponse.class.php
/trunk/jobqueue.class.php
/trunk/labeller.class.php
/trunk/metabox.class.php
/trunk/moriarty.inc.php
/trunk/multisparqlservice.class.php
/trunk/networkresource.class.php
/trunk/oaiservice.class.php
/trunk/phing.xml
/trunk/phphttpclient.class.php
/trunk/privategraph.class.php
/trunk/queryprofile.class.php
/trunk/rollback.class.php
/trunk/simplegraph.class.php
/trunk/snapshots.class.php
/trunk/sparqlservice.class.php
/trunk/sparqlservicebase.class.php
/trunk/store.class.php
/trunk/storecollection.class.php
/trunk/storegroup.class.php
/trunk/storegroupconfig.class.php
/trunk/tests/augmentservice.test.php
/trunk/tests/curlhttpclient.test.php
/trunk/tests/graph.test.php
/trunk/tests/runtests.php
/trunk/tests/simplegraph.test.php
/trunk/tests/store.test.php
/trunk/union.class.php
/trunk/valuepool.class.php
=======================================
--- /dev/null
+++ /trunk/changesetbatch.class.php Tue Aug 2 01:13:40 2011
@@ -0,0 +1,153 @@
+<?php
+require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'constants.inc.php';
+require_once MORIARTY_ARC_DIR . "ARC2.php";
+require_once MORIARTY_DIR . "changeset.class.php";
+
+/**
+ * Represents a batch of changesets. Can be used to create changesets
based on the difference between two graphs.
+ * @see http://n2.talis.com/wiki/Metabox#Batch_Updating
+ */
+
+
+class ChangeSetBatch {
+
+ var $a;
+ var $utils;
+ var $before;
+ var $after;
+ var $subjectIndex = array();
+ var $__index = array();
+
+ function __construct($a = array()) {
+ $this->a = $a;
+ /* parse the before and after graphs if necessary*/
+ foreach(array('before','after') as $rdf){
+ if(!is_array($a[$rdf]) AND !empty($a[$rdf])){
+ $parser = ARC2::getRDFParser();
+ $parser->parse(false, $a[$rdf]);
+ $a[$rdf] = $parser->getSimpleIndex(0);
+ }
+ $this->$rdf = ($a[$rdf])? $a[$rdf] : array();
+ }
+
+ }
+
+ function ChangeSetBatch ($a = array()) {
+ $this->__construct($a);
+ }
+
+ function __init() {
+ $csIndex = array();
+ $CSNS = 'http://purl.org/vocab/changeset/schema#';
+ $utils = ARC2::getComponent('ARC2_IndexUtilsPlugin');
+
+ // Get the triples to be added
+ $additions = !empty($this->before)? $utils->diff($this->after,
$this->before) : $this->after;
+ //Get the triples to be removed
+ $removals = !empty($this->after)? $utils->diff($this->before,
$this->after) : $this->before;
+ // Get an array of all the subject uris
+ $subjectIndex = array_merge(array_keys($this->before),
array_keys($this->after));
+
+ // Get the metadata for all the changesets
+ $date = (!empty($this->a['createdDate']))? $this->a['createdDate'] :
date(DATE_ATOM);
+ $creator = (!empty($this->a['creatorName']))?
$this->a['creatorName'] : 'Talis ChangeSet Builder plugin';
+ $reason = (!empty($this->a['changeReason']))?
$this->a['changeReason'] : 'Change using Talis ChangeSet Builder plugin';
+
+
+ // for every subject uri, create a new changeset
+ $n = count($subjectIndex);
+
+ for ($i=0 ; $i < $n; $i++) {
+ $csID = '_:cs'.$i;
+ $csIndex[$subjectIndex[$i]] = $csID;
+ $this->addT($csID, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
$CSNS.'ChangeSet', 'uri');
+ $this->addT($csID, $CSNS.'subjectOfChange', $subjectIndex[$i], 'uri');
+ $this->addT($csID, $CSNS.'createdDate', $date, 'literal');
+ $this->addT($csID, $CSNS.'creatorName', $creator, 'literal');
+ $this->addT($csID, $CSNS.'changeReason', $reason, 'literal');
+
+ /* add extra user-given properties to each changeset*/
+ if(!empty($this->a['properties'])){
+ foreach ($this->a['properties'] as $p => $objs) $this->addT($csID, $p,
$objs);
+ }
+ }
+ /*iterate through the triples to be added,
+ reifying them,
+ and linking to the Statements from the appropriate changeset
+ */
+ $reifiedAdditions = $utils->reify($additions, 'Add');
+ foreach($reifiedAdditions as $nodeID => $props){
+ $subject =
$props['http://www.w3.org/1999/02/22-rdf-syntax-ns#subject'][0]['value'];
+ $csID = $csIndex[$subject];
+ $this->addT($csID, $CSNS.'addition', $nodeID, 'bnode');
+
+ // if dc:source is given in the instantiating arguments, add it to the
statement as provenance
+ if(isset($this->a['http://purl.org/dc/terms/source'])){
+ $this->addT($nodeID, 'http://purl.org/dc/terms/source',
$this->a['http://purl.org/dc/terms/source'], 'uri');
+ }
+
+
+
+ }
+
+ /*iterate through the triples to be removed,
+ reifying them,
+ and linking to the Statements from the appropriate changeset
+ */
+
+
+ $reifiedRemovals = $utils->reify($removals, 'Remove');
+
+ foreach($reifiedRemovals as $nodeID => $props){
+ $subject =
$props['http://www.w3.org/1999/02/22-rdf-syntax-ns#subject'][0]['value'];
+ $csID = $csIndex[$subject];
+ $this->addT($csID, $CSNS.'removal', $nodeID, 'bnode');
+ }
+
+ foreach($this->__index as $uri => $props){
+ if(
+ !isset($props[$CSNS.'removal'])
+ AND
+ !isset($props[$CSNS.'addition'])
+ ){
+ unset($this->__index[$uri]);
+ }
+
+ }
+ $this->__index = $utils->merge($this->__index, $reifiedAdditions,
$reifiedRemovals);
+
+ parent::__init();
+
+ }
+
+/**
+ * addT
+ * adds a triple to the internal simpleIndex holding all the changesets
and statements
+ * @return void
+ * @author Keith
+ **/
+ function addT($s, $p, $o, $o_type='bnode'){
+ if(is_array($o) AND isset($o[0]['type'])){
+ foreach($o as $obj){
+ $this->addT($s, $p, $obj );
+ }
+ }else {
+ $obj = !is_array($o)? array('value' => $o, 'type'=> $o_type) : $o ;
+ $this->__index[$s][$p][]=$obj;
+ }
+ }
+
+ function toRDFXML(){
+ $ser = ARC2::getRDFXMLSerializer();
+ return $ser->getSerializedIndex($this->__index);
+ }
+
+ function to_rdfxml(){
+ return $this->toRDFXML();
+ }
+
+ function hasChanges(){
+ return !empty($this->__index);
+ }
+}
+?>
=======================================
--- /trunk/augmentservice.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/augmentservice.class.php Tue Aug 2 01:13:40 2011
@@ -59,14 +59,7 @@
$request = $this->request_factory->make( 'POST', $this->uri ,
$this->credentials );
$request->set_accept(MIME_RSS);
$request->set_content_type(MIME_RSS);
-
- $data = new SimpleGraph();
- $data->add_turtle( $graph->to_turtle());
-
-
$data->add_resource_triple( 'tag:talis.com,2008:moriarty-tmp-augment-channel',
RDF_TYPE, 'http://purl.org/rss/1.0/channel');
-
$data->add_resource_triple( 'tag:talis.com,2008:moriarty-tmp-augment-channel',
RSS_ITEMS, 'tag:talis.com,2008:moriarty-tmp-augment-channel-items');
-
$data->add_resource_triple( 'tag:talis.com,2008:moriarty-tmp-augment-channel-items',
RDF_TYPE, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq');
- $request->set_body( $data->to_rdfxml() );
+ $request->set_body( $graph->to_rdfxml() );
return $request->execute();
}
=======================================
--- /trunk/build.xml Fri Jul 29 08:34:10 2011
+++ /trunk/build.xml Tue Aug 2 01:13:40 2011
@@ -1,17 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<project name="Moriarty" default="build">
-<property name="base-dir" value
= "/opt/hudson/jobs/moriarty/workspace/trunk" />
-<property name="test-dir" value = "${base-dir}/tests" />
-<property name="test-results-dir" value="${test-dir}/test_results"/>
-<property name="deploy-dir" value="/var/www/html"/>
-
-<target name="unit-tests">
- <echo message="Running moriarty unit tests"/>
- <exec dir="${test-dir}" executable="php" failonerror="true" >
- <arg line="${base-dir}/../tests.php" />
- </exec>
-</target>
-<target name="build" depends="unit-tests" />
+ <property name="base-dir" value="." />
+ <property name="test-dir" value="${base-dir}/tests" />
+ <property name="test-results-dir" value="${test-dir}/test_results" />
+ <property name="deploy-dir" value="/var/www/html" />
+
+ <target name="build" depends="unit-tests" />
+
+ <target name="init">
+ <mkdir dir="${test-results-dir}" />
+ </target>
+
+ <target name="unit-tests">
+ <echo message="Running moriarty unit tests" />
+ <exec dir="${test-dir}" executable="phpunit" failonerror="true">
+ <arg line=" runtests" />
+ </exec>
+ </target>
+
</project>
=======================================
--- /trunk/changeset.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/changeset.class.php Tue Aug 2 01:13:40 2011
@@ -50,7 +50,6 @@
var $_index = array();
function __construct($a = '') {
- parent::__construct();
$this->a = $a;
/* parse the before and after graphs if necessary*/
foreach(array('before','after', 'before_rdfxml', 'after_rdfxml') as
$rdf){
@@ -235,6 +234,4 @@
}
}
-
-
?>
=======================================
--- /trunk/contentbox.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/contentbox.class.php Tue Aug 2 01:13:40 2011
@@ -222,5 +222,4 @@
*/
var $items;
}
-
?>
=======================================
--- /trunk/curlhttpclient.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/curlhttpclient.class.php Tue Aug 2 01:13:40 2011
@@ -56,6 +56,7 @@
switch($request->method) {
case 'GET' : break;
case 'POST' : curl_setopt($curl_handle, CURLOPT_POST, 1); break;
+ case 'HEAD' : curl_setopt($curl_handle, CURLOPT_NOBODY, 1); break;
default : curl_setopt($curl_handle,
CURLOPT_CUSTOMREQUEST,strtoupper($request->method));
}
@@ -197,6 +198,4 @@
return array($response_code,$response_header_array,$response_body);
}
}
-
-
?>
=======================================
--- /trunk/datatable.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/datatable.class.php Tue Aug 2 01:13:40 2011
@@ -931,4 +931,4 @@
}
}
-
+?>
=======================================
--- /trunk/datatableresult.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/datatableresult.class.php Tue Aug 2 01:13:40 2011
@@ -194,6 +194,5 @@
return $ret;
}
-
-
-}
+}
+?>
=======================================
--- /trunk/etc/phingBootstrap.php Fri Jul 29 08:34:10 2011
+++ /trunk/etc/phingBootstrap.php Tue Aug 2 01:13:40 2011
@@ -13,6 +13,8 @@
require_once MORIARTY_DIR . '/tests/fakehttprequest.class.php';
require_once MORIARTY_DIR . '/tests/fakerequestfactory.class.php';
+error_reporting(E_ALL && ~E_STRICT);
+
ini_set('include_path',
ini_get('include_path')
.PATH_SEPARATOR.MORIARTY_DIR
=======================================
--- /trunk/graph.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/graph.class.php Tue Aug 2 01:13:40 2011
@@ -125,31 +125,6 @@
$request->set_body( $turtle );
return $request->execute();
}
-
- function
submit_ntriples_in_batches_from_file($filename,$no_of_lines=500,
$stop_on_failure=true) {
- $responses = array();
- $pointer = fopen($filename, 'r');
- $batch = '';
- $lineCount=0;
- while($line = fgets($pointer)){
- $batch.=$line;
- $lineCount++;
- if($lineCount==$no_of_lines){
- $response = $this->submit_turtle($batch);
- $responses[] = $response;
- if($response->is_success()===false AND $stop_on_failure){
- return $responses;
- } else {
- $lineCount=0;
- $batch='';
- }
- }
- }
- if(!empty($batch)){
- $responses[]=$this->submit_turtle($batch);
- }
- return $responses;
- }
/**
* Obtain the graph's bounded description of a given resource
@@ -255,9 +230,6 @@
else if ($response->status_code == 412) {
return false;
}
-
-
-
}
}
?>
=======================================
--- /trunk/graphpath.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/graphpath.class.php Tue Aug 2 01:13:40 2011
@@ -1357,4 +1357,4 @@
}
}
}
-
+?>
=======================================
--- /trunk/httpcache.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/httpcache.class.php Tue Aug 2 01:13:40 2011
@@ -70,13 +70,6 @@
$filename = $this->_directory . $id;
return file_exists($filename);
}
-
-
}
-
-
-
-
-
?>
=======================================
--- /trunk/httprequest.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/httprequest.class.php Tue Aug 2 01:13:40 2011
@@ -276,5 +276,4 @@
}
-
?>
=======================================
--- /trunk/httpresponse.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/httpresponse.class.php Tue Aug 2 01:13:40 2011
@@ -60,20 +60,6 @@
return $this->status_code >= 200 && $this->status_code < 300;
}
-
- /**
- * Gets the content-type sent with the response, if any
- * @return string if content-type is set, boolean false otherwise
- */
-
- function get_content_type() {
- foreach($this->headers as $k => $v){
- if(stristr($k, 'Content-Type')){
- return $v;
- }
- }
- return false;
- }
/**
* Obtain a string representation of this response
@@ -186,5 +172,4 @@
}
-
?>
=======================================
--- /trunk/jobqueue.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/jobqueue.class.php Tue Aug 2 01:13:40 2011
@@ -162,3 +162,4 @@
return $response;
}
}
+?>
=======================================
--- /trunk/labeller.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/labeller.class.php Tue Aug 2 01:13:40 2011
@@ -550,3 +550,4 @@
}
}
+?>
=======================================
--- /trunk/moriarty.inc.php Fri Jul 29 08:34:10 2011
+++ /trunk/moriarty.inc.php Tue Aug 2 01:13:40 2011
@@ -142,7 +142,6 @@
define('OWL_SYMMETRICPROPERTY', 'http://www.w3.org/2002/07/owl#SymmetricProperty');
define('OWL_ANNOTATIONPROPERTY', 'http://www.w3.org/2002/07/owl#AnnotationProperty');
define('OWL_DISJOINTWITH', 'http://www.w3.org/2002/07/owl#disjointWith');
-define('OPEN_LASTCACHEDPAGE', 'http://open.vocab.org/terms/lastCachedPage');
define('OUTPUT_TYPE_RDF', 'rdf');
define('OUTPUT_TYPE_XML', 'xml');
@@ -151,5 +150,4 @@
define('OUTPUT_TYPE_HTML', 'html');
define('OUTPUT_TYPE_JSON', 'json');
-
?>
=======================================
--- /trunk/phing.xml Fri Jul 29 08:34:10 2011
+++ /trunk/phing.xml Tue Aug 2 01:13:40 2011
@@ -37,6 +37,7 @@
<!-- no tests yet -->
<exclude name="httpcache.test.php" />
+ <exclude name="storegroup.test.php" />
</fileset>
</batchtest>
</phpunit>
@@ -59,6 +60,7 @@
<!-- no tests yet -->
<exclude name="httpcache.test.php" />
+ <exclude name="storegroup.test.php" />
</fileset>
</batchtest>
</phpunit>
=======================================
--- /trunk/phphttpclient.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/phphttpclient.class.php Tue Aug 2 01:13:40 2011
@@ -73,10 +73,10 @@
$response->body = $response_body;
$response->info = $response_info;
//ID20100317 $response->request = $request;
- $response->request_method = $this->method;
- $response->request_uri = $this->uri;
- $response->request_headers = $this->headers;
- $response->request_body = $this->body;
+ $response->request_method = $request->method;
+ $response->request_uri = $request->uri;
+ $response->request_headers = $request->headers;
+ $response->request_body = $request->body;
$key = spl_object_hash($request);
$this->responses[$key] = $response;
@@ -90,6 +90,4 @@
return @$this->responses[$key];
}
}
-
-
?>
=======================================
--- /trunk/rollback.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/rollback.class.php Tue Aug 2 01:13:40 2011
@@ -79,5 +79,4 @@
}
}
-
?>
=======================================
--- /trunk/simplegraph.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/simplegraph.class.php Tue Aug 2 01:13:40 2011
@@ -1075,7 +1075,16 @@
}
else {
foreach($base_obs as $base_o){
- if(!in_array($base_o, $index[$base_uri][$base_p])) {
+ // because we want to enforce strict type check
+ // on in_array, we need to ensure that array keys
+ // are ordered the same
+ ksort($base_o);
+ $base_p_values = $index[$base_uri][$base_p];
+ foreach($base_p_values as &$v)
+ {
+ ksort($v);
+ }
+ if(!in_array($base_o, $base_p_values, true)) {
$diff[$base_uri][$base_p][]=$base_o;
}
}
@@ -1363,38 +1372,5 @@
return $values;
}
- /** Skolemise Bnodes
- * replace bnodes in the graph with URIs
- * @param urispace
- **/
-
- public function skolemise_bnodes($urispace)
- {
- $bnodes = $this->get_bnodes();
- $skolemised_bnodes = array();
- foreach($bnodes as $no => $bnode){
- $uri = $urispace.'id-'.++$no;
- $this->replace_resource($bnode, $uri);
- $skolemised_bnodes[$bnode] = $uri;
- }
- return $skolemised_bnodes;
- }
-
- public function get_bnodes()
- {
- $bnodes = array();
- $index = $this->get_index();
- foreach($index as $s => $ps){
- if(strpos($s,'_:')===0) $bnodes[]=$s;
- foreach($ps as $p => $os){
- foreach($os as $o){
- if($o['type']=='bnode'){
- $bnodes[]=$o['value'];
- }
- }
- }
- }
- return array_unique($bnodes);
- }
-}
-
+}
+?>
=======================================
--- /trunk/snapshots.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/snapshots.class.php Tue Aug 2 01:13:40 2011
@@ -45,5 +45,4 @@
}
}
-
?>
=======================================
--- /trunk/store.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/store.class.php Tue Aug 2 01:13:40 2011
@@ -12,7 +12,7 @@
require_once MORIARTY_DIR. 'augmentservice.class.php';
require_once MORIARTY_DIR. 'oaiservice.class.php';
require_once MORIARTY_DIR. 'httprequest.class.php';
-require_once MORIARTY_DIR. 'changeset.class.php';
+
/**
* Represents a platform store.
*/
@@ -203,90 +203,6 @@
{
return $this->get_contentbox()->save_item($content, $content_type);
}
-
-
- /**
- * mirror_from_url
- *
- * @return array of responses from http requests, and overall success
status
- * @author Keith Alexander
- **/
- function mirror_from_url($url, $rdf_content=false)
- {
-
- $return = array(
- 'get_page' => false,
- 'get_copy' => false,
- 'put_page' => false,
- 'update_data' => false,
- 'success' => false,
- );
-
- if (empty( $this->request_factory) ) {
- $this->request_factory = new HttpRequestFactory();
- }
-
- $last_cached_page_uri = $this->get_contentbox()->uri.'/mirrors/'.$url;
-
- if(!$rdf_content){
-
- $web_page_request = $this->request_factory->make('GET', $url);
-
$web_page_request->set_accept('application/rdf+xml;q=0.8,text/turtle;q=0.9,*/*;q=0.1');
- $web_page_response = $web_page_request->execute();
- $return['get_page'] = $web_page_response;
- $web_page_content = $web_page_response->body;
- } else {
- $web_page_content = $rdf_content;
- $return['rdf_content'] = $rdf_content;
- }
- if($rdf_content OR $web_page_response->is_success() ){
-
- $newGraph = new SimpleGraph();
- $newGraph->add_rdf($web_page_content);
- $newGraph->add_resource_triple($url, OPEN_LASTCACHEDPAGE,
$last_cached_page_uri);
- $newGraph->skolemise_bnodes($last_cached_page_uri.'/');
- $after = $newGraph->get_index();
- # get previous copy if it exists
- $cached_page_request = $this->request_factory->make('GET',
$last_cached_page_uri, $this->credentials);
- $cached_page_response = $cached_page_request->execute();
- $return['get_copy'] = $cached_page_response;
- if($cached_page_response->status_code == '200'){
- $before = json_decode($cached_page_response->body, true);
- } else if( $cached_page_response->status_code == '404' ) {
- $before = false;
- } else {
- return $return;
- }
- $put_page_request = $this->request_factory->make('PUT',
$last_cached_page_uri, $this->credentials);
- $put_page_request->set_body($newGraph->to_json());
- $put_page_request->set_content_type('application/json');
- $put_page_response = $put_page_request->execute();
- $return['put_page'] = $put_page_response;
-
- if(!$put_page_response->is_success()){
- return $return;
- }
- # build new changeset
-
- $Changeset = new ChangeSet(array('before' => $before, 'after' =>
$after));
-
- if($Changeset->has_changes()){
- $return['update_data'] =
$this->get_metabox()->apply_changeset($Changeset);
- if($return['update_data']->is_success()){
- $return['success'] = true;
- }
- return $return;
- } else {
- $return['success'] = true;
- return $return;
- }
-
-
- } else {
-
- return $return;
- }
- }
}
?>
=======================================
--- /trunk/tests/augmentservice.test.php Fri Jul 29 08:34:10 2011
+++ /trunk/tests/augmentservice.test.php Tue Aug 2 01:13:40 2011
@@ -60,57 +60,5 @@
$this->assertTrue( in_array('Content-Type: application/rss+xml',
$fake_request->get_headers() ) );
}
- function test_augment_graph_creates_rss_channel() {
- $fake_request_factory = new FakeRequestFactory();
- $fake_request = new FakeHttpRequest( new HttpResponse() );
-
$fake_request_factory->register('POST', "http://example.org/store/services/augment",
$fake_request );
- $ss = new AugmentService("http://example.org/store/services/augment");
- $ss->request_factory = $fake_request_factory;
-
- $response = $ss->augment_graph( new SimpleGraph() );
-
- $data = new SimpleGraph();
- $data->from_rdfxml($fake_request->get_body());
-
- $this->assertTrue(
$data->has_resource_triple('tag:talis.com,2008:moriarty-tmp-augment-channel',
RDF_TYPE, 'http://purl.org/rss/1.0/channel'));
-
-
- }
-
- function test_augment_graph_creates_items_list() {
- $fake_request_factory = new FakeRequestFactory();
- $fake_request = new FakeHttpRequest( new HttpResponse() );
-
$fake_request_factory->register('POST', "http://example.org/store/services/augment",
$fake_request );
- $ss = new AugmentService("http://example.org/store/services/augment");
- $ss->request_factory = $fake_request_factory;
-
- $response = $ss->augment_graph( new SimpleGraph() );
-
- $data = new SimpleGraph();
- $data->from_rdfxml($fake_request->get_body());
-
- $this->assertTrue(
$data->has_resource_triple('tag:talis.com,2008:moriarty-tmp-augment-channel',
RSS_ITEMS, 'tag:talis.com,2008:moriarty-tmp-augment-channel-items'));
- $this->assertTrue(
$data->has_resource_triple('tag:talis.com,2008:moriarty-tmp-augment-channel-items',
RDF_TYPE, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq'));
- }
-
-/*
- function test_augment_graph_creates_item_for_each_subject_in_graph() {
- $fake_request_factory = new FakeRequestFactory();
- $fake_request = new FakeHttpRequest( new HttpResponse() );
-
$fake_request_factory->register('POST', "http://example.org/store/services/augment",
$fake_request );
- $ss = new AugmentService("http://example.org/store/services/augment");
- $ss->request_factory = $fake_request_factory;
-
- $g = new SimpleGraph();
-
$g->add_resource_triple('http://example.org/subj', 'http://example.org/pred', 'http://example.org/obj');
- $response = $ss->augment_graph( $g );
-
- $data = new SimpleGraph();
- $data->from_rdfxml($fake_request->get_body());
-
- $this->assertTrue(
$data->has_resource_triple('tag:talis.com,2008:moriarty-tmp-augment-channel-items', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#_1', 'http://example.org/subj'));
- $this->assertTrue(
$data->has_resource_triple('http://example.org/subj', 'http://example.org/pred', 'http://example.org/obj'));
- }
-*/
}
?>
=======================================
--- /trunk/tests/curlhttpclient.test.php Fri Jul 29 08:34:10 2011
+++ /trunk/tests/curlhttpclient.test.php Tue Aug 2 01:13:40 2011
@@ -40,7 +40,16 @@
$google_response = $client->get_response_for($google_key);
$this->assertEquals('gws', $google_response->headers['server']);
-
$this->assertEquals('http://open.login.yahooapis.com/openid20/www.yahoo.com/xrds',
$yahoo_response->headers['x-xrds-location']);
+ $this->assertEquals('YTS/1.20.0', $yahoo_response->headers['server']);
+ }
+
+ function test_send_request_with_head_method()
+ {
+ $client = new CurlHttpClient();
+ $google_request = new HttpRequest('HEAD', 'http://www.google.com/');
+ $google_key = $client->send_request($google_request);
+ $google_response = $client->get_response_for($google_key);
+ $this->assertEquals('gws', $google_response->headers['server']);
}
function test_parse_response_parses_all_responses() {
=======================================
--- /trunk/tests/graph.test.php Fri Jul 29 08:34:10 2011
+++ /trunk/tests/graph.test.php Tue Aug 2 01:13:40 2011
@@ -352,27 +352,6 @@
$response = $g->submit_turtle( $this->_turtle_doc );
$this->assertTrue( in_array('Accept: */*',
$fake_request->get_headers() ) );
}
-
- function test_submit_ntriples_from_file_in_batches(){
- $response = new HttpResponse('202');
- $graph = $this->getMock('Graph', array('submit_turtle'),
array(),'',false );
- $graph->expects($this->exactly(10))
- ->method('submit_turtle')
- ->will($this->returnValue($response));
- $filename = dirname(__FILE__).'/documents/10-ntriples.nt';
- $result = $graph->submit_ntriples_in_batches_from_file($filename,1);
- $this->assertEquals(count($result), 10);
- }
- function test_submit_ntriples_from_file_in_batches_stop_on_failure(){
- $response = new HttpResponse('500');
- $graph = $this->getMock('Graph', array('submit_turtle'),
array(),'',false );
- $graph->expects($this->exactly(1))
- ->method('submit_turtle')
- ->will($this->returnValue($response));
- $filename = dirname(__FILE__).'/documents/10-ntriples.nt';
- $result =
$graph->submit_ntriples_in_batches_from_file($filename,1,true);
- $this->assertEquals(count($result), 1);
- }
}
=======================================
--- /trunk/tests/runtests.php Fri Jul 29 08:34:10 2011
+++ /trunk/tests/runtests.php Tue Aug 2 01:13:40 2011
@@ -17,7 +17,6 @@
require_once MORIARTY_TEST_DIR . 'fieldpredicatemap.test.php';
require_once MORIARTY_TEST_DIR . 'valuepool.test.php';
require_once MORIARTY_TEST_DIR . 'httprequest.test.php';
-require_once MORIARTY_TEST_DIR . 'httpresponse.test.php';
require_once MORIARTY_TEST_DIR . 'credentials.test.php';
require_once MORIARTY_TEST_DIR . 'privategraph.test.php';
require_once MORIARTY_TEST_DIR . 'contentbox.test.php';
@@ -42,8 +41,7 @@
require_once MORIARTY_TEST_DIR . 'datatable.test.php';
require_once MORIARTY_TEST_DIR . 'datatableresult.test.php';
-
-error_reporting(E_ALL );
+error_reporting(E_ALL && ~E_STRICT);
function exceptions_error_handler($severity, $message, $filename, $lineno)
{
if (error_reporting() == 0) {
return;
@@ -83,7 +81,6 @@
$suite->addTestSuite('CredentialsTest');
$suite->addTestSuite('ValuePoolTest');
$suite->addTestSuite('HttpRequestTest');
- $suite->addTestSuite('HttpResponseTest');
$suite->addTestSuite('PrivateGraphTest');
$suite->addTestSuite('MetaboxTest');
$suite->addTestSuite('ContentboxTest');
=======================================
--- /trunk/tests/simplegraph.test.php Fri Jul 29 08:34:10 2011
+++ /trunk/tests/simplegraph.test.php Tue Aug 2 01:13:40 2011
@@ -13,6 +13,11 @@
</rdf:Description>
</rdf:RDF>';
+ var $_single_triple_invalid_rdf = '<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:ex="http://example.org/">
+ <rdf:Description rdf:about="http://example.org/subj">
+ <ex:pred>foo</ex:pred>
+</rdf:RDF>';
+
var $_single_triple_turtle = '@prefix ex: <http://example.org/> .
<http://example.org/subj> ex:pred "foo" .';
@@ -577,7 +582,7 @@
$this->assertEquals( $_1, $actual);
}
- function test_diff_where_orifinal_array_is_empty(){
+ function test_diff_where_original_array_is_empty(){
$_1 = array();
@@ -586,9 +591,38 @@
);
$actual = SimpleGraph::diff($_1,$_2);
-
+
$this->assertEquals( $_1, $actual);
}
+
+ function test_diff_where_array_key_order_is_different()
+ {
+ $_1 = array(
+ '#x' => array('#name' => array(array('value'=> 'Keith', 'type'
=> 'literal')))
+ );
+
+ $_2 = array(
+ '#x' => array('#name' => array(array('type'
=> 'literal', 'value'=> 'Keith')))
+ );
+
+ $actual = SimpleGraph::diff($_1,$_2);
+
+ $this->assertEquals(array(), $actual);
+
+ }
+
+ function test_diff_to_ensure_type_insensitive_comparison()
+ {
+ $_1 = array(
+ '#x' => array('#lcn' => array(array('value'=> '1521278'),) )
+ );
+ $_2 = array(
+ '#x' => array('#lcn' => array(array('value'=> '00001521278'),) )
+ );
+
+ $actual = SimpleGraph::diff($_1,$_2);
+ $this->assertEquals( $_1, $actual);
+ }
function test_merge_static(){
@@ -1091,111 +1125,19 @@
$expectedArray =
array('http://value/1', 'http://value/2', 'http://value/3', 'http://value/4', 'http://value/5');
$this->assertEquals($expectedArray,
$graph->get_sequence_values('http://some/subject/1'));
}
- public function testGetParserErrors(){
+
+
+ public function testGetParserErrors(){
$graph = new SimpleGraph();
$graph->add_rdf($this->_single_triple_turtle);
$errors = $graph->get_parser_errors();
$this->assertTrue(empty($errors), "Errors should be empty");
- $graph->add_rdf($this->_single_triple_invalid_turtle );
- $errors = $graph->get_parser_errors();
+ $graph->add_rdf($this->_single_triple_invalid_rdf );
+ $errors = $graph->get_parser_errors();
$this->assertFalse(empty($errors), "Errors should not be empty");
$this->assertTrue(!empty($errors[0]), "Errors first item should not be
empty");
}
-
- public function test_skolemise_bnodes(){
-
- $input = array(
- '_:a' => array(
- RDFS_LABEL => array(
- array(
- 'value' => 'A Bnode',
- 'type' => 'literal',
- ),
- array(
- 'value' => '_:b',
- 'type' => 'bnode',
- ),
- ),
- ),
-
- '_:b' => array(
- RDFS_LABEL => array(
- array(
- 'type' => 'literal',
- 'value' => 'bnode B',
- )
- )
- )
-
- );
-
- $expected_output = array(
- 'http://example.org/document/id-1' => array(
- RDFS_LABEL => array(
- array(
- 'value' => 'A Bnode',
- 'type' => 'literal',
- ),
- array(
- 'value' => 'http://example.org/document/id-2',
- 'type' => 'uri',
- ),
-
- ),
- ),
- 'http://example.org/document/id-2' => array(
- RDFS_LABEL => array(
- array(
- 'type' => 'literal',
- 'value' => 'bnode B',
- )
- )
- )
- );
-
- $graph = new SimpleGraph($input);
- $graph->skolemise_bnodes('http://example.org/document/');
- $output = $graph->get_index();
- $this->assertEquals($expected_output, $output, "bnodes in the graph
should be replaced with URIs");
-
-
- }
-
-
- function test_graph_pattern_is_unchanged_by_replace_resource(){
-
- }
-
- function
test_number_of_resources_remains_constant_after_skolemise_bnodes(){
- $graph = new
SimpleGraph(file_get_contents(dirname(__FILE__).'/documents/ckan-ds.ttl'));
- $index = $graph->get_index();
- $before = count($graph->get_subjects());
- $graph->skolemise_bnodes('http://example.com/test/');
- $after = count($graph->get_subjects());
- $this->assertEquals($before, $after, "skolemise_bnodes shouldn't
reduce the number of resources");
- }
-
- function test_get_bnodes(){
-
- $input = array(
- '_:a' => array(
- RDFS_SEEALSO => array(
- array(
- 'value' => '_:b',
- 'type' => 'bnode',
- ),
- ),
- ),
-
- );
-
-
- $graph = new SimpleGraph($input);
- $actual = $graph->get_bnodes();
- $expected = array('_:a', '_:b');
- $this->assertEquals($expected, $actual, "get_bnodes() should return
bnodes in subject and object positions");
- }
}
?>
=======================================
--- /trunk/tests/store.test.php Fri Jul 29 08:34:10 2011
+++ /trunk/tests/store.test.php Tue Aug 2 01:13:40 2011
@@ -348,55 +348,7 @@
$this->assertTrue( $fake_request->was_executed() );
}
- function test_store_content_sets_content_type() {
- $fake_request_factory = new FakeRequestFactory();
- $fake_request = new FakeHttpRequest( new HttpResponse() );
-
$fake_request_factory->register('POST', "http://example.org/store/items",
$fake_request );
-
- $store = new Store("http://example.org/store", new FakeCredentials(),
$fake_request_factory);
- $response = $store->store_content('some content', 'text/html');
- $this->assertTrue( in_array('Content-Type: text/html',
$fake_request->get_headers() ) );
- }
-
- function test_mirror_from_url(){
- $url = "http://example.org/web-page";
- $fake_request_factory = new FakeRequestFactory();
- $webpage_response = new HttpResponse('200') ;
- $webpage_response->body =
file_get_contents(dirname(__FILE__).DIRECTORY_SEPARATOR.'documents/after.ttl');
- $fake_webpage_request = new FakeHttpRequest($webpage_response);
- $fake_request_factory->register('GET',$url, $fake_webpage_request );
-
-
- $contentbox_copy = new HttpResponse('200');
- $contentbox_copy->body =
file_get_contents(dirname(__FILE__).DIRECTORY_SEPARATOR.'documents/before.ttl');
- $fake_contentbox_request = new FakeHttpRequest($contentbox_copy);
-
$fake_request_factory->register('GET','http://api.talis.com/stores/example/items/mirrors/'.$url ,
$fake_contentbox_request);
-
- $putResponse =new HttpResponse('201');
- $fake_postContent_request = new FakeHttpRequest($putResponse);
-
$fake_request_factory->register('PUT', 'http://api.talis.com/stores/example/items/mirrors/'.$url ,
$fake_postContent_request );
-
- $postDataResponse = new HttpResponse('201');
- $fake_postData_request = new FakeHttpRequest($postDataResponse);
-
$fake_request_factory->register('POST', 'http://api.talis.com/stores/example/meta' ,
$fake_postData_request );
-
- $store = new Store("http://api.talis.com/stores/example", new
FakeCredentials(), $fake_request_factory);
- $response = $store->mirror_from_url($url);
-
- $this->assertTrue($fake_webpage_request->was_executed(), "The webpage
$url should be retrieved over HTTP");
-
$this->assertTrue($fake_contentbox_request->was_executed(), "Store:mirror_from_url
should attempt to retrieve a copy of $url from the content box at
{storeuri}/items/mirrors/{$url} if it exists yet.");
- $this->assertTrue($fake_postContent_request->was_executed(), "The
contents of $url should be POSTed to the contentbox");
- $this->assertTrue($fake_postData_request->was_executed(), "The data
from $url (and its metadata) should be added to the store by POSTing a
document containing changesets to /meta");
-
- $expected_response = array(
- 'get_page' => $webpage_response,
- 'get_copy' => $contentbox_copy,
- 'put_page' => $putResponse,
- 'update_data' => $postDataResponse,
- 'success' => true,
- );
- $this->assertEquals($expected_response, $response,"");
- }
+
}
?>
=======================================
--- /trunk/union.class.php Fri Jul 29 08:34:10 2011
+++ /trunk/union.class.php Tue Aug 2 01:13:40 2011
@@ -37,3 +37,4 @@
}
}
}
+?>