Skip to content

Commit

Permalink
Better testing
Browse files Browse the repository at this point in the history
  • Loading branch information
lordtatty committed Jul 22, 2015
1 parent 3a963e4 commit a8cfc26
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/unit/ExtendedGraphTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,27 @@ protected function setUp()
echo "\nTest: {$className}->{$testName}\n";
}

/**
* @dataProvider addValidValueToLiteralResultsInTriple_Provider
*/
public function testAddValidValueToLiteralResultsInTriple($value)
{
$graph = new ExtendedGraph();
$addResult = $graph->add_literal_triple('http://some/subject/1', 'http://some/predicate', $value);
$this->assertTrue($addResult, 'The triple should have been added for this value');

$hasPropertyResult = $graph->subject_has_property('http://some/subject/1', 'http://some/predicate');
$this->assertTrue($hasPropertyResult, 'The triple should have been added for this value');
}
public function addValidValueToLiteralResultsInTriple_Provider(){
return array(
array('String'),
array(1),
array(1.2),
array(true)
);
}

/**
* @dataProvider addInvalidValueToLiteralResultsInNoTriple_Provider
*/
Expand All @@ -43,6 +64,18 @@ public function addInvalidValueToLiteralResultsInNoTriple_Provider(){
);
}

public function testAddValidValueToResourceResultsInTriple()
{
$value = 'A String';
$graph = new ExtendedGraph();
$addResult = $graph->add_resource_triple('http://some/subject/1', 'http://some/predicate', $value);
$this->assertTrue($addResult, 'The triple should have been added for this value');

$hasPropertyResult = $graph->subject_has_property('http://some/subject/1', 'http://some/predicate');
$this->assertTrue($hasPropertyResult, 'The triple should have been added for this value');
}


/**
* @dataProvider addInvalidValueToResourceResultsInNoTriple_Provider
*/
Expand Down
63 changes: 63 additions & 0 deletions test/unit/mongo/MongoGraphTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,42 @@ public function testAddTripodArraySingleDoc()
$this->assertEquals($expected, $g);
}

/**
* @dataProvider addTripodArrayContainingValidLiteralValues_Provider
*/
public function testAddTripodArrayContainingValidLiteralValues($value)
{
$doc = array(
"_id"=>array("r"=>"http://talisaspire.com/works/4d101f63c10a6-2", "c"=>"http://talisaspire.com/works/4d101f63c10a6-2"),
"_version"=>0,
"rdf:type"=>array(
array("l"=>$value),
array("l"=>"a Value"),
),
"bibo:isbn13"=>array("l"=>"9211234567890"),
"bibo:isbn10"=>array("l"=>$value)
);

$expected = new \Tripod\Mongo\MongoGraph();
$expected->add_literal_triple("http://talisaspire.com/works/4d101f63c10a6-2", $expected->qname_to_uri("bibo:isbn13"),"9211234567890");
$expected->add_literal_triple("http://talisaspire.com/works/4d101f63c10a6-2", $expected->qname_to_uri("bibo:isbn10"),$value);
$expected->add_literal_triple("http://talisaspire.com/works/4d101f63c10a6-2", $expected->qname_to_uri("rdf:type"),$value);
$expected->add_literal_triple("http://talisaspire.com/works/4d101f63c10a6-2", $expected->qname_to_uri("rdf:type"),"a Value");

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

$this->assertEquals($expected, $g);
}
public function addTripodArrayContainingValidLiteralValues_Provider(){
return array(
array('A String'),
array(1),
array(1.2),
array(true)
);
}

/**
* @dataProvider addTripodArrayContainingInvalidLiteralValues_Provider
*/
Expand Down Expand Up @@ -135,6 +171,33 @@ public function addTripodArrayContainingInvalidLiteralValues_Provider(){
);
}


public function testAddTripodArrayContainingValidResourceValues()
{
$value = 'A String';
$doc = array(
"_id"=>array("r"=>"http://talisaspire.com/works/4d101f63c10a6-2", "c"=>"http://talisaspire.com/works/4d101f63c10a6-2"),
"_version"=>0,
"dct:subject"=>array("u"=>"http://talisaspire.com/disciplines/physics"),
"dct:publisher"=>array("u"=>$value),
"rdf:type"=>array(
array("u"=>$value),
array("u"=>"http://talisaspire.com/schema#Work")
),
);

$expected = new \Tripod\Mongo\MongoGraph();
$expected->add_resource_triple("http://talisaspire.com/works/4d101f63c10a6-2", $expected->qname_to_uri("dct:subject"),"http://talisaspire.com/disciplines/physics");
$expected->add_resource_triple("http://talisaspire.com/works/4d101f63c10a6-2", $expected->qname_to_uri("dct:publisher"),$value);
$expected->add_resource_triple("http://talisaspire.com/works/4d101f63c10a6-2", $expected->qname_to_uri("rdf:type"),$value);
$expected->add_resource_triple("http://talisaspire.com/works/4d101f63c10a6-2", $expected->qname_to_uri("rdf:type"),"http://talisaspire.com/schema#Work");

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

$this->assertEquals($expected, $g);
}

/**
* @dataProvider addTripodArrayContainingInvalidResourceValues_Provider
*/
Expand Down

0 comments on commit a8cfc26

Please sign in to comment.