forked from friendica/php-json-ld
Add support for normalization test suite.
- Handle rdfn:Urgna2012EvalTest and rdfn:Urdna2015EvalTest. - Use nquads input format for normalization tests. - Support normalization test suite format with various tweaks. Compacting the data would eliminate most of these changes but can't rely on compact to work in the code that tests compact! So hard coded fixes are used. - Support 'entries' and 'sequence' for tests. - Support 'include' as filename without a .jsonld extension. - Support 'type' and '@type' as aliases. - Support 'id' and '@id' as aliases. - Support 'action' and 'input' as aliases. - Support 'result' and 'expect' as aliases. - No longer strip '#t' prefix from '#tNNN' ids. - Default to positive test if nothing specified. - Add normalization test to travis-ci config. - Fix container infrastructure flag from 'root' to 'sudo'. - Update README with new testing info.
This commit is contained in:
parent
57b3279718
commit
c63a5961fb
14
.travis.yml
14
.travis.yml
|
@ -1,15 +1,17 @@
|
||||||
language: php
|
language: php
|
||||||
php:
|
php:
|
||||||
- 5.6
|
|
||||||
- 5.5
|
|
||||||
- 5.4
|
|
||||||
- 5.3
|
- 5.3
|
||||||
root: false
|
- 5.4
|
||||||
|
- 5.5
|
||||||
|
- 5.6
|
||||||
|
sudo: false
|
||||||
# download test suite and run tests... submodule? meta testing project with
|
# download test suite and run tests... submodule? meta testing project with
|
||||||
# all of the reference implementations?
|
# all of the reference implementations?
|
||||||
script:
|
script:
|
||||||
- git clone https://github.com/json-ld/json-ld.org.git spec
|
- git clone https://github.com/json-ld/json-ld.org.git _json-ld.org
|
||||||
- phpunit test.php -d spec/test-suite
|
- phpunit test.php -d ./_json-ld.org/test-suite
|
||||||
|
- git clone https://github.com/json-ld/normalization.git _normalization
|
||||||
|
- phpunit test.php -d ./_normalization/tests
|
||||||
notifications:
|
notifications:
|
||||||
email:
|
email:
|
||||||
on_success: change
|
on_success: change
|
||||||
|
|
11
README.md
11
README.md
|
@ -171,14 +171,16 @@ This library includes a sample testing utility which may be used to verify
|
||||||
that changes to the processor maintain the correct output.
|
that changes to the processor maintain the correct output.
|
||||||
|
|
||||||
To run the sample tests you will need to get the test suite files by cloning
|
To run the sample tests you will need to get the test suite files by cloning
|
||||||
the [json-ld.org repository][json-ld.org] hosted on GitHub:
|
the `json-ld.org` and `normalization` repositories hosted on GitHub:
|
||||||
|
|
||||||
https://github.com/json-ld/json-ld.org
|
- https://github.com/json-ld/json-ld.org
|
||||||
|
- https://github.com/json-ld/normalization
|
||||||
|
|
||||||
Then run the PHPUnit test.php application and point it at the directory
|
Then run the PHPUnit test.php application and point it at the directories
|
||||||
containing the tests.
|
containing the tests:
|
||||||
|
|
||||||
phpunit test.php -d {PATH_TO_JSON_LD_ORG/test-suite}
|
phpunit test.php -d {PATH_TO_JSON_LD_ORG/test-suite}
|
||||||
|
phpunit test.php -d {PATH_TO_NORMALIZATION/tests}
|
||||||
|
|
||||||
[Digital Bazaar]: http://digitalbazaar.com/
|
[Digital Bazaar]: http://digitalbazaar.com/
|
||||||
[JSON-LD]: http://json-ld.org/
|
[JSON-LD]: http://json-ld.org/
|
||||||
|
@ -187,4 +189,3 @@ containing the tests.
|
||||||
[PHP]: http://php.net
|
[PHP]: http://php.net
|
||||||
[RDFa]: http://www.w3.org/TR/rdfa-core/
|
[RDFa]: http://www.w3.org/TR/rdfa-core/
|
||||||
[RFC7159]: http://tools.ietf.org/html/rfc7159
|
[RFC7159]: http://tools.ietf.org/html/rfc7159
|
||||||
[json-ld.org]: https://github.com/json-ld/json-ld.org
|
|
||||||
|
|
131
test.php
131
test.php
|
@ -130,6 +130,42 @@ class JsonLdTestCase extends PHPUnit_Framework_TestCase {
|
||||||
$test->run('jsonld_normalize', array($input, $options));
|
$test->run('jsonld_normalize', array($input, $options));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests URGNA2012 normalization.
|
||||||
|
*
|
||||||
|
* @param JsonLdTest $test the test to run.
|
||||||
|
*
|
||||||
|
* @group normalize
|
||||||
|
* @dataProvider urgna2012Provider
|
||||||
|
*/
|
||||||
|
public function testUrgna2012($test) {
|
||||||
|
$this->test = $test;
|
||||||
|
$input = $test->readProperty('action');
|
||||||
|
$options = $test->createOptions(array(
|
||||||
|
'algorithm' => 'URGNA2012',
|
||||||
|
'inputFormat' => 'application/nquads',
|
||||||
|
'format' => 'application/nquads'));
|
||||||
|
$test->run('jsonld_normalize', array($input, $options));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests URDNA2015 normalization.
|
||||||
|
*
|
||||||
|
* @param JsonLdTest $test the test to run.
|
||||||
|
*
|
||||||
|
* @group normalize
|
||||||
|
* @dataProvider urdna2015Provider
|
||||||
|
*/
|
||||||
|
public function testUrdna2015($test) {
|
||||||
|
$this->test = $test;
|
||||||
|
$input = $test->readProperty('action');
|
||||||
|
$options = $test->createOptions(array(
|
||||||
|
'algorithm' => 'URDNA2015',
|
||||||
|
'inputFormat' => 'application/nquads',
|
||||||
|
'format' => 'application/nquads'));
|
||||||
|
$test->run('jsonld_normalize', array($input, $options));
|
||||||
|
}
|
||||||
|
|
||||||
public function expandProvider() {
|
public function expandProvider() {
|
||||||
return new JsonLdTestIterator('jld:ExpandTest');
|
return new JsonLdTestIterator('jld:ExpandTest');
|
||||||
}
|
}
|
||||||
|
@ -157,6 +193,14 @@ class JsonLdTestCase extends PHPUnit_Framework_TestCase {
|
||||||
public function frameProvider() {
|
public function frameProvider() {
|
||||||
return new JsonLdTestIterator('jld:FrameTest');
|
return new JsonLdTestIterator('jld:FrameTest');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function urgna2012Provider() {
|
||||||
|
return new JsonLdTestIterator('rdfn:Urgna2012EvalTest');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function urdna2015Provider() {
|
||||||
|
return new JsonLdTestIterator('rdfn:Urdna2015EvalTest');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class JsonLdManifest {
|
class JsonLdManifest {
|
||||||
|
@ -167,8 +211,14 @@ class JsonLdManifest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load(&$tests) {
|
public function load(&$tests) {
|
||||||
$sequence = JsonLdProcessor::getValues($this->data, 'sequence');
|
$entries = array_merge(
|
||||||
foreach($sequence as $entry) {
|
JsonLdProcessor::getValues($this->data, 'sequence'),
|
||||||
|
JsonLdProcessor::getValues($this->data, 'entries'));
|
||||||
|
$includes = JsonLdProcessor::getValues($this->data, 'include');
|
||||||
|
foreach($includes as $include) {
|
||||||
|
array_push($entries, $include . '.jsonld');
|
||||||
|
}
|
||||||
|
foreach($entries as $entry) {
|
||||||
if(is_string($entry)) {
|
if(is_string($entry)) {
|
||||||
$filename = join(
|
$filename = join(
|
||||||
DIRECTORY_SEPARATOR, array($this->dirname, $entry));
|
DIRECTORY_SEPARATOR, array($this->dirname, $entry));
|
||||||
|
@ -177,14 +227,17 @@ class JsonLdManifest {
|
||||||
$filename = $this->filename;
|
$filename = $this->filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(JsonLdProcessor::hasValue($entry, '@type', 'mf:Manifest')) {
|
if(JsonLdProcessor::hasValue($entry, '@type', 'mf:Manifest') ||
|
||||||
|
JsonLdProcessor::hasValue($entry, 'type', 'mf:Manifest')) {
|
||||||
// entry is another manifest
|
// entry is another manifest
|
||||||
$manifest = new JsonLdManifest($entry, $filename);
|
$manifest = new JsonLdManifest($entry, $filename);
|
||||||
$manifest->load($tests);
|
$manifest->load($tests);
|
||||||
} else {
|
} else {
|
||||||
// assume entry is a test
|
// assume entry is a test
|
||||||
$test = new JsonLdTest($this, $entry, $filename);
|
$test = new JsonLdTest($this, $entry, $filename);
|
||||||
$types = JsonLdProcessor::getValues($test->data, '@type');
|
$types = array_merge(
|
||||||
|
JsonLdProcessor::getValues($test->data, '@type'),
|
||||||
|
JsonLdProcessor::getValues($test->data, 'type'));
|
||||||
foreach($types as $type) {
|
foreach($types as $type) {
|
||||||
if(!isset($tests[$type])) {
|
if(!isset($tests[$type])) {
|
||||||
$tests[$type] = array();
|
$tests[$type] = array();
|
||||||
|
@ -202,27 +255,64 @@ class JsonLdTest {
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
$this->filename = $filename;
|
$this->filename = $filename;
|
||||||
$this->dirname = dirname($filename);
|
$this->dirname = dirname($filename);
|
||||||
$this->isPositive = JsonLdProcessor::hasValue(
|
$this->isPositive =
|
||||||
$data, '@type', 'jld:PositiveEvaluationTest');
|
JsonLdProcessor::hasValue(
|
||||||
$this->isNegative = JsonLdProcessor::hasValue(
|
$data, '@type', 'jld:PositiveEvaluationTest') ||
|
||||||
$data, '@type', 'jld:NegativeEvaluationTest');
|
JsonLdProcessor::hasValue(
|
||||||
|
$data, 'type', 'jld:PositiveEvaluationTest');
|
||||||
|
$this->isNegative =
|
||||||
|
JsonLdProcessor::hasValue(
|
||||||
|
$data, '@type', 'jld:NegativeEvaluationTest') ||
|
||||||
|
JsonLdProcessor::hasValue(
|
||||||
|
$data, 'type', 'jld:NegativeEvaluationTest');
|
||||||
|
|
||||||
// generate test name
|
// generate test name
|
||||||
$this->name = $manifest->data->name . ' ' . substr($data->{'@id'}, 2) .
|
if(isset($manifest->data->name)) {
|
||||||
' - ' . $this->data->name;
|
$manifestLabel = $manifest->data->name;
|
||||||
|
} else if(isset($manifest->data->label)) {
|
||||||
|
$manifestLabel = $manifest->data->label;
|
||||||
|
} else {
|
||||||
|
$manifestLabel = 'UNNAMED';
|
||||||
|
}
|
||||||
|
if(isset($this->data->id)) {
|
||||||
|
$testId = $this->data->id;
|
||||||
|
} else {
|
||||||
|
$testId = $this->data->{'@id'};
|
||||||
|
}
|
||||||
|
if(isset($this->data->name)) {
|
||||||
|
$testLabel = $this->data->name;
|
||||||
|
} else if(isset($this->data->label)) {
|
||||||
|
$testLabel = $this->data->label;
|
||||||
|
} else {
|
||||||
|
$testLabel = 'UNNAMED';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->name = $manifestLabel . ' ' . $testId . ' - ' . $testLabel;
|
||||||
|
|
||||||
// expand @id and input base
|
// expand @id and input base
|
||||||
|
if(isset($manifest->data->baseIri)) {
|
||||||
$data->{'@id'} = ($manifest->data->baseIri .
|
$data->{'@id'} = ($manifest->data->baseIri .
|
||||||
basename($manifest->filename) . $data->{'@id'});
|
basename($manifest->filename) . $data->{'@id'});
|
||||||
$this->base = $manifest->data->baseIri . $data->input;
|
$this->base = $manifest->data->baseIri . $data->input;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function _getResultProperty() {
|
||||||
|
if(isset($this->data->expect)) {
|
||||||
|
return 'expect';
|
||||||
|
} else if(isset($this->data->result)) {
|
||||||
|
return 'result';
|
||||||
|
} else {
|
||||||
|
throw new Exception('No test result property found.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function run($fn, $params) {
|
public function run($fn, $params) {
|
||||||
// read expected data
|
// read expected data
|
||||||
if($this->isNegative) {
|
if($this->isNegative) {
|
||||||
$this->expected = $this->data->expect;
|
$this->expected = $this->data->expect;
|
||||||
} else {
|
} else {
|
||||||
$this->expected = $this->readProperty('expect');
|
$this->expected = $this->readProperty($this->_getResultProperty());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -232,11 +322,14 @@ class JsonLdTest {
|
||||||
}
|
}
|
||||||
PHPUnit_Framework_TestCase::assertEquals($this->expected, $this->actual);
|
PHPUnit_Framework_TestCase::assertEquals($this->expected, $this->actual);
|
||||||
} catch(Exception $e) {
|
} catch(Exception $e) {
|
||||||
if($this->isPositive) {
|
// assume positive test
|
||||||
|
if($this->isNegative) {
|
||||||
|
$this->actual = $this->getJsonLdErrorCode($e);
|
||||||
|
PHPUnit_Framework_TestCase::assertEquals(
|
||||||
|
$this->expected, $this->actual);
|
||||||
|
} else {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
$this->actual = $this->getJsonLdErrorCode($e);
|
|
||||||
PHPUnit_Framework_TestCase::assertEquals($this->expected, $this->actual);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -541,8 +634,16 @@ class EarlReport extends PHPUnit_Util_Printer
|
||||||
PHPUnit_Framework_AssertionFailedError $e, $time) {
|
PHPUnit_Framework_AssertionFailedError $e, $time) {
|
||||||
$this->addAssertion($test->test, false);
|
$this->addAssertion($test->test, false);
|
||||||
if($test->result->shouldStop()) {
|
if($test->result->shouldStop()) {
|
||||||
|
if(isset($test->test->name)) {
|
||||||
|
$name = $test->test->name;
|
||||||
|
} else if(isset($test->test->label)) {
|
||||||
|
$name = $test->test->label;
|
||||||
|
} else {
|
||||||
|
$name = 'UNNAMED';
|
||||||
|
}
|
||||||
|
// FIXME
|
||||||
printf("\n\nFAILED\n");
|
printf("\n\nFAILED\n");
|
||||||
printf("Test: %s\n", $test->test->name);
|
printf("Test: %s\n", $name);
|
||||||
printf("Purpose: %s\n", $test->test->data->purpose);
|
printf("Purpose: %s\n", $test->test->data->purpose);
|
||||||
printf("EXPECTED: %s\n", Util::jsonldEncode($test->test->expected));
|
printf("EXPECTED: %s\n", Util::jsonldEncode($test->test->expected));
|
||||||
printf("ACTUAL: %s\n", Util::jsonldEncode($test->test->actual));
|
printf("ACTUAL: %s\n", Util::jsonldEncode($test->test->actual));
|
||||||
|
|
Loading…
Reference in a new issue