Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jsmit
committed
Aug 27, 2015
1 parent
d269056
commit e71f684
Showing
14 changed files
with
493 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: jsmit | ||
* Date: 26/08/2015 | ||
* Time: 14:55 | ||
*/ | ||
|
||
namespace OpenSkos2\Rdf; | ||
|
||
|
||
class Object | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $type; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $value; | ||
|
||
/** | ||
* Object constructor. | ||
* @param $type | ||
* @param $value | ||
*/ | ||
public function __construct($type, $value) | ||
{ | ||
$this->type = $type; | ||
$this->value = $value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: jsmit | ||
* Date: 27/08/2015 | ||
* Time: 10:02 | ||
*/ | ||
|
||
namespace OpenSkos2\Validator\Concept; | ||
|
||
|
||
use OpenSkos2\Concept; | ||
use OpenSkos2\Validator\ConceptValidator; | ||
|
||
class DuplicateBroader extends ConceptValidator | ||
{ | ||
/** | ||
* @param Concept $concept | ||
* @return bool | ||
*/ | ||
protected function validateConcept(Concept $concept) | ||
{ | ||
$broaderTerms = $concept->getProperty(Concept::PROPERTY_BROADER); | ||
|
||
$loopedConcepts = []; | ||
foreach ($broaderTerms as $broaderTerm) { | ||
if (isset($loopedConcepts[$broaderTerm->getValue()])) { | ||
$this->errorMessage = "Broader term {$broaderTerm->getValue()} is defined more than once"; | ||
return false; | ||
} | ||
$loopedConcepts[$broaderTerm->getValue()] = true; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: jsmit | ||
* Date: 27/08/2015 | ||
* Time: 10:02 | ||
*/ | ||
|
||
namespace OpenSkos2\Validator\Concept; | ||
|
||
|
||
use OpenSkos2\Concept; | ||
use OpenSkos2\Validator\ConceptValidator; | ||
|
||
class DuplicateNarrower extends ConceptValidator | ||
{ | ||
/** | ||
* @param Concept $concept | ||
* @return bool | ||
*/ | ||
protected function validateConcept(Concept $concept) | ||
{ | ||
$narrowerTerms = $concept->getProperty(Concept::PROPERTY_NARROWER); | ||
|
||
$loopedConcepts = []; | ||
foreach ($narrowerTerms as $narrowerTerm) { | ||
if (isset($loopedConcepts[$narrowerTerm->getValue()])) { | ||
$this->errorMessage = "Narrower term {$narrowerTerm->getValue()} is defined more than once"; | ||
return false; | ||
} | ||
$loopedConcepts[$narrowerTerm->getValue()] = true; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: jsmit | ||
* Date: 27/08/2015 | ||
* Time: 10:02 | ||
*/ | ||
|
||
namespace OpenSkos2\Validator\Concept; | ||
|
||
|
||
use OpenSkos2\Concept; | ||
use OpenSkos2\Validator\ConceptValidator; | ||
|
||
class DuplicateRelated extends ConceptValidator | ||
{ | ||
/** | ||
* @param Concept $concept | ||
* @return bool | ||
*/ | ||
protected function validateConcept(Concept $concept) | ||
{ | ||
$relatedTerms = $concept->getProperty(Concept::PROPERTY_RELATED); | ||
|
||
$loopedConcepts = []; | ||
foreach ($relatedTerms as $relatedTerm) { | ||
if (isset($loopedConcepts[$relatedTerm->getValue()])) { | ||
$this->errorMessage = "Related term {$relatedTerm->getValue()} is defined more than once"; | ||
return false; | ||
} | ||
$loopedConcepts[$relatedTerm->getValue()] = true; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: jsmit | ||
* Date: 27/08/2015 | ||
* Time: 10:57 | ||
*/ | ||
|
||
namespace OpenSkos2\Validator\Concept; | ||
|
||
|
||
use OpenSkos2\Concept; | ||
use OpenSkos2\Validator\ConceptValidator; | ||
|
||
class InScheme extends ConceptValidator | ||
{ | ||
/** | ||
* @param Concept $concept | ||
* @return bool | ||
*/ | ||
protected function validateConcept(Concept $concept) | ||
{ | ||
if (!count($concept->getProperty(Concept::PROPERTY_INSCHEME))) { | ||
$this->errorMessage = 'The concept must be included in at least one scheme.'; | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: jsmit | ||
* Date: 27/08/2015 | ||
* Time: 11:25 | ||
*/ | ||
|
||
namespace OpenSkos2\Validator\Concept; | ||
|
||
|
||
use OpenSkos2\Concept; | ||
use OpenSkos2\Validator\ConceptValidator; | ||
|
||
class RelatedToSelf extends ConceptValidator | ||
{ | ||
/** | ||
* @param Concept $concept | ||
* @return bool | ||
*/ | ||
protected function validateConcept(Concept $concept) | ||
{ | ||
$relationFields = array_merge(Concept::$classes['SemanticRelations'], Concept::$classes['MappingProperties']); | ||
|
||
$ownUri = $concept->getUri(); | ||
foreach ($relationFields as $field) { | ||
foreach ($concept->getProperty($field) as $object) { | ||
if ($object->getValue() == $ownUri) { | ||
$this->errorMessage ='The concept can not be related to itself.'; | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: jsmit | ||
* Date: 27/08/2015 | ||
* Time: 08:15 | ||
*/ | ||
|
||
namespace OpenSkos2\Validator; | ||
|
||
|
||
use OpenSkos2\Concept; | ||
use OpenSkos2\Rdf\Resource; | ||
|
||
abstract class ConceptValidator extends ResourceValidator | ||
{ | ||
/** | ||
* @param Resource $resource | ||
* @return bool | ||
*/ | ||
public function validate(Resource $resource) | ||
{ | ||
if ($resource instanceof Concept) { | ||
return $this->validateConcept($resource); | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* @param Concept $concept | ||
* @return bool | ||
*/ | ||
abstract protected function validateConcept(Concept $concept); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: jsmit | ||
* Date: 26/08/2015 | ||
* Time: 16:58 | ||
*/ | ||
|
||
namespace OpenSkos2\Validator; | ||
|
||
|
||
use OpenSkos2\Rdf\Resource; | ||
|
||
abstract class ResourceValidator | ||
{ | ||
protected $errorMessage; | ||
|
||
abstract public function validate(Resource $resource); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getErrorMessage() | ||
{ | ||
return $this->errorMessage; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="vendor/autoload.php" | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
verbose="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Openskos Test Suite"> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">library/</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<!--<log type="tap" target="build/report.tap"/>--> | ||
<!--<log type="junit" target="build/report.junit.xml"/>--> | ||
<!--<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>--> | ||
<!--<log type="coverage-text" target="build/coverage.txt"/>--> | ||
<!--<log type="coverage-clover" target="build/logs/clover.xml"/>--> | ||
</logging> | ||
</phpunit> |
40 changes: 40 additions & 0 deletions
40
tests/OpenSkos2/Validator/Concept/DuplicateBroaderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: jsmit | ||
* Date: 27/08/2015 | ||
* Time: 10:40 | ||
*/ | ||
|
||
namespace OpenSkos2\Validator\Concept; | ||
|
||
|
||
use OpenSkos2\Concept; | ||
use OpenSkos2\Rdf\Object; | ||
|
||
class DuplicateBroaderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
public function testValidate() | ||
{ | ||
$validator = new DuplicateBroader(); | ||
$concept = new Concept(); | ||
|
||
$this->assertTrue($validator->validate($concept)); | ||
|
||
$concept->addProperty(Concept::PROPERTY_BROADER, new Object(Object::TYPE_URI, 'http://example.com#broader')); | ||
|
||
$this->assertTrue($validator->validate($concept)); | ||
|
||
$concept->addProperty(Concept::PROPERTY_BROADER, new Object(Object::TYPE_URI, 'http://example.com#broader2')); | ||
|
||
$this->assertTrue($validator->validate($concept)); | ||
|
||
|
||
|
||
|
||
$concept->addProperty(Concept::PROPERTY_BROADER, new Object(Object::TYPE_URI, 'http://example.com#broader2')); | ||
|
||
$this->assertFalse($validator->validate($concept)); | ||
} | ||
} |
Oops, something went wrong.