Skip to content

Commit

Permalink
Ensure exception is thrown if a blank subject is added to ExtendedGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
lordtatty committed Jul 22, 2015
1 parent 460f258 commit 5396f60
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/classes/ExtendedGraph.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ public function add_literal_triple($s, $p, $o, $lang = null, $dt = null) {
* @return bool
*/
private function _add_triple($s, $p, Array $o_info) {
// Make sure the subject is not an empty string
if($s === ""){
throw new \Tripod\Exceptions\Exception("The subject cannot be an empty string");
}
// The value $o should already have been validated by this point
// It's validation differs depending on whether it is a literal or resource
// So just check the subject and predicate here...
Expand Down
3 changes: 3 additions & 0 deletions src/mongo/MongoGraph.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ private function add_tarray_to_index($tarray)
if(!isset($value['r']) || !$this->isValidTripleValue($value['r'])){
return;
}
if($value['r'] === ""){
throw new \Tripod\Exceptions\Exception("The subject cannot be an empty string");
}
}
}
$_i[$this->_labeller->qname_to_alias($tarray["_id"][_ID_RESOURCE])] = $predObjects;
Expand Down
14 changes: 14 additions & 0 deletions test/unit/ExtendedGraphTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ public function addInvalidSubjectToLiteralResultsInNoTriple_Provider(){
);
}

public function testAddEmptySubjectToLiteralThrowsException()
{
$this->setExpectedException('\Tripod\Exceptions\Exception');
$graph = new ExtendedGraph();
$graph->add_literal_triple("", 'http://some/predicate', 'http://someplace.com');
}

/**
* @dataProvider addInvalidSubjectToLiteralResultsInNoTriple_Provider
*/
Expand Down Expand Up @@ -176,6 +183,13 @@ public function addInvalidSubjectToResourceResultsInNoTriple_Provider(){
);
}

public function testAddEmptySubjectToResourceThrowsException()
{
$this->setExpectedException('\Tripod\Exceptions\Exception');
$graph = new ExtendedGraph();
$graph->add_resource_triple("", 'http://some/predicate', 'http://someplace.com');
}

/**
* @dataProvider addInvalidSubjectToLiteralResultsInNoTriple_Provider
*/
Expand Down
16 changes: 16 additions & 0 deletions test/unit/mongo/MongoGraphTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,22 @@ public function addTripodArrayContainingInvalidSubject_Provider(){
);
}

public function testAddTripodArrayContainingEmptySubject()
{
$this->setExpectedException('\Tripod\Exceptions\Exception');
$doc = array(
"_id"=>array("r"=>"", "c"=>"http://talisaspire.com/works/4d101f63c10a6-2"),
"_version"=>0,
"rdf:type"=>array(
array("l"=>"a Value"),
),
"bibo:isbn13"=>array("l"=>"9211234567890"),
);

$g = new \Tripod\Mongo\MongoGraph();
$g->add_tripod_array($doc);
}


public function testAddTripodArrayContainingValidResourceValues()
{
Expand Down

0 comments on commit 5396f60

Please sign in to comment.