downgrade to kirby v3
This commit is contained in:
100
vendor/ml/json-ld/Test/DocumentTest.php
vendored
Normal file
100
vendor/ml/json-ld/Test/DocumentTest.php
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* (c) Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace ML\JsonLD\Test;
|
||||
|
||||
use ML\JsonLD\JsonLD;
|
||||
use ML\JsonLD\Document;
|
||||
|
||||
/**
|
||||
* Test the parsing of a JSON-LD document into a Document.
|
||||
*
|
||||
* @author Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*/
|
||||
class DocumentTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* The document instance being used throughout the tests.
|
||||
*
|
||||
* @var Document
|
||||
*/
|
||||
protected $document;
|
||||
|
||||
/**
|
||||
* Create the document to test.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->document = JsonLD::getDocument(
|
||||
dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'dataset.jsonld',
|
||||
array('base' => 'http://example.com/dataset.jsonld')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests whether all nodes are returned and blank nodes are renamed accordingly.
|
||||
*/
|
||||
public function testGetIri()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'http://example.com/dataset.jsonld',
|
||||
$this->document->getIri()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether all nodes are interlinked correctly.
|
||||
*/
|
||||
public function testGetGraphNames()
|
||||
{
|
||||
// The blank node graph name _:_:graphBn gets relabeled to _:b0 during node map generation
|
||||
$this->assertEquals(
|
||||
array('_:b0', 'http://example.com/named-graph'),
|
||||
$this->document->getGraphNames()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether all nodes also have the correct reverse links.
|
||||
*/
|
||||
public function testContainsGraph()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->document->containsGraph('/named-graph'),
|
||||
'Relative IRI'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$this->document->containsGraph('http://example.com/named-graph'),
|
||||
'Absolute IRI'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$this->document->containsGraph('_:b0'),
|
||||
'Blank node identifier'
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$this->document->containsGraph('http://example.org/not-here'),
|
||||
'Non-existent graph'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests isBlankNode()
|
||||
*/
|
||||
public function testRemoveGraph()
|
||||
{
|
||||
$this->document->removeGraph('/named-graph');
|
||||
|
||||
$this->assertFalse(
|
||||
$this->document->containsGraph('/named-graph'),
|
||||
'Is the removed graph still there?'
|
||||
);
|
||||
}
|
||||
}
|
||||
273
vendor/ml/json-ld/Test/EarlReportGenerator.php
vendored
Normal file
273
vendor/ml/json-ld/Test/EarlReportGenerator.php
vendored
Normal file
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* (c) Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace ML\JsonLD\Test;
|
||||
|
||||
/**
|
||||
* EarlReportGenerator
|
||||
*
|
||||
* A test listener to create an EARL report. It can be configured uses
|
||||
* the following configuration
|
||||
*
|
||||
* <listeners>
|
||||
* <listener class="\ML\JsonLD\Test\EarlReportGenerator">
|
||||
* <arguments>
|
||||
* <array>
|
||||
* <element key="target">
|
||||
* <string>...</string>
|
||||
* </element>
|
||||
* <element key="project-name">
|
||||
* <string>...</string>
|
||||
* </element>
|
||||
* <element key="project-url">
|
||||
* <string>...</string>
|
||||
* </element>
|
||||
* <element key="project-homepage">
|
||||
* <string>...</string>
|
||||
* </element>
|
||||
* <element key="license-url">
|
||||
* <string>...</string>
|
||||
* </element>
|
||||
* <element key="project-description">
|
||||
* <string>...</string>
|
||||
* </element>
|
||||
* <element key="programming-language">
|
||||
* <string>...</string>
|
||||
* </element>
|
||||
* <element key="developer-name">
|
||||
* <string>...</string>
|
||||
* </element>
|
||||
* <element key="developer-url">
|
||||
* <string>...</string>
|
||||
* </element>
|
||||
* <element key="developer-homepage">
|
||||
* <string>...</string>
|
||||
* </element>
|
||||
* </array>
|
||||
* </arguments>
|
||||
* </listener>
|
||||
* </listeners>
|
||||
*
|
||||
* @author Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*/
|
||||
class EarlReportGenerator extends \PHPUnit_Util_Printer implements \PHPUnit_Framework_TestListener
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $testTypeOfInterest = 'ML\\JsonLD\\Test\\W3CTestSuiteTest';
|
||||
|
||||
/**
|
||||
* @var array Lookup table for EARL statuses
|
||||
*/
|
||||
protected $earlStatuses;
|
||||
|
||||
/**
|
||||
* @var array Options
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* @var array Collected EARL assertions
|
||||
*/
|
||||
protected $assertions;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Configuration options
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
$reqOptions = array(
|
||||
'target',
|
||||
'project-name',
|
||||
'project-url',
|
||||
'project-homepage',
|
||||
'license-url',
|
||||
'project-description',
|
||||
'programming-language',
|
||||
'developer-name',
|
||||
'developer-url',
|
||||
'developer-homepage'
|
||||
);
|
||||
|
||||
foreach ($reqOptions as $option) {
|
||||
if (false === isset($options[$option])) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf('The "%s" option is not set', $option)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->options = $options;
|
||||
|
||||
$this->earlStatuses = array(
|
||||
\PHPUnit_Runner_BaseTestRunner::STATUS_PASSED => 'earl:passed',
|
||||
\PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED => 'earl:untested',
|
||||
\PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE => 'earl:cantTell',
|
||||
\PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE => 'earl:failed',
|
||||
\PHPUnit_Runner_BaseTestRunner::STATUS_ERROR => 'earl:failed'
|
||||
);
|
||||
|
||||
$this->assertions = array();
|
||||
|
||||
parent::__construct($options['target']);
|
||||
}
|
||||
|
||||
/**
|
||||
* A test ended.
|
||||
*
|
||||
* @param \PHPUnit_Framework_Test $test
|
||||
* @param float $time
|
||||
*/
|
||||
public function endTest(\PHPUnit_Framework_Test $test, $time)
|
||||
{
|
||||
if (false === ($test instanceof $this->testTypeOfInterest)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$assertion = array(
|
||||
'@type' => 'earl:Assertion',
|
||||
'earl:assertedBy' => $this->options['developer-url'],
|
||||
'earl:mode' => 'earl:automatic',
|
||||
'earl:test' => $test->getTestId(),
|
||||
'earl:result' => array(
|
||||
'@type' => 'earl:TestResult',
|
||||
'earl:outcome' => $this->earlStatuses[$test->getStatus()],
|
||||
'dc:date' => date('c')
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertions[] = $assertion;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function flush()
|
||||
{
|
||||
if (0 === $this->assertions) {
|
||||
return;
|
||||
}
|
||||
|
||||
$report = array(
|
||||
'@context' => array(
|
||||
'doap' => 'http://usefulinc.com/ns/doap#',
|
||||
'foaf' => 'http://xmlns.com/foaf/0.1/',
|
||||
'dc' => 'http://purl.org/dc/terms/',
|
||||
'earl' => 'http://www.w3.org/ns/earl#',
|
||||
'xsd' => 'http://www.w3.org/2001/XMLSchema#',
|
||||
'doap:homepage' => array('@type' => '@id'),
|
||||
'doap:license' => array('@type' => '@id'),
|
||||
'dc:creator' => array('@type' => '@id'),
|
||||
'foaf:homepage' => array('@type' => '@id'),
|
||||
'subjectOf' => array('@reverse' => 'earl:subject'),
|
||||
'earl:assertedBy' => array('@type' => '@id'),
|
||||
'earl:mode' => array('@type' => '@id'),
|
||||
'earl:test' => array('@type' => '@id'),
|
||||
'earl:outcome' => array('@type' => '@id'),
|
||||
'dc:date' => array('@type' => 'xsd:date')
|
||||
),
|
||||
'@id' => $this->options['project-url'],
|
||||
'@type' => array('doap:Project', 'earl:TestSubject', 'earl:Software'),
|
||||
'doap:name' => $this->options['project-name'],
|
||||
'dc:title' => $this->options['project-name'],
|
||||
'doap:homepage' => $this->options['project-homepage'],
|
||||
'doap:license' => $this->options['license-url'],
|
||||
'doap:description' => $this->options['project-description'],
|
||||
'doap:programming-language' => $this->options['programming-language'],
|
||||
'doap:developer' => array(
|
||||
'@id' => $this->options['developer-url'],
|
||||
'@type' => array('foaf:Person', 'earl:Assertor'),
|
||||
'foaf:name' => $this->options['developer-name'],
|
||||
'foaf:homepage' => $this->options['developer-homepage']
|
||||
),
|
||||
'dc:creator' => $this->options['developer-url'],
|
||||
'dc:date' => array(
|
||||
'@value' => date('Y-m-d'),
|
||||
'@type' => 'xsd:date'
|
||||
),
|
||||
'subjectOf' => $this->assertions
|
||||
);
|
||||
|
||||
$options = 0;
|
||||
|
||||
if (PHP_VERSION_ID >= 50400) {
|
||||
$options |= JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT;
|
||||
$report = json_encode($report, $options);
|
||||
} else {
|
||||
$report = json_encode($report);
|
||||
$report = str_replace('\\/', '/', $report); // unescape slahes
|
||||
|
||||
// unescape unicode
|
||||
$report = preg_replace_callback(
|
||||
'/\\\\u([a-f0-9]{4})/',
|
||||
function ($match) {
|
||||
return iconv('UCS-4LE', 'UTF-8', pack('V', hexdec($match[1])));
|
||||
},
|
||||
$report
|
||||
);
|
||||
}
|
||||
|
||||
$this->write($report);
|
||||
|
||||
parent::flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function startTestSuite(\PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function endTestSuite(\PHPUnit_Framework_TestSuite $suite)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function addIncompleteTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function addSkippedTest(\PHPUnit_Framework_Test $test, \Exception $e, $time)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function startTest(\PHPUnit_Framework_Test $test)
|
||||
{
|
||||
}
|
||||
}
|
||||
99
vendor/ml/json-ld/Test/FileGetContentsLoaderTest.php
vendored
Normal file
99
vendor/ml/json-ld/Test/FileGetContentsLoaderTest.php
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* (c) Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace ML\JsonLD\Test;
|
||||
|
||||
use ML\IRI\IRI;
|
||||
use ML\JsonLD\FileGetContentsLoader;
|
||||
|
||||
/**
|
||||
* Test the parsing of a JSON-LD document into a Document.
|
||||
*/
|
||||
class FileGetContentsLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
protected $iri;
|
||||
|
||||
protected $loader;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->iri = new IRI('https://www.example.com');
|
||||
$this->loader = new FileGetContentsLoader;
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
unset($iri);
|
||||
unset($this->loader);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testParseLinkHeadersExactsValues()
|
||||
{
|
||||
$headers = array(
|
||||
'<https://www.example.com>; param1=foo; param2="bar";',
|
||||
);
|
||||
|
||||
$parsed = $this->loader->parseLinkHeaders($headers, $this->iri);
|
||||
|
||||
$this->assertEquals('https://www.example.com', $parsed[0]['uri']);
|
||||
$this->assertEquals('foo', $parsed[0]['param1']);
|
||||
$this->assertEquals('bar', $parsed[0]['param2']);
|
||||
}
|
||||
|
||||
public function testParseLinkHeadersTrimsValues()
|
||||
{
|
||||
$headers = array(
|
||||
'< https://www.example.com >; param1= foo ; param2=" bar ";',
|
||||
);
|
||||
|
||||
$parsed = $this->loader->parseLinkHeaders($headers, $this->iri);
|
||||
|
||||
$this->assertEquals('https://www.example.com', $parsed[0]['uri']);
|
||||
$this->assertEquals('foo', $parsed[0]['param1']);
|
||||
$this->assertEquals('bar', $parsed[0]['param2']);
|
||||
}
|
||||
|
||||
public function testParseLinkHeadersWithMultipleHeaders()
|
||||
{
|
||||
$headers = array(
|
||||
'<https://www.example.com>; param1=foo; param2=bar;',
|
||||
'<https://www.example.org>; param1=fizz; param2=buzz;',
|
||||
);
|
||||
|
||||
$parsed = $this->loader->parseLinkHeaders($headers, $this->iri);
|
||||
|
||||
$this->assertCount(2, $parsed);
|
||||
}
|
||||
|
||||
public function testParseLinkHeadersWithMultipleLinks()
|
||||
{
|
||||
$headers = array(
|
||||
'<https://www.example.com>; param1=foo; param2=bar;, '
|
||||
. '<https://www.example.org>; param1=fizz; param2=buzz;'
|
||||
);
|
||||
|
||||
$parsed = $this->loader->parseLinkHeaders($headers, $this->iri);
|
||||
|
||||
$this->assertCount(2, $parsed);
|
||||
$this->assertEquals('https://www.example.com', $parsed[0]['uri']);
|
||||
$this->assertEquals('https://www.example.org', $parsed[1]['uri']);
|
||||
}
|
||||
|
||||
public function testParseLinkHeadersConvertsRelativeLinksToAbsolute()
|
||||
{
|
||||
$headers = array('</foo/bar>;');
|
||||
$parsed = $this->loader->parseLinkHeaders($headers, $this->iri);
|
||||
$this->assertEquals('https://www.example.com/foo/bar', $parsed[0]['uri']);
|
||||
}
|
||||
}
|
||||
36
vendor/ml/json-ld/Test/Fixtures/dataset.jsonld
vendored
Normal file
36
vendor/ml/json-ld/Test/Fixtures/dataset.jsonld
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
{
|
||||
"@context": {
|
||||
"@vocab": "http://example.com/vocab#",
|
||||
"references": { "@type": "@id" }
|
||||
},
|
||||
"@graph": [
|
||||
{
|
||||
"@id": "/node1",
|
||||
"references": [ "_:graphBn", "/named-graph" ]
|
||||
},
|
||||
{
|
||||
"@id": "_:graphBn",
|
||||
"@graph": [
|
||||
{
|
||||
"@id": "_:graphBn/node1",
|
||||
"name": "_:graphBn/node1",
|
||||
"references": [ "_:bnode", "/node1", "/named-graph/node1" ]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"@id": "/named-graph",
|
||||
"@graph": [
|
||||
{
|
||||
"@id": "/named-graph/node1",
|
||||
"name": "/named-graph/node1",
|
||||
"references": [ "_:bnode", "/node1", "_:graphBn/node1" ]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"@id": "_:bnode",
|
||||
"name": "_:bnode"
|
||||
}
|
||||
]
|
||||
}
|
||||
24
vendor/ml/json-ld/Test/Fixtures/sample-compacted.jsonld
vendored
Normal file
24
vendor/ml/json-ld/Test/Fixtures/sample-compacted.jsonld
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"@context": {
|
||||
"t1": "http://example.com/t1",
|
||||
"t2": "http://example.com/t2",
|
||||
"term1": "http://example.com/term1",
|
||||
"term2": "http://example.com/term2",
|
||||
"term3": "http://example.com/term3",
|
||||
"term4": "http://example.com/term4",
|
||||
"term5": "http://example.com/term5"
|
||||
},
|
||||
"@id": "http://example.com/id1",
|
||||
"@type": "t1",
|
||||
"term1": "v1",
|
||||
"term2": { "@value": "v2", "@type": "t2" },
|
||||
"term3": { "@value": "v3", "@language": "en" },
|
||||
"term4": 4,
|
||||
"term5": [ 50, 51 ],
|
||||
"http://example.com/term6": [
|
||||
{ "@value": "1", "@type": "t1" },
|
||||
{ "@value": "2", "@type": "t2" },
|
||||
{ "@value": "3", "@language": "en" },
|
||||
{ "@value": "4", "@language": "de" }
|
||||
]
|
||||
}
|
||||
11
vendor/ml/json-ld/Test/Fixtures/sample-context.jsonld
vendored
Normal file
11
vendor/ml/json-ld/Test/Fixtures/sample-context.jsonld
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"@context": {
|
||||
"t1": "http://example.com/t1",
|
||||
"t2": "http://example.com/t2",
|
||||
"term1": "http://example.com/term1",
|
||||
"term2": "http://example.com/term2",
|
||||
"term3": "http://example.com/term3",
|
||||
"term4": "http://example.com/term4",
|
||||
"term5": "http://example.com/term5"
|
||||
}
|
||||
}
|
||||
20
vendor/ml/json-ld/Test/Fixtures/sample-expanded.jsonld
vendored
Normal file
20
vendor/ml/json-ld/Test/Fixtures/sample-expanded.jsonld
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
[
|
||||
{
|
||||
"@id": "http://example.com/id1",
|
||||
"@type": [ "http://example.com/t1" ],
|
||||
"http://example.com/term1": [ {"@value": "v1"} ],
|
||||
"http://example.com/term2": [ {"@value": "v2", "@type": "http://example.com/t2"} ],
|
||||
"http://example.com/term3": [ {"@value": "v3", "@language": "en"} ],
|
||||
"http://example.com/term4": [ {"@value": 4} ],
|
||||
"http://example.com/term5": [
|
||||
{ "@value": 50 },
|
||||
{ "@value": 51 }
|
||||
],
|
||||
"http://example.com/term6": [
|
||||
{ "@value": "1", "@type": "http://example.com/t1" },
|
||||
{ "@value": "2", "@type": "http://example.com/t2" },
|
||||
{ "@value": "3", "@language": "en" },
|
||||
{ "@value": "4", "@language": "de" }
|
||||
]
|
||||
}
|
||||
]
|
||||
34
vendor/ml/json-ld/Test/Fixtures/sample-flattened.jsonld
vendored
Normal file
34
vendor/ml/json-ld/Test/Fixtures/sample-flattened.jsonld
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"@context": {
|
||||
"t1": "http://example.com/t1",
|
||||
"t2": "http://example.com/t2",
|
||||
"term1": "http://example.com/term1",
|
||||
"term2": "http://example.com/term2",
|
||||
"term3": "http://example.com/term3",
|
||||
"term4": "http://example.com/term4",
|
||||
"term5": "http://example.com/term5"
|
||||
},
|
||||
"@graph": [
|
||||
{
|
||||
"@id": "http://example.com/id1",
|
||||
"@type": "t1",
|
||||
"term1": "v1",
|
||||
"term2": {
|
||||
"@type": "t2",
|
||||
"@value": "v2"
|
||||
},
|
||||
"term3": {
|
||||
"@language": "en",
|
||||
"@value": "v3"
|
||||
},
|
||||
"term4": 4,
|
||||
"term5": [ 50, 51 ],
|
||||
"http://example.com/term6": [
|
||||
{ "@value": "1", "@type": "t1" },
|
||||
{ "@value": "2", "@type": "t2" },
|
||||
{ "@value": "3", "@language": "en" },
|
||||
{ "@value": "4", "@language": "de" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
22
vendor/ml/json-ld/Test/Fixtures/sample-in.jsonld
vendored
Normal file
22
vendor/ml/json-ld/Test/Fixtures/sample-in.jsonld
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"@context": {
|
||||
"t1": "http://example.com/t1",
|
||||
"t2": "http://example.com/t2",
|
||||
"term1": "http://example.com/term1",
|
||||
"term3": "http://example.com/term3",
|
||||
"term5": "http://example.com/term5"
|
||||
},
|
||||
"@id": "http://example.com/id1",
|
||||
"@type": "t1",
|
||||
"term1": "v1",
|
||||
"http://example.com/term2": { "@value": "v2", "@type": "t2" },
|
||||
"term3": { "@value": "v3", "@language": "en" },
|
||||
"http://example.com/term4": 4,
|
||||
"term5": [ 50, 51 ],
|
||||
"http://example.com/term6": [
|
||||
{ "@value": "1", "@type": "t1" },
|
||||
{ "@value": "2", "@type": "t2" },
|
||||
{ "@value": "3", "@language": "en" },
|
||||
{ "@value": "4", "@language": "de" }
|
||||
]
|
||||
}
|
||||
23
vendor/ml/json-ld/Test/Fixtures/sample-serialized-document.jsonld
vendored
Normal file
23
vendor/ml/json-ld/Test/Fixtures/sample-serialized-document.jsonld
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
[
|
||||
{
|
||||
"@id": "http://example.com/id1",
|
||||
"@type": [ "http://example.com/t1" ],
|
||||
"http://example.com/term1": [ {"@value": "v1"} ],
|
||||
"http://example.com/term2": [ {"@value": "v2", "@type": "http://example.com/t2"} ],
|
||||
"http://example.com/term3": [ {"@value": "v3", "@language": "en"} ],
|
||||
"http://example.com/term4": [ {"@value": 4} ],
|
||||
"http://example.com/term5": [
|
||||
{"@value": 50 },
|
||||
{"@value": 51 }
|
||||
],
|
||||
"http://example.com/term6": [
|
||||
{ "@value": "1", "@type": "http://example.com/t1" },
|
||||
{ "@value": "2", "@type": "http://example.com/t2" },
|
||||
{ "@value": "3", "@language": "en" },
|
||||
{ "@value": "4", "@language": "de" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"@id": "http://example.com/t1"
|
||||
}
|
||||
]
|
||||
915
vendor/ml/json-ld/Test/GraphTest.php
vendored
Normal file
915
vendor/ml/json-ld/Test/GraphTest.php
vendored
Normal file
@@ -0,0 +1,915 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* (c) Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace ML\JsonLD\Test;
|
||||
|
||||
use ML\JsonLD\Document;
|
||||
use ML\JsonLD\FileGetContentsLoader;
|
||||
use ML\JsonLD\Graph;
|
||||
use ML\JsonLD\GraphInterface;
|
||||
use ML\JsonLD\Node;
|
||||
use ML\JsonLD\LanguageTaggedString;
|
||||
use ML\JsonLD\TypedValue;
|
||||
use ML\JsonLD\RdfConstants;
|
||||
|
||||
/**
|
||||
* Test the parsing of a JSON-LD document into a Graph.
|
||||
*
|
||||
* @author Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*/
|
||||
class GraphTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* The graph instance being used throughout the tests.
|
||||
*
|
||||
* @var GraphInterface
|
||||
*/
|
||||
protected $graph;
|
||||
|
||||
/**
|
||||
* The document loader used to parse expected values.
|
||||
*/
|
||||
protected $documentLoader;
|
||||
|
||||
/**
|
||||
* Create the graph to test.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$json = <<<JSON_LD_DOCUMENT
|
||||
{
|
||||
"@context": {
|
||||
"ex": "http://vocab.com/",
|
||||
"ex:lang": { "@language": "en" },
|
||||
"ex:typed": { "@type": "ex:type/datatype" },
|
||||
"Node": "ex:type/node"
|
||||
},
|
||||
"@graph": [
|
||||
{
|
||||
"@id": "1",
|
||||
"@type": "ex:type/node",
|
||||
"ex:name": "1",
|
||||
"ex:link": { "@id": "./2" },
|
||||
"ex:contains": { "ex:nested": "1.1" }
|
||||
},
|
||||
{
|
||||
"@id": "/node/2",
|
||||
"ex:name": "2",
|
||||
"@type": "ex:type/nodeWithAliases",
|
||||
"ex:lang": "language-tagged string",
|
||||
"ex:typed": "typed value",
|
||||
"ex:link": { "@id": "/node/3" },
|
||||
"ex:contains": [
|
||||
{ "ex:nested": "2.1" },
|
||||
{ "ex:nested": "2.2" }
|
||||
],
|
||||
"ex:aliases": [ "node2", 2 ]
|
||||
},
|
||||
{
|
||||
"@id": "http://example.com/node/3",
|
||||
"ex:name": "3",
|
||||
"@type": "Node",
|
||||
"ex:link": { "@id": "http://example.com/node/1" },
|
||||
"ex:contains": {
|
||||
"@id": "_:someBlankNode",
|
||||
"ex:nested": "3.1"
|
||||
},
|
||||
"ex:lang": [
|
||||
"language-tagged string: en",
|
||||
{ "@value": "language-tagged string: de", "@language": "de" },
|
||||
{ "@value": "language-tagged string: en", "@language": "en" }
|
||||
],
|
||||
"ex:typed": [
|
||||
"typed value",
|
||||
{ "@value": "typed value", "@language": "ex:/type/otherDataType" },
|
||||
{ "@value": "typed value", "@language": "ex:/type/datatype" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
JSON_LD_DOCUMENT;
|
||||
|
||||
$doc = Document::load($json, array('base' => 'http://example.com/node/index.jsonld'));
|
||||
$this->graph = $doc->getGraph();
|
||||
$this->documentLoader = new FileGetContentsLoader();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests whether all nodes are returned and blank nodes are renamed accordingly.
|
||||
*/
|
||||
public function testGetNodes()
|
||||
{
|
||||
$nodeIds = array(
|
||||
'http://example.com/node/1',
|
||||
'http://example.com/node/2',
|
||||
'http://example.com/node/3',
|
||||
'_:b0',
|
||||
'_:b1',
|
||||
'_:b2',
|
||||
'_:b3',
|
||||
'http://vocab.com/type/node',
|
||||
'http://vocab.com/type/nodeWithAliases'
|
||||
);
|
||||
|
||||
$nodes = $this->graph->getNodes();
|
||||
$this->assertCount(count($nodeIds), $nodes);
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
// Is the node's ID valid?
|
||||
$this->assertContains($node->getId(), $nodeIds, 'Found unexpected node ID: ' . $node->getId());
|
||||
|
||||
// Is the node of the right type?
|
||||
$this->assertInstanceOf('ML\JsonLD\Node', $node);
|
||||
|
||||
// Does the graph return the same instance?
|
||||
$n = $this->graph->getNode($node->getId());
|
||||
$this->assertSame($node, $n, 'same instance');
|
||||
$this->assertTrue($node->equals($n), 'equals');
|
||||
$this->assertSame($this->graph, $n->getGraph(), 'linked to graph');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether all nodes are interlinked correctly.
|
||||
*/
|
||||
public function testNodeRelationships()
|
||||
{
|
||||
$node1 = $this->graph->getNode('http://example.com/node/1');
|
||||
$node2 = $this->graph->getNode('http://example.com/node/2');
|
||||
$node3 = $this->graph->getNode('http://example.com/node/3');
|
||||
|
||||
$node1_1 = $this->graph->getNode('_:b0');
|
||||
$node2_1 = $this->graph->getNode('_:b1');
|
||||
$node2_2 = $this->graph->getNode('_:b2');
|
||||
$node3_1 = $this->graph->getNode('_:b3');
|
||||
|
||||
$nodeType = $this->graph->getNode('http://vocab.com/type/node');
|
||||
$nodeWithAliasesType = $this->graph->getNode('http://vocab.com/type/nodeWithAliases');
|
||||
|
||||
$this->assertSame($node2, $node1->getProperty('http://vocab.com/link'), 'n1 -link-> n2');
|
||||
$this->assertSame($node1_1, $node1->getProperty('http://vocab.com/contains'), 'n1 -contains-> n1.1');
|
||||
$this->assertSame($nodeType, $node1->getType(), 'n1 type');
|
||||
|
||||
$this->assertSame($node3, $node2->getProperty('http://vocab.com/link'), 'n2 -link-> n3');
|
||||
$values = $node2->getProperty('http://vocab.com/contains');
|
||||
$this->assertCount(2, $values, 'n2 -contains-> 2 nodes');
|
||||
$this->assertSame($node2_1, $values[0], 'n2 -contains-> n2.1');
|
||||
$this->assertSame($node2_2, $values[1], 'n2 -contains-> n2.1');
|
||||
$this->assertSame($nodeWithAliasesType, $node2->getType(), 'n2 type');
|
||||
|
||||
$this->assertSame($node1, $node3->getProperty('http://vocab.com/link'), 'n3 -link-> n1');
|
||||
$this->assertSame($node3_1, $node3->getProperty('http://vocab.com/contains'), 'n3 -contains-> n3.1');
|
||||
$this->assertSame($nodeType, $node3->getType(), 'n3 type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether all nodes also have the correct reverse links.
|
||||
*/
|
||||
public function testNodeReverseRelationships()
|
||||
{
|
||||
$node1 = $this->graph->getNode('http://example.com/node/1');
|
||||
$node2 = $this->graph->getNode('http://example.com/node/2');
|
||||
$node3 = $this->graph->getNode('http://example.com/node/3');
|
||||
|
||||
$node1_1 = $this->graph->getNode('_:b0');
|
||||
$node2_1 = $this->graph->getNode('_:b1');
|
||||
$node2_2 = $this->graph->getNode('_:b2');
|
||||
$node3_1 = $this->graph->getNode('_:b3');
|
||||
|
||||
$nodeType = $this->graph->getNode('http://vocab.com/type/node');
|
||||
$nodeWithAliasesType = $this->graph->getNode('http://vocab.com/type/nodeWithAliases');
|
||||
|
||||
$this->assertSame($node1, $node2->getReverseProperty('http://vocab.com/link'), 'n2 <-link- n1');
|
||||
$this->assertSame($node1, $node1_1->getReverseProperty('http://vocab.com/contains'), 'n1.1 <-contains- n1');
|
||||
|
||||
$this->assertSame($node2, $node3->getReverseProperty('http://vocab.com/link'), 'n3 <-link- n2');
|
||||
$this->assertSame($node2, $node2_1->getReverseProperty('http://vocab.com/contains'), 'n2.1 <-contains- n2');
|
||||
$this->assertSame($node2, $node2_2->getReverseProperty('http://vocab.com/contains'), 'n2.1 <-contains- n2');
|
||||
|
||||
$this->assertSame($node3, $node1->getReverseProperty('http://vocab.com/link'), 'n1 <-link- n3');
|
||||
$this->assertSame($node3, $node3_1->getReverseProperty('http://vocab.com/contains'), 'n3.1 <-contains- n3');
|
||||
|
||||
$this->assertSame(array($node1, $node3), $nodeType->getReverseProperty(Node::TYPE), 'n1+n3 <-type- nodeType');
|
||||
$this->assertSame(array($node2), $nodeWithAliasesType->getNodesWithThisType(), 'n2 <-type- nodeWithAliases');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests isBlankNode()
|
||||
*/
|
||||
public function testNodeIsBlankNode()
|
||||
{
|
||||
$this->assertFalse($this->graph->getNode('http://example.com/node/1')->isBlankNode(), 'n1');
|
||||
$this->assertFalse($this->graph->getNode('http://example.com/node/2')->isBlankNode(), 'n2');
|
||||
$this->assertFalse($this->graph->getNode('http://example.com/node/3')->isBlankNode(), 'n3');
|
||||
|
||||
$this->assertTrue($this->graph->getNode('_:b0')->isBlankNode(), '_:b0');
|
||||
$this->assertTrue($this->graph->getNode('_:b1')->isBlankNode(), '_:b1');
|
||||
$this->assertTrue($this->graph->getNode('_:b2')->isBlankNode(), '_:b2');
|
||||
$this->assertTrue($this->graph->getNode('_:b3')->isBlankNode(), '_:b3');
|
||||
|
||||
$node = $this->graph->createNode();
|
||||
$this->assertTrue($node->isBlankNode(), 'new node without ID');
|
||||
|
||||
$node = $this->graph->createNode('_:fljdf');
|
||||
$this->assertTrue($node->isBlankNode(), 'new node blank node ID');
|
||||
|
||||
$node = $this->graph->createNode('http://www.example.com/node/new');
|
||||
$this->assertFalse($node->isBlankNode(), 'new node with ID');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if reverse node relationships are updated when a property is updated.
|
||||
*/
|
||||
public function testNodeReverseRelationshipsUpdated()
|
||||
{
|
||||
$node1 = $this->graph->getNode('http://example.com/node/1');
|
||||
$node1_1 = $this->graph->getNode('_:b0');
|
||||
$node2 = $this->graph->getNode('http://example.com/node/2');
|
||||
$node3 = $this->graph->getNode('http://example.com/node/3');
|
||||
|
||||
$nodeType = $this->graph->getNode('http://vocab.com/type/node');
|
||||
$nodeWithAliasesType = $this->graph->getNode('http://vocab.com/type/nodeWithAliases');
|
||||
|
||||
$revProperties = $node2->getReverseProperties();
|
||||
$this->assertCount(1, $revProperties, 'Check number of node2\'s reverse properties');
|
||||
$this->assertSame(
|
||||
array('http://vocab.com/link' => array($node1)),
|
||||
$revProperties,
|
||||
'Check node2\'s reverse properties'
|
||||
);
|
||||
|
||||
$node1->setProperty('http://vocab.com/link', null);
|
||||
$this->assertNull($node1->getProperty('http://vocab.com/link'), 'n1 -link-> n2 removed');
|
||||
|
||||
$node1->removePropertyValue('http://vocab.com/contains', $node1_1);
|
||||
$this->assertNull($node1->getProperty('http://vocab.com/contains'), 'n1 -contains-> n1.1 removed');
|
||||
|
||||
$this->assertNull($node2->getReverseProperty('http://vocab.com/link'), 'n2 <-link- n1 removed');
|
||||
$this->assertNull($node1_1->getReverseProperty('http://vocab.com/contains'), 'n1.1 <-contains- n1 removed');
|
||||
|
||||
$expectedProperties = array(
|
||||
Node::TYPE => $this->graph->getNode('http://vocab.com/type/node'),
|
||||
'http://vocab.com/name' => new TypedValue('1', RdfConstants::XSD_STRING)
|
||||
);
|
||||
$properties = $node1->getProperties();
|
||||
$this->assertCount(2, $properties, 'Check number of properties');
|
||||
$this->assertEquals($expectedProperties, $properties, 'Check properties');
|
||||
|
||||
$this->assertSame(array($node1, $node3), $nodeType->getNodesWithThisType(), 'n1+n3 <-type- nodeType');
|
||||
$this->assertSame($node2, $nodeWithAliasesType->getReverseProperty(Node::TYPE), 'n2 <-type- nodeWithAliases');
|
||||
|
||||
$node1->setType(null);
|
||||
$node2->removeType($nodeWithAliasesType);
|
||||
|
||||
$this->assertSame($node3, $nodeType->getReverseProperty(Node::TYPE), 'n3 <-type- nodeType');
|
||||
$this->assertSame(array(), $nodeWithAliasesType->getNodesWithThisType(), 'nodeWithAliases removed from n2');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the removal of nodes from the graph.
|
||||
*/
|
||||
public function testNodeRemoval()
|
||||
{
|
||||
// Remove node 1
|
||||
$node1 = $this->graph->getNode('/node/1');
|
||||
$node1_1 = $this->graph->getNode('_:b0');
|
||||
$node2 = $this->graph->getNode('http://example.com/node/2');
|
||||
|
||||
$this->assertTrue($this->graph->containsNode('http://example.com/node/1'), 'node 1 in graph?');
|
||||
|
||||
$this->assertSame(
|
||||
array('http://vocab.com/link' => array($node1)),
|
||||
$node2->getReverseProperties(),
|
||||
'Check node2\'s reverse properties'
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
array('http://vocab.com/contains' => array($node1)),
|
||||
$node1_1->getReverseProperties(),
|
||||
'Check node1.1\'s reverse properties'
|
||||
);
|
||||
|
||||
$node1->removeFromGraph();
|
||||
|
||||
$this->assertSame(array(), $node2->getReverseProperties(), 'n2 reverse properties');
|
||||
$this->assertNull($node2->getReverseProperty('http://vocab.com/link'), 'n2 <-link- n1 removed');
|
||||
|
||||
$this->assertSame(array(), $node1_1->getReverseProperties(), 'n1.1 reverse properties');
|
||||
$this->assertNull($node1_1->getReverseProperty('http://vocab.com/contains'), 'n1.1 <-contains- n1 removed');
|
||||
|
||||
$this->assertFalse($this->graph->containsNode('/node/1'), 'node 1 still in graph?');
|
||||
$this->assertNull($node1->getGraph(), 'node 1\'s graph reset?');
|
||||
|
||||
// Remove node 2
|
||||
$node2 = $this->graph->getNode('http://example.com/node/2');
|
||||
$node2_1 = $this->graph->getNode('_:b1');
|
||||
$node2_2 = $this->graph->getNode('_:b2');
|
||||
$node3 = $this->graph->getNode('/node/3');
|
||||
|
||||
$this->assertTrue($this->graph->containsNode('/node/2'), 'node 2 in graph?');
|
||||
|
||||
$this->assertSame(
|
||||
array('http://vocab.com/link' => array($node2)),
|
||||
$node3->getReverseProperties(),
|
||||
'Check node3\'s reverse properties'
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
array('http://vocab.com/contains' => array($node2)),
|
||||
$node2_1->getReverseProperties(),
|
||||
'Check node2.1\'s reverse properties'
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
array('http://vocab.com/contains' => array($node2)),
|
||||
$node2_2->getReverseProperties(),
|
||||
'Check node2.2\'s reverse properties'
|
||||
);
|
||||
|
||||
$this->graph->removeNode($node2);
|
||||
|
||||
$this->assertSame(array(), $node3->getReverseProperties(), 'n3 reverse properties');
|
||||
$this->assertNull($node3->getReverseProperty('http://vocab.com/link'), 'n3 <-link- n2 removed');
|
||||
|
||||
$this->assertSame(array(), $node2_1->getReverseProperties(), 'n2.1 reverse properties');
|
||||
$this->assertNull($node2_1->getReverseProperty('http://vocab.com/contains'), 'n2.1 <-contains- n2 removed');
|
||||
|
||||
$this->assertSame(array(), $node2_2->getReverseProperties(), 'n2.2 reverse properties');
|
||||
$this->assertNull($node2_2->getReverseProperty('http://vocab.com/contains'), 'n2.2 <-contains- n2 removed');
|
||||
|
||||
$this->assertFalse($this->graph->containsNode('./2'), 'node 2 still in graph?');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the removal of node types from the graph.
|
||||
*/
|
||||
public function testNodeTypeRemoval()
|
||||
{
|
||||
// Remove nodeType
|
||||
$node1 = $this->graph->getNode('http://example.com/node/1');
|
||||
$node3 = $this->graph->getNode('/node/3');
|
||||
$nodeType = $this->graph->getNode('http://vocab.com/type/node');
|
||||
|
||||
$this->assertTrue($this->graph->containsNode('http://vocab.com/type/node'), 'node type in graph?');
|
||||
|
||||
$this->assertSame($nodeType, $node1->getType(), 'n1 type');
|
||||
$this->assertSame($nodeType, $node3->getType(), 'n3 type');
|
||||
|
||||
$this->assertSame(
|
||||
array(Node::TYPE => array($node1, $node3)),
|
||||
$nodeType->getReverseProperties(),
|
||||
'Check node type\'s reverse properties'
|
||||
);
|
||||
|
||||
$this->graph->removeNode($nodeType);
|
||||
|
||||
$this->assertSame(array(), $nodeType->getReverseProperties(), 'node type\'s reverse properties');
|
||||
$this->assertSame(array(), $nodeType->getNodesWithThisType(), 'n1+n3 <-type- node type removed');
|
||||
|
||||
$this->assertNull($node1->getType(), 'n1 type removed');
|
||||
$this->assertNull($node3->getType(), 'n3 type removed');
|
||||
|
||||
$this->assertFalse($this->graph->containsNode('http://vocab.com/type/node'), 'node type still in graph?');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if adding a value maintains uniqueness
|
||||
*/
|
||||
public function testNodePropertyUniqueness()
|
||||
{
|
||||
// Null
|
||||
$node = $this->graph->getNode('http://example.com/node/1');
|
||||
$this->assertNull($node->getProperty('http://example.com/node/1'), 'inexistent');
|
||||
|
||||
$node->addPropertyValue('http://vocab.com/inexistent', null);
|
||||
$this->assertNull($node->getProperty('http://example.com/node/1'), 'inexistent + null');
|
||||
|
||||
$node->removeProperty('http://vocab.com/inexistent');
|
||||
$node->removePropertyValue('http://vocab.com/inexistent', null);
|
||||
$this->assertNull($node->getProperty('http://example.com/node/1'), 'inexistent removed');
|
||||
|
||||
// Scalars
|
||||
$node = $this->graph->getNode('http://example.com/node/1');
|
||||
|
||||
$initialNameValue = $node->getProperty('http://vocab.com/name');
|
||||
|
||||
$this->assertEquals(
|
||||
new TypedValue('1', RdfConstants::XSD_STRING),
|
||||
$node->getProperty('http://vocab.com/name'),
|
||||
'name: initial value'
|
||||
);
|
||||
|
||||
$node->addPropertyValue('http://vocab.com/name', '1');
|
||||
$node->addPropertyValue('http://vocab.com/name', null);
|
||||
$this->assertSame($initialNameValue, $node->getProperty('http://vocab.com/name'), 'name: still same');
|
||||
|
||||
$node->addPropertyValue('http://vocab.com/name', 1);
|
||||
$this->assertEquals(
|
||||
array($initialNameValue, new TypedValue('1', RdfConstants::XSD_INTEGER)),
|
||||
$node->getProperty('http://vocab.com/name'),
|
||||
'name: new value'
|
||||
);
|
||||
|
||||
$node->removePropertyValue('http://vocab.com/name', 1);
|
||||
$this->assertSame($initialNameValue, $node->getProperty('http://vocab.com/name'), 'name: removed new value');
|
||||
|
||||
// Language-tagged strings
|
||||
$node = $this->graph->getNode('http://example.com/node/2');
|
||||
$value = $node->getProperty('http://vocab.com/lang');
|
||||
|
||||
$this->assertInstanceOf('ML\JsonLD\LanguageTaggedString', $value, 'lang: initial value type');
|
||||
$this->assertEquals('language-tagged string', $value->getValue(), 'lang: initial value');
|
||||
$this->assertEquals('en', $value->getLanguage(), 'lang: initial language');
|
||||
|
||||
$sameLangValue = new LanguageTaggedString('language-tagged string', 'en');
|
||||
$this->assertTrue($value->equals($sameLangValue), 'lang: equals same');
|
||||
|
||||
$newLangValue1 = new LanguageTaggedString('language-tagged string', 'de');
|
||||
$this->assertFalse($value->equals($newLangValue1), 'lang: equals new1');
|
||||
|
||||
$newLangValue2 = new LanguageTaggedString('other language-tagged string', 'en');
|
||||
$this->assertFalse($value->equals($newLangValue2), 'lang: equals new2');
|
||||
|
||||
$node->addPropertyValue('http://vocab.com/lang', $sameLangValue);
|
||||
$this->assertSame($value, $node->getProperty('http://vocab.com/lang'), 'lang: still same');
|
||||
|
||||
$node->addPropertyValue('http://vocab.com/lang', $newLangValue1);
|
||||
$node->addPropertyValue('http://vocab.com/lang', $newLangValue2);
|
||||
|
||||
$value = $node->getProperty('http://vocab.com/lang');
|
||||
$this->assertCount(3, $value, 'lang: count values added');
|
||||
|
||||
$this->assertTrue($sameLangValue->equals($value[0]), 'lang: check values 1');
|
||||
$this->assertTrue($newLangValue1->equals($value[1]), 'lang: check values 2');
|
||||
$this->assertTrue($newLangValue2->equals($value[2]), 'lang: check values 3');
|
||||
|
||||
$node->removePropertyValue('http://vocab.com/lang', $newLangValue1);
|
||||
$value = $node->getProperty('http://vocab.com/lang');
|
||||
$this->assertCount(2, $value, 'lang: count value 1 removed again');
|
||||
|
||||
$this->assertTrue($sameLangValue->equals($value[0]), 'lang: check values 1 (2)');
|
||||
$this->assertTrue($newLangValue2->equals($value[1]), 'lang: check values 2 (2)');
|
||||
|
||||
// Typed values
|
||||
$node = $this->graph->getNode('http://example.com/node/2');
|
||||
$value = $node->getProperty('http://vocab.com/typed');
|
||||
|
||||
$this->assertInstanceOf('ML\JsonLD\TypedValue', $value, 'typed: initial value class');
|
||||
$this->assertEquals('typed value', $value->getValue(), 'typed: initial value');
|
||||
$this->assertEquals('http://vocab.com/type/datatype', $value->getType(), 'typed: initial value type');
|
||||
|
||||
$sameTypedValue = new TypedValue('typed value', 'http://vocab.com/type/datatype');
|
||||
$this->assertTrue($value->equals($sameTypedValue), 'typed: equals same');
|
||||
|
||||
$newTypedValue1 = new TypedValue('typed value', 'http://vocab.com/otherType');
|
||||
$this->assertFalse($value->equals($newTypedValue1), 'typed: equals new1');
|
||||
|
||||
$newTypedValue2 = new TypedValue('other typed value', 'http://vocab.com/type/datatype');
|
||||
$this->assertFalse($value->equals($newTypedValue2), 'typed: equals new2');
|
||||
|
||||
$node->addPropertyValue('http://vocab.com/typed', $sameTypedValue);
|
||||
$this->assertSame($value, $node->getProperty('http://vocab.com/typed'), 'typed: still same');
|
||||
|
||||
$node->addPropertyValue('http://vocab.com/typed', $newTypedValue1);
|
||||
$node->addPropertyValue('http://vocab.com/typed', $newTypedValue2);
|
||||
|
||||
$value = $node->getProperty('http://vocab.com/typed');
|
||||
$this->assertCount(3, $value, 'typed: count values added');
|
||||
|
||||
$this->assertTrue($sameTypedValue->equals($value[0]), 'typed: check values 1');
|
||||
$this->assertTrue($newTypedValue1->equals($value[1]), 'typed: check values 2');
|
||||
$this->assertTrue($newTypedValue2->equals($value[2]), 'typed: check values 3');
|
||||
|
||||
$node->removePropertyValue('http://vocab.com/typed', $newTypedValue1);
|
||||
$value = $node->getProperty('http://vocab.com/typed');
|
||||
$this->assertCount(2, $value, 'typed: count value 1 removed again');
|
||||
|
||||
$this->assertTrue($sameTypedValue->equals($value[0]), 'typed: check values 1 (2)');
|
||||
$this->assertTrue($newTypedValue2->equals($value[1]), 'typed: check values 2 (2)');
|
||||
|
||||
// Nodes
|
||||
$node = $this->graph->getNode('http://example.com/node/3');
|
||||
$node1 = $this->graph->getNode('http://example.com/node/1');
|
||||
|
||||
$value = $node->getProperty('http://vocab.com/link');
|
||||
|
||||
$this->assertInstanceOf('ML\JsonLD\Node', $value, 'node: initial value class');
|
||||
$this->assertSame($node1, $value, 'node: initial node');
|
||||
|
||||
$newNode1 = $this->graph->createNode();
|
||||
$this->assertTrue($this->graph->containsNode($newNode1), 'node: new1 in graph');
|
||||
|
||||
$newNode2 = $this->graph->createNode('http://example.com/node/new/2');
|
||||
$this->assertTrue($this->graph->containsNode($newNode2), 'node: new2 in graph');
|
||||
|
||||
$node->addPropertyValue('http://vocab.com/link', $node1);
|
||||
$this->assertSame($node1, $node->getProperty('http://vocab.com/link'), 'node: still same');
|
||||
|
||||
$node->addPropertyValue('http://vocab.com/link', $newNode1);
|
||||
$node->addPropertyValue('http://vocab.com/link', $newNode2);
|
||||
|
||||
$value = $node->getProperty('http://vocab.com/link');
|
||||
$this->assertCount(3, $value, 'node: count values added');
|
||||
|
||||
$this->assertSame($node1, $value[0], 'node: check values 1');
|
||||
$this->assertSame($newNode1, $value[1], 'node: check values 2');
|
||||
$this->assertSame($newNode2, $value[2], 'node: check values 3');
|
||||
|
||||
$node->removePropertyValue('http://vocab.com/link', $newNode1);
|
||||
$value = $node->getProperty('http://vocab.com/link');
|
||||
$this->assertCount(2, $value, 'typed: count new node 1 removed again');
|
||||
|
||||
$this->assertTrue($node1->equals($value[0]), 'node: check values 1 (2)');
|
||||
$this->assertTrue($newNode2->equals($value[1]), 'node: check values 2 (2)');
|
||||
|
||||
// Node types
|
||||
$node1 = $this->graph->getNode('http://example.com/node/1');
|
||||
$nodeType = $this->graph->getNode('http://vocab.com/type/node');
|
||||
$nodeWithAliasesType = $this->graph->getNode('http://vocab.com/type/nodeWithAliases');
|
||||
|
||||
$this->assertSame($nodeType, $node1->getType(), 'type: n1 initial type');
|
||||
|
||||
$newType1 = $this->graph->createNode();
|
||||
$this->assertTrue($this->graph->containsNode($newNode1), 'type: new1 in graph');
|
||||
|
||||
$node1->addType($nodeType);
|
||||
$this->assertSame($nodeType, $node1->getType(), 'type: n1 type still same');
|
||||
|
||||
$node1->addType($nodeWithAliasesType);
|
||||
$node1->addType($newType1);
|
||||
|
||||
$value = $node1->getType();
|
||||
$this->assertCount(3, $value, 'type: count values added');
|
||||
|
||||
$this->assertSame($nodeType, $value[0], 'type: check values 1');
|
||||
$this->assertSame($nodeWithAliasesType, $value[1], 'type: check values 2');
|
||||
$this->assertSame($newType1, $value[2], 'type: check values 3');
|
||||
|
||||
$node1->removeType($nodeWithAliasesType);
|
||||
$value = $node1->getType();
|
||||
$this->assertCount(2, $value, 'typed: count nodeWithAliasesType removed again');
|
||||
|
||||
$this->assertTrue($nodeType->equals($value[0]), 'type: check values 1 (2)');
|
||||
$this->assertTrue($newType1->equals($value[1]), 'type: check values 2 (2)');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether it is possible to add invalid values
|
||||
*
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testAddInvalidPropertyValue()
|
||||
{
|
||||
$graph = new Graph();
|
||||
$newNode = $graph->createNode();
|
||||
|
||||
$node1 = $this->graph->getNode('http://example.com/node/1');
|
||||
$node1->addPropertyValue('http://vocab.com/link', $newNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether it is possible to set the node's type to an invalid
|
||||
* value
|
||||
*
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testSetInvalidTypeValue()
|
||||
{
|
||||
$node1 = $this->graph->getNode('http://example.com/node/1');
|
||||
$node1->setType('http://vocab.com/type/aTypeAsString');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether it is possible to set the node's type to an invalid
|
||||
* value when an array is used.
|
||||
*
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testSetInvalidTypeArray()
|
||||
{
|
||||
$types = array(
|
||||
$this->graph->getNode('http://vocab.com/type/nodeWithAliases'),
|
||||
'http://vocab.com/type/aTypeAsString'
|
||||
);
|
||||
|
||||
$node1 = $this->graph->getNode('http://example.com/node/1');
|
||||
|
||||
$node1->setType($types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether it is possible to add an type which is not part of the
|
||||
* graph
|
||||
*
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testAddTypeNotInGraph()
|
||||
{
|
||||
$graph = new Graph();
|
||||
$newType = $graph->createNode();
|
||||
|
||||
$node1 = $this->graph->getNode('http://example.com/node/1');
|
||||
$node1->addType($newType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether nodes are contained in the graph
|
||||
*/
|
||||
public function testContains()
|
||||
{
|
||||
$node1 = $this->graph->getNode('http://example.com/node/1');
|
||||
$nodeb_0 = $this->graph->getNode('_:b0');
|
||||
|
||||
$this->assertTrue($this->graph->containsNode($node1), 'node1 obj');
|
||||
$this->assertTrue($this->graph->containsNode('http://example.com/node/1'), 'node1 IRI');
|
||||
$this->assertFalse($this->graph->containsNode('http://example.com/node/X'), 'inexistent IRI');
|
||||
$this->assertTrue($this->graph->containsNode($nodeb_0), '_:b0');
|
||||
$this->assertFalse($this->graph->containsNode('_:b0'), '_:b0 IRI');
|
||||
$this->assertFalse($this->graph->containsNode(new TypedValue('val', 'http://example.com/type')), 'typed value');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether creating an existing node returns the instance of that node
|
||||
*/
|
||||
public function testCreateExistingNode()
|
||||
{
|
||||
$node1 = $this->graph->getNode('http://example.com/node/1');
|
||||
$nodeType = $this->graph->getNode('http://vocab.com/type/node');
|
||||
|
||||
$this->assertSame($node1, $this->graph->createNode('http://example.com/node/1'));
|
||||
$this->assertSame($nodeType, $this->graph->createNode('http://vocab.com/type/node'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the merging of two graphs
|
||||
*/
|
||||
public function testMerge()
|
||||
{
|
||||
$this->markTestSkipped("Merging graphs doesn't work yet as blank nodes are not relabeled properly");
|
||||
|
||||
$json = <<<JSON_LD_DOCUMENT
|
||||
{
|
||||
"@context": {
|
||||
"ex": "http://vocab.com/",
|
||||
"node": "ex:type/node"
|
||||
},
|
||||
"@graph": [
|
||||
{
|
||||
"@id": "1",
|
||||
"@type": "ex:type/node",
|
||||
"ex:name": "1",
|
||||
"ex:link": { "@id": "./2" },
|
||||
"ex:contains": { "ex:nested": "1.1 (graph 2)" }
|
||||
},
|
||||
{
|
||||
"@id": "/node/2",
|
||||
"ex:name": "and a different name in graph 2",
|
||||
"ex:link": { "@id": "/node/4" },
|
||||
"ex:newFromGraph2": "this was added in graph 2"
|
||||
},
|
||||
{
|
||||
"@id": "http://example.com/node/4",
|
||||
"ex:name": "node 4 from graph 2"
|
||||
}
|
||||
]
|
||||
}
|
||||
JSON_LD_DOCUMENT;
|
||||
|
||||
$graph2 = Document::load($json, array('base' => 'http://example.com/node/index.jsonld'))->getGraph();
|
||||
|
||||
// Merge graph2 into graph
|
||||
$this->graph->merge($graph2);
|
||||
|
||||
$nodeIds = array(
|
||||
'http://example.com/node/1',
|
||||
'http://example.com/node/2',
|
||||
'http://example.com/node/3',
|
||||
'http://example.com/node/4',
|
||||
'_:b0',
|
||||
'_:b1',
|
||||
'_:b2',
|
||||
'_:b3',
|
||||
'_:b4',
|
||||
'http://vocab.com/type/node',
|
||||
'http://vocab.com/type/nodeWithAliases'
|
||||
);
|
||||
|
||||
$nodes = $this->graph->getNodes();
|
||||
$this->assertCount(count($nodeIds), $nodes);
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
// Is the node's ID valid?
|
||||
$this->assertContains($node->getId(), $nodeIds, 'Found unexpected node ID: ' . $node->getId());
|
||||
|
||||
// Is the node of the right type?
|
||||
$this->assertInstanceOf('ML\JsonLD\Node', $node);
|
||||
|
||||
// Does the graph return the same instance?
|
||||
$n = $this->graph->getNode($node->getId());
|
||||
$this->assertSame($node, $n, 'same instance');
|
||||
$this->assertTrue($node->equals($n), 'equals');
|
||||
$this->assertSame($this->graph, $n->getGraph(), 'linked to graph');
|
||||
|
||||
// It must not share node objects with graph 2
|
||||
$this->assertNotSame($node, $graph2->getNode($node->getId()), 'shared instance between graph and graph 2');
|
||||
}
|
||||
|
||||
// Check that the properties have been updated as well
|
||||
$node1 = $this->graph->getNode('http://example.com/node/1');
|
||||
$node2 = $this->graph->getNode('http://example.com/node/2');
|
||||
$node3 = $this->graph->getNode('http://example.com/node/3');
|
||||
$node4 = $this->graph->getNode('http://example.com/node/4');
|
||||
|
||||
$this->assertEquals(
|
||||
new TypedValue('1', RdfConstants::XSD_STRING),
|
||||
$node1->getProperty('http://vocab.com/name'),
|
||||
'n1->name'
|
||||
);
|
||||
$this->assertSame($node2, $node1->getProperty('http://vocab.com/link'), 'n1 -link-> n2');
|
||||
$this->assertCount(2, $node1->getProperty('http://vocab.com/contains'), 'n1 -contains-> 2 blank nodes');
|
||||
|
||||
$this->assertEquals(
|
||||
array(
|
||||
new TypedValue('2', RdfConstants::XSD_STRING),
|
||||
new TypedValue('and a different name in graph 2', RdfConstants::XSD_STRING)
|
||||
),
|
||||
$node2->getProperty('http://vocab.com/name'),
|
||||
'n2->name'
|
||||
);
|
||||
|
||||
$this->assertSame(array($node3, $node4), $node2->getProperty('http://vocab.com/link'), 'n2 -link-> n3 & n4');
|
||||
$this->assertEquals(
|
||||
new TypedValue('this was added in graph 2', RdfConstants::XSD_STRING),
|
||||
$node2->getProperty('http://vocab.com/newFromGraph2'),
|
||||
'n2->newFromGraph2'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
new TypedValue('node 4 from graph 2', RdfConstants::XSD_STRING),
|
||||
$node4->getProperty('http://vocab.com/name'),
|
||||
'n4->name'
|
||||
);
|
||||
|
||||
// Verify that graph 2 wasn't changed
|
||||
$nodeIds = array(
|
||||
'http://example.com/node/1',
|
||||
'http://example.com/node/2',
|
||||
'_:b0', // ex:contains: { ex:nested }
|
||||
'http://example.com/node/4',
|
||||
'http://vocab.com/type/node'
|
||||
);
|
||||
|
||||
$nodes = $graph2->getNodes();
|
||||
$this->assertCount(count($nodeIds), $nodes);
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
// Is the node's ID valid?
|
||||
$this->assertContains($node->getId(), $nodeIds, 'Found unexpected node ID in graph 2: ' . $node->getId());
|
||||
|
||||
// Is the node of the right type?
|
||||
$this->assertInstanceOf('ML\JsonLD\Node', $node);
|
||||
|
||||
// Does the graph return the same instance?
|
||||
$n = $graph2->getNode($node->getId());
|
||||
$this->assertSame($node, $n, 'same instance (graph 2)');
|
||||
$this->assertTrue($node->equals($n), 'equals (graph 2)');
|
||||
$this->assertSame($graph2, $n->getGraph(), 'linked to graph (graph 2)');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the serialization of nodes
|
||||
*/
|
||||
public function testSerializeNode()
|
||||
{
|
||||
$expected = $this->documentLoader->loadDocument(
|
||||
'{
|
||||
"@id": "http://example.com/node/1",
|
||||
"@type": [ "http://vocab.com/type/node" ],
|
||||
"http://vocab.com/name": [ { "@value": "1" } ],
|
||||
"http://vocab.com/link": [ { "@id": "http://example.com/node/2" } ],
|
||||
"http://vocab.com/contains": [ { "@id": "_:b0" } ]
|
||||
}'
|
||||
);
|
||||
$expected = $expected->document;
|
||||
|
||||
$node1 = $this->graph->getNode('http://example.com/node/1');
|
||||
$this->assertEquals($expected, $node1->toJsonLd(), 'Serialize node 1');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the serialization of graphs
|
||||
*/
|
||||
public function testSerializeGraph()
|
||||
{
|
||||
// This is the expanded and flattened version of the test document
|
||||
// (the blank node labels have been renamed from _:t... to _:b...)
|
||||
$expected = $this->documentLoader->loadDocument(
|
||||
'[{
|
||||
"@id": "_:b0",
|
||||
"http://vocab.com/nested": [{
|
||||
"@value": "1.1"
|
||||
}]
|
||||
}, {
|
||||
"@id": "_:b1",
|
||||
"http://vocab.com/nested": [{
|
||||
"@value": "2.1"
|
||||
}]
|
||||
}, {
|
||||
"@id": "_:b2",
|
||||
"http://vocab.com/nested": [{
|
||||
"@value": "2.2"
|
||||
}]
|
||||
}, {
|
||||
"@id": "_:b3",
|
||||
"http://vocab.com/nested": [{
|
||||
"@value": "3.1"
|
||||
}]
|
||||
}, {
|
||||
"@id": "http://example.com/node/1",
|
||||
"@type": ["http://vocab.com/type/node"],
|
||||
"http://vocab.com/contains": [{
|
||||
"@id": "_:b0"
|
||||
}],
|
||||
"http://vocab.com/link": [{
|
||||
"@id": "http://example.com/node/2"
|
||||
}],
|
||||
"http://vocab.com/name": [{
|
||||
"@value": "1"
|
||||
}]
|
||||
}, {
|
||||
"@id": "http://example.com/node/2",
|
||||
"@type": ["http://vocab.com/type/nodeWithAliases"],
|
||||
"http://vocab.com/aliases": [{
|
||||
"@value": "node2"
|
||||
}, {
|
||||
"@value": 2,
|
||||
"@type": "http://www.w3.org/2001/XMLSchema#integer"
|
||||
}],
|
||||
"http://vocab.com/contains": [{
|
||||
"@id": "_:b1"
|
||||
}, {
|
||||
"@id": "_:b2"
|
||||
}],
|
||||
"http://vocab.com/lang": [{
|
||||
"@language": "en",
|
||||
"@value": "language-tagged string"
|
||||
}],
|
||||
"http://vocab.com/link": [{
|
||||
"@id": "http://example.com/node/3"
|
||||
}],
|
||||
"http://vocab.com/name": [{
|
||||
"@value": "2"
|
||||
}],
|
||||
"http://vocab.com/typed": [{
|
||||
"@type": "http://vocab.com/type/datatype",
|
||||
"@value": "typed value"
|
||||
}]
|
||||
}, {
|
||||
"@id": "http://example.com/node/3",
|
||||
"@type": ["http://vocab.com/type/node"],
|
||||
"http://vocab.com/contains": [{
|
||||
"@id": "_:b3"
|
||||
}],
|
||||
"http://vocab.com/lang": [{
|
||||
"@language": "en",
|
||||
"@value": "language-tagged string: en"
|
||||
}, {
|
||||
"@language": "de",
|
||||
"@value": "language-tagged string: de"
|
||||
}],
|
||||
"http://vocab.com/link": [{
|
||||
"@id": "http://example.com/node/1"
|
||||
}],
|
||||
"http://vocab.com/name": [{
|
||||
"@value": "3"
|
||||
}],
|
||||
"http://vocab.com/typed": [{
|
||||
"@type": "http://vocab.com/type/datatype",
|
||||
"@value": "typed value"
|
||||
}, {
|
||||
"@language": "ex:/type/otherDataType",
|
||||
"@value": "typed value"
|
||||
}, {
|
||||
"@language": "ex:/type/datatype",
|
||||
"@value": "typed value"
|
||||
}]
|
||||
}, {
|
||||
"@id": "http://vocab.com/type/node"
|
||||
}, {
|
||||
"@id": "http://vocab.com/type/nodeWithAliases"
|
||||
}]'
|
||||
);
|
||||
$expected = $expected->document;
|
||||
|
||||
$this->assertEquals($expected, $this->graph->toJsonLd(false), 'Serialize graph');
|
||||
}
|
||||
}
|
||||
132
vendor/ml/json-ld/Test/JsonLDApiTest.php
vendored
Normal file
132
vendor/ml/json-ld/Test/JsonLDApiTest.php
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* (c) Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace ML\JsonLD\Test;
|
||||
|
||||
use ML\JsonLD\JsonLD;
|
||||
|
||||
/**
|
||||
* Tests JsonLD's API
|
||||
*
|
||||
* @author Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*/
|
||||
class JsonLDApiTest extends JsonTestCase
|
||||
{
|
||||
/**
|
||||
* Tests the expansion API
|
||||
*
|
||||
* @group expansion
|
||||
*/
|
||||
public function testExpansion()
|
||||
{
|
||||
$path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR;
|
||||
$expected = json_decode(file_get_contents($path . 'sample-expanded.jsonld'));
|
||||
|
||||
$input = $path . 'sample-in.jsonld';
|
||||
$this->assertJsonEquals($expected, JsonLD::expand($input), 'Passing the file path');
|
||||
|
||||
$input = file_get_contents($input);
|
||||
$this->assertJsonEquals($expected, JsonLD::expand($input), 'Passing the raw input (string)');
|
||||
|
||||
$input = json_decode($input);
|
||||
$this->assertJsonEquals($expected, JsonLD::expand($input), 'Passing the parsed object');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the compaction API
|
||||
*
|
||||
* @group compaction
|
||||
*/
|
||||
public function testCompaction()
|
||||
{
|
||||
$path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR;
|
||||
$expected = json_decode(file_get_contents($path . 'sample-compacted.jsonld'));
|
||||
|
||||
$input = $path . 'sample-in.jsonld';
|
||||
$context = $path . 'sample-context.jsonld';
|
||||
$this->assertJsonEquals($expected, JsonLD::compact($input, $context), 'Passing the file path');
|
||||
|
||||
$input = file_get_contents($input);
|
||||
$context = file_get_contents($context);
|
||||
$this->assertJsonEquals($expected, JsonLD::compact($input, $context), 'Passing the raw input (string)');
|
||||
|
||||
$input = json_decode($input);
|
||||
$context = json_decode($context);
|
||||
$this->assertJsonEquals($expected, JsonLD::compact($input, $context), 'Passing the parsed object');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the flattening API
|
||||
*
|
||||
* @group flattening
|
||||
*/
|
||||
public function testFlatten()
|
||||
{
|
||||
$path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR;
|
||||
$expected = json_decode(file_get_contents($path . 'sample-flattened.jsonld'));
|
||||
|
||||
$input = $path . 'sample-in.jsonld';
|
||||
$context = $path . 'sample-context.jsonld';
|
||||
$this->assertJsonEquals($expected, JsonLD::flatten($input, $context), 'Passing the file path');
|
||||
|
||||
$input = file_get_contents($input);
|
||||
$context = file_get_contents($context);
|
||||
$this->assertJsonEquals($expected, JsonLD::flatten($input, $context), 'Passing the raw input (string)');
|
||||
|
||||
$input = json_decode($input);
|
||||
$context = json_decode($context);
|
||||
$this->assertJsonEquals($expected, JsonLD::flatten($input, $context), 'Passing the parsed object');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the framing API
|
||||
*
|
||||
* This test intentionally uses the same fixtures as the flattening tests.
|
||||
*
|
||||
* @group framing
|
||||
*/
|
||||
public function testFrame()
|
||||
{
|
||||
$path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR;
|
||||
$expected = json_decode(file_get_contents($path . 'sample-flattened.jsonld'));
|
||||
|
||||
$input = $path . 'sample-in.jsonld';
|
||||
$context = $path . 'sample-context.jsonld';
|
||||
$this->assertJsonEquals($expected, JsonLD::frame($input, $context), 'Passing the file path');
|
||||
|
||||
$input = file_get_contents($input);
|
||||
$context = file_get_contents($context);
|
||||
$this->assertJsonEquals($expected, JsonLD::frame($input, $context), 'Passing the raw input (string)');
|
||||
|
||||
$input = json_decode($input);
|
||||
$context = json_decode($context);
|
||||
$this->assertJsonEquals($expected, JsonLD::frame($input, $context), 'Passing the parsed object');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the document API
|
||||
*
|
||||
* This test intentionally uses the same fixtures as the flattening tests.
|
||||
*/
|
||||
public function testGetDocument()
|
||||
{
|
||||
|
||||
$path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR;
|
||||
$expected = json_decode(file_get_contents($path . 'sample-serialized-document.jsonld'));
|
||||
|
||||
$input = $path . 'sample-in.jsonld';
|
||||
$this->assertJsonEquals($expected, JsonLD::getDocument($input)->toJsonLd(), 'Passing the file path');
|
||||
|
||||
$input = file_get_contents($input);
|
||||
$this->assertJsonEquals($expected, JsonLD::getDocument($input)->toJsonLd(), 'Passing the raw input (string)');
|
||||
|
||||
$input = json_decode($input);
|
||||
$this->assertJsonEquals($expected, JsonLD::getDocument($input)->toJsonLd(), 'Passing the parsed object');
|
||||
}
|
||||
}
|
||||
64
vendor/ml/json-ld/Test/JsonTestCase.php
vendored
Normal file
64
vendor/ml/json-ld/Test/JsonTestCase.php
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* (c) Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace ML\JsonLD\Test;
|
||||
|
||||
/**
|
||||
* A JSON Test Case
|
||||
*
|
||||
* This class extends {@link \PHPUnit_Framework_TestCase} with an assertion
|
||||
* to compare JSON.
|
||||
*
|
||||
* @author Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*/
|
||||
abstract class JsonTestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Asserts that two JSON structures are equal.
|
||||
*
|
||||
* @param object|array $expected
|
||||
* @param object|array $actual
|
||||
* @param string $message
|
||||
*/
|
||||
public static function assertJsonEquals($expected, $actual, $message = '')
|
||||
{
|
||||
$expected = self::normalizeJson($expected);
|
||||
$actual = self::normalizeJson($actual);
|
||||
|
||||
self::assertEquals($expected, $actual, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Brings the keys of objects to a deterministic order to enable
|
||||
* comparison of JSON structures
|
||||
*
|
||||
* @param mixed $element The element to normalize.
|
||||
*
|
||||
* @return mixed The same data with all object keys ordered in a
|
||||
* deterministic way.
|
||||
*/
|
||||
private static function normalizeJson($element)
|
||||
{
|
||||
if (is_array($element)) {
|
||||
foreach ($element as &$item) {
|
||||
$item = self::normalizeJson($item);
|
||||
}
|
||||
} elseif (is_object($element)) {
|
||||
$element = (array) $element;
|
||||
ksort($element);
|
||||
$element = (object) $element;
|
||||
|
||||
foreach ($element as &$item) {
|
||||
$item = self::normalizeJson($item);
|
||||
}
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
106
vendor/ml/json-ld/Test/NQuadsTest.php
vendored
Normal file
106
vendor/ml/json-ld/Test/NQuadsTest.php
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* (c) Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace ML\JsonLD\Test;
|
||||
|
||||
use ML\JsonLD\JsonLD;
|
||||
use ML\JsonLD\NQuads;
|
||||
|
||||
/**
|
||||
* Tests NQuads
|
||||
*
|
||||
* @author Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*/
|
||||
class NQuadsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Tests that parsing an invalid NQuad file fails
|
||||
*
|
||||
* @expectedException \ML\JsonLD\Exception\InvalidQuadException
|
||||
*/
|
||||
public function testInvalidParse()
|
||||
{
|
||||
$nquads = new NQuads();
|
||||
$nquads->parse('Invalid NQuads file');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests escaping
|
||||
*/
|
||||
public function testEscaping()
|
||||
{
|
||||
$doc = '<http://example.com>';
|
||||
$doc .= ' <http://schema.org/description>';
|
||||
$doc .= ' "String with line-break \n and quote (\")" .';
|
||||
$doc .= "\n";
|
||||
|
||||
$nquads = new NQuads();
|
||||
$parsed = JsonLD::fromRdf($nquads->parse($doc));
|
||||
$serialized = $nquads->serialize(JsonLD::toRdf($parsed));
|
||||
|
||||
$this->assertSame($doc, $serialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests blank node label parsing
|
||||
*/
|
||||
public function testParseBlankNodes()
|
||||
{
|
||||
$nquads = new NQuads();
|
||||
|
||||
$this->assertNotEmpty($nquads->parse('_:b <http://ex/1> "Test" .'), 'just a letter');
|
||||
|
||||
$this->assertNotEmpty($nquads->parse('_:b1 <http://ex/1> "Test" .'), 'letter and number');
|
||||
|
||||
$this->assertNotEmpty($nquads->parse('_:_b1 <http://ex/1> "Test" .'), 'beginning _');
|
||||
|
||||
$this->assertNotEmpty($nquads->parse('_:b_1 <http://ex/1> "Test" .'), 'containing _');
|
||||
|
||||
$this->assertNotEmpty($nquads->parse('_:b1_ <http://ex/1> "Test" .'), 'ending _');
|
||||
|
||||
$this->assertNotEmpty($nquads->parse('_:b-1 <http://ex/1> "Test" .'), 'containing -');
|
||||
|
||||
$this->assertNotEmpty($nquads->parse('_:b-1 <http://ex/1> "Test" .'), 'ending -');
|
||||
|
||||
$this->assertNotEmpty($nquads->parse('_:b.1 <http://ex/1> "Test" .'), 'containing .');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that parsing fails for blank node labels beginning with "-"
|
||||
*
|
||||
* @expectedException \ML\JsonLD\Exception\InvalidQuadException
|
||||
*/
|
||||
public function testParseBlankNodeDashAtTheBeginning()
|
||||
{
|
||||
$nquads = new NQuads();
|
||||
$nquads->parse('_:-b1 <http://ex/1> "Test" .');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that parsing fails for blank node labels beginning with "."
|
||||
*
|
||||
* @expectedException \ML\JsonLD\Exception\InvalidQuadException
|
||||
*/
|
||||
public function testParseBlankNodePeriodAtTheBeginning()
|
||||
{
|
||||
$nquads = new NQuads();
|
||||
$nquads->parse('_:.b1 <http://ex/1> "Test" .');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that parsing fails for blank node labels ending with "."
|
||||
*
|
||||
* @expectedException \ML\JsonLD\Exception\InvalidQuadException
|
||||
*/
|
||||
public function testParseBlankNodePeriodAtTheEnd()
|
||||
{
|
||||
$nquads = new NQuads();
|
||||
$nquads->parse('_:b1. <http://ex/1> "Test" .');
|
||||
}
|
||||
}
|
||||
120
vendor/ml/json-ld/Test/TestManifestIterator.php
vendored
Normal file
120
vendor/ml/json-ld/Test/TestManifestIterator.php
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* (c) Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace ML\JsonLD\Test;
|
||||
|
||||
/**
|
||||
* TestManifestIterator reads a test manifest and returns the contained test
|
||||
* definitions.
|
||||
*
|
||||
* @author Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*/
|
||||
class TestManifestIterator implements \Iterator
|
||||
{
|
||||
/** The current position. */
|
||||
private $key = 0;
|
||||
|
||||
/** The test directory. */
|
||||
private $directory;
|
||||
|
||||
/** The test manifest. */
|
||||
private $manifest;
|
||||
|
||||
/** The URL of the test manifest. */
|
||||
private $url;
|
||||
|
||||
/** The total number of tests. */
|
||||
private $numberTests = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $file The manifest's filename.
|
||||
* @param string $url The manifest's URL.
|
||||
*/
|
||||
public function __construct($file, $url)
|
||||
{
|
||||
if (file_exists($file)) {
|
||||
$this->manifest = json_decode(file_get_contents($file));
|
||||
$this->numberTests = count($this->manifest->{'sequence'});
|
||||
$this->url = $url;
|
||||
$this->directory = dirname($file) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewinds the TestManifestIterator to the first element.
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
$this->key = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if current position is valid.
|
||||
*
|
||||
* @return bool True if the current position is valid; otherwise, false.
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
return ($this->key < $this->numberTests);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key of the current element.
|
||||
*
|
||||
* @return string The key of the current element
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return $this->url . $this->manifest->{'sequence'}[$this->key]->{'@id'};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current element.
|
||||
*
|
||||
* @return array Returns an array containing the name of the test and the
|
||||
* test definition object.
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
$test = $this->manifest->{'sequence'}[$this->key];
|
||||
$options = isset($test->{'option'})
|
||||
? clone $test->{'option'} // cloning because we are modifying it
|
||||
: new \stdClass();
|
||||
|
||||
if (false === property_exists($options, 'base')) {
|
||||
if (property_exists($this->manifest, 'baseIri')) {
|
||||
$options->base = $this->manifest->{'baseIri'} . $test->{'input'};
|
||||
} else {
|
||||
$options->base = $test->{'input'};
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options->{'expandContext'}) && (false === strpos($options->{'expandContext'}, ':'))) {
|
||||
$options->{'expandContext'} = $this->directory . $options->{'expandContext'};
|
||||
}
|
||||
|
||||
$test = array(
|
||||
'name' => $test->{'name'},
|
||||
'test' => $test,
|
||||
'options' => $options
|
||||
);
|
||||
|
||||
return $test;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves forward to next element.
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
$this->key++;
|
||||
}
|
||||
}
|
||||
138
vendor/ml/json-ld/Test/ValueTest.php
vendored
Normal file
138
vendor/ml/json-ld/Test/ValueTest.php
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* (c) Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace ML\JsonLD\Test;
|
||||
|
||||
use ML\JsonLD\LanguageTaggedString;
|
||||
use ML\JsonLD\TypedValue;
|
||||
|
||||
/**
|
||||
* Test LanguageTaggedString and TypedValue
|
||||
*
|
||||
* @author Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*/
|
||||
class ValueTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Tests LanguageTaggedString
|
||||
*/
|
||||
public function testLanguageTaggedString()
|
||||
{
|
||||
$string1 = new LanguageTaggedString('', '');
|
||||
$this->assertSame('', $string1->getValue(), 'string1 value');
|
||||
$this->assertSame('', $string1->getLanguage(), 'string1 language');
|
||||
|
||||
$string2 = new LanguageTaggedString('wert', 'de');
|
||||
$this->assertSame('wert', $string2->getValue(), 'string2 value');
|
||||
$this->assertSame('de', $string2->getLanguage(), 'string2 language');
|
||||
|
||||
$string3 = new LanguageTaggedString('value', 'en');
|
||||
$this->assertSame('value', $string3->getValue(), 'string3 value');
|
||||
$this->assertSame('en', $string3->getLanguage(), 'string3 language');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests LanguageTaggedString with an invalid value
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testLanguageTaggedStringInvalidValue()
|
||||
{
|
||||
$string1 = new LanguageTaggedString('value', 'language');
|
||||
$string1->setValue(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests LanguageTaggedString with an invalid language
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testLanguageTaggedStringInvalidLanguage()
|
||||
{
|
||||
$string1 = new LanguageTaggedString('value', 'language');
|
||||
$string1->setLanguage(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests TypedValue
|
||||
*/
|
||||
public function testTypedValue()
|
||||
{
|
||||
$value1 = new TypedValue('', '');
|
||||
$this->assertSame('', $value1->getValue(), 'string1 value');
|
||||
$this->assertSame('', $value1->getType(), 'string1 type');
|
||||
|
||||
$value2 = new TypedValue('wert', 'http://example.com/type1');
|
||||
$this->assertSame('wert', $value2->getValue(), 'string2 value');
|
||||
$this->assertSame('http://example.com/type1', $value2->getType(), 'string2 type');
|
||||
|
||||
$value3 = new TypedValue('value', 'http://example.com/type2');
|
||||
$this->assertSame('value', $value3->getValue(), 'string3 value');
|
||||
$this->assertSame('http://example.com/type2', $value3->getType(), 'string3 type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests TypedValue with an invalid value
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testTypedValueInvalidValue()
|
||||
{
|
||||
$value1 = new LanguageTaggedString('value', 'language');
|
||||
$value1->setValue(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests TypedValue with an invalid type
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testTypedValueInvalidLanguage()
|
||||
{
|
||||
$value1 = new TypedValue('value', 'http://example.com/type');
|
||||
$value1->setType(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests TypedValue with an invalid type
|
||||
*/
|
||||
public function testEquals()
|
||||
{
|
||||
$string1a = new LanguageTaggedString('value', 'en');
|
||||
$string1b = new LanguageTaggedString('value', 'en');
|
||||
$string2 = new LanguageTaggedString('value', 'de');
|
||||
$string3 = new LanguageTaggedString('wert', 'en');
|
||||
|
||||
$this->assertTrue($string1a->equals($string1b), 's1a == s1b?');
|
||||
$this->assertFalse($string1a->equals($string2), 's1a == s2?');
|
||||
$this->assertFalse($string1a->equals($string3), 's1a == s3?');
|
||||
$this->assertFalse($string1b->equals($string2), 's1b == s2?');
|
||||
$this->assertFalse($string1b->equals($string3), 's1b == s3?');
|
||||
$this->assertFalse($string2->equals($string3), 's2 == s3?');
|
||||
|
||||
|
||||
$typed1a = new TypedValue('value', 'http://example.com/type1');
|
||||
$typed1b = new TypedValue('value', 'http://example.com/type1');
|
||||
$typed2 = new TypedValue('value', 'http://example.com/type2');
|
||||
$typed3 = new TypedValue('wert', 'http://example.com/type1');
|
||||
|
||||
$this->assertTrue($typed1a->equals($typed1b), 't1a == t1b?');
|
||||
$this->assertFalse($typed1a->equals($typed2), 't1a == t2?');
|
||||
$this->assertFalse($typed1a->equals($typed3), 't1a == t3?');
|
||||
$this->assertFalse($typed1b->equals($typed2), 't1b == t2?');
|
||||
$this->assertFalse($typed1b->equals($typed3), 't1b == t3?');
|
||||
$this->assertFalse($typed2->equals($typed3), 't2 == t3?');
|
||||
|
||||
$string4 = new LanguageTaggedString('', '');
|
||||
$typed4 = new TypedValue('', '');
|
||||
|
||||
$this->assertFalse($string4->equals($typed4), 's4 == t4');
|
||||
$this->assertFalse($typed4->equals($string4), 's4 == t4');
|
||||
}
|
||||
}
|
||||
368
vendor/ml/json-ld/Test/W3CTestSuiteTest.php
vendored
Normal file
368
vendor/ml/json-ld/Test/W3CTestSuiteTest.php
vendored
Normal file
@@ -0,0 +1,368 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* (c) Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace ML\JsonLD\Test;
|
||||
|
||||
use ML\JsonLD\JsonLD;
|
||||
use ML\JsonLD\NQuads;
|
||||
use ML\JsonLD\Test\TestManifestIterator;
|
||||
|
||||
/**
|
||||
* The official W3C JSON-LD test suite.
|
||||
*
|
||||
* @link http://www.w3.org/2013/json-ld-tests/ Official W3C JSON-LD test suite
|
||||
*
|
||||
* @author Markus Lanthaler <mail@markus-lanthaler.com>
|
||||
*/
|
||||
class W3CTestSuiteTest extends JsonTestCase
|
||||
{
|
||||
/**
|
||||
* The base directory from which the test manifests, input, and output
|
||||
* files should be read.
|
||||
*/
|
||||
private $basedir;
|
||||
|
||||
/**
|
||||
* The URL corresponding to the base directory
|
||||
*/
|
||||
private $baseurl = 'http://json-ld.org/test-suite/tests/';
|
||||
|
||||
/**
|
||||
* @var string The test's ID.
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* Constructs a test case with the given name.
|
||||
*
|
||||
* @param null|string $name
|
||||
* @param array $data
|
||||
* @param string $dataName
|
||||
*/
|
||||
public function __construct($name = null, array $data = array(), $dataName = '')
|
||||
{
|
||||
$this->id = $dataName;
|
||||
|
||||
parent::__construct($name, $data, $dataName);
|
||||
$this->basedir = dirname(__FILE__) . '/../vendor/json-ld/tests/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the test identifier.
|
||||
*
|
||||
* @return string The test identifier
|
||||
*/
|
||||
public function getTestId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests expansion.
|
||||
*
|
||||
* @param string $name The test name.
|
||||
* @param object $test The test definition.
|
||||
* @param object $options The options to configure the algorithms.
|
||||
*
|
||||
* @group expansion
|
||||
* @dataProvider expansionProvider
|
||||
*/
|
||||
public function testExpansion($name, $test, $options)
|
||||
{
|
||||
$expected = json_decode(file_get_contents($this->basedir . $test->{'expect'}));
|
||||
$result = JsonLD::expand($this->basedir . $test->{'input'}, $options);
|
||||
|
||||
$this->assertJsonEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides expansion test cases.
|
||||
*/
|
||||
public function expansionProvider()
|
||||
{
|
||||
return new TestManifestIterator(
|
||||
$this->basedir . 'expand-manifest.jsonld',
|
||||
$this->baseurl . 'expand-manifest.jsonld'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests compaction.
|
||||
*
|
||||
* @param string $name The test name.
|
||||
* @param object $test The test definition.
|
||||
* @param object $options The options to configure the algorithms.
|
||||
*
|
||||
* @group compaction
|
||||
* @dataProvider compactionProvider
|
||||
*/
|
||||
public function testCompaction($name, $test, $options)
|
||||
{
|
||||
$expected = json_decode(file_get_contents($this->basedir . $test->{'expect'}));
|
||||
$result = JsonLD::compact(
|
||||
$this->basedir . $test->{'input'},
|
||||
$this->basedir . $test->{'context'},
|
||||
$options
|
||||
);
|
||||
|
||||
$this->assertJsonEquals($expected, $result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Provides compaction test cases.
|
||||
*/
|
||||
public function compactionProvider()
|
||||
{
|
||||
return new TestManifestIterator(
|
||||
$this->basedir . 'compact-manifest.jsonld',
|
||||
$this->baseurl . 'compact-manifest.jsonld'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests flattening.
|
||||
*
|
||||
* @param string $name The test name.
|
||||
* @param object $test The test definition.
|
||||
* @param object $options The options to configure the algorithms.
|
||||
*
|
||||
* @group flattening
|
||||
* @dataProvider flattenProvider
|
||||
*/
|
||||
public function testFlatten($name, $test, $options)
|
||||
{
|
||||
$expected = json_decode(file_get_contents($this->basedir . $test->{'expect'}));
|
||||
$context = (isset($test->{'context'}))
|
||||
? $this->basedir . $test->{'context'}
|
||||
: null;
|
||||
|
||||
$result = JsonLD::flatten($this->basedir . $test->{'input'}, $context, $options);
|
||||
|
||||
$this->assertJsonEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides flattening test cases.
|
||||
*/
|
||||
public function flattenProvider()
|
||||
{
|
||||
return new TestManifestIterator(
|
||||
$this->basedir . 'flatten-manifest.jsonld',
|
||||
$this->baseurl . 'flatten-manifest.jsonld'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests remote document loading.
|
||||
*
|
||||
* @param string $name The test name.
|
||||
* @param object $test The test definition.
|
||||
* @param object $options The options to configure the algorithms.
|
||||
*
|
||||
* @group remote
|
||||
* @dataProvider remoteDocumentLoadingProvider
|
||||
*/
|
||||
public function testRemoteDocumentLoading($name, $test, $options)
|
||||
{
|
||||
if (in_array('jld:NegativeEvaluationTest', $test->{'@type'})) {
|
||||
$this->setExpectedException('ML\JsonLD\Exception\JsonLdException', null, $test->{'expect'});
|
||||
} else {
|
||||
$expected = json_decode($this->replaceBaseUrl(file_get_contents($this->basedir . $test->{'expect'})));
|
||||
}
|
||||
|
||||
unset($options->base);
|
||||
|
||||
$result = JsonLD::expand($this->replaceBaseUrl($this->baseurl . $test->{'input'}), $options);
|
||||
|
||||
if (isset($expected)) {
|
||||
$this->assertJsonEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides remote document loading test cases.
|
||||
*/
|
||||
public function remoteDocumentLoadingProvider()
|
||||
{
|
||||
return new TestManifestIterator(
|
||||
$this->basedir . 'remote-doc-manifest.jsonld',
|
||||
$this->baseurl . 'remote-doc-manifest.jsonld'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the base URL 'http://json-ld.org/' with 'https://json-ld.org:443/'.
|
||||
*
|
||||
* The test location of the test suite has been changed as the site has been
|
||||
* updated to use HTTPS everywhere.
|
||||
*
|
||||
* @param string $input The input string.
|
||||
*
|
||||
* @return string The input string with all occurrences of the old base URL replaced with the new HTTPS-based one.
|
||||
*/
|
||||
private function replaceBaseUrl($input) {
|
||||
return str_replace('http://json-ld.org/', 'https://json-ld.org:443/', $input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests errors (uses flattening).
|
||||
*
|
||||
* @param string $name The test name.
|
||||
* @param object $test The test definition.
|
||||
* @param object $options The options to configure the algorithms.
|
||||
*
|
||||
* @group errors
|
||||
* @dataProvider errorProvider
|
||||
*/
|
||||
public function testError($name, $test, $options)
|
||||
{
|
||||
$this->setExpectedException('ML\JsonLD\Exception\JsonLdException', null, $test->{'expect'});
|
||||
|
||||
JsonLD::flatten(
|
||||
$this->basedir . $test->{'input'},
|
||||
(isset($test->{'context'})) ? $this->basedir . $test->{'context'} : null,
|
||||
$options
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides error test cases.
|
||||
*/
|
||||
public function errorProvider()
|
||||
{
|
||||
return new TestManifestIterator(
|
||||
$this->basedir . 'error-manifest.jsonld',
|
||||
$this->baseurl . 'error-manifest.jsonld'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests framing.
|
||||
*
|
||||
* @param string $name The test name.
|
||||
* @param object $test The test definition.
|
||||
* @param object $options The options to configure the algorithms.
|
||||
*
|
||||
* @group framing
|
||||
* @dataProvider framingProvider
|
||||
*/
|
||||
public function testFraming($name, $test, $options)
|
||||
{
|
||||
$ignoredTests = array(
|
||||
'frame-0005-in.jsonld',
|
||||
'frame-0009-in.jsonld',
|
||||
'frame-0010-in.jsonld',
|
||||
'frame-0012-in.jsonld',
|
||||
'frame-0013-in.jsonld',
|
||||
'frame-0023-in.jsonld',
|
||||
'frame-0024-in.jsonld',
|
||||
'frame-0027-in.jsonld',
|
||||
'frame-0028-in.jsonld',
|
||||
'frame-0029-in.jsonld',
|
||||
'frame-0030-in.jsonld'
|
||||
);
|
||||
|
||||
if (in_array($test->{'input'}, $ignoredTests)) {
|
||||
$this->markTestSkipped(
|
||||
'This implementation uses deep value matching and aggressive re-embedding. See ISSUE-110 and ISSUE-119.'
|
||||
);
|
||||
}
|
||||
|
||||
$expected = json_decode(file_get_contents($this->basedir . $test->{'expect'}));
|
||||
$result = JsonLD::frame(
|
||||
$this->basedir . $test->{'input'},
|
||||
$this->basedir . $test->{'frame'},
|
||||
$options
|
||||
);
|
||||
|
||||
$this->assertJsonEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides framing test cases.
|
||||
*/
|
||||
public function framingProvider()
|
||||
{
|
||||
return new TestManifestIterator(
|
||||
$this->basedir . 'frame-manifest.jsonld',
|
||||
$this->baseurl . 'frame-manifest.jsonld'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests conversion to RDF quads.
|
||||
*
|
||||
* @param string $name The test name.
|
||||
* @param object $test The test definition.
|
||||
* @param object $options The options to configure the algorithms.
|
||||
*
|
||||
* @group toRdf
|
||||
* @dataProvider toRdfProvider
|
||||
*/
|
||||
public function testToRdf($name, $test, $options)
|
||||
{
|
||||
$expected = trim(file_get_contents($this->basedir . $test->{'expect'}));
|
||||
$quads = JsonLD::toRdf($this->basedir . $test->{'input'}, $options);
|
||||
|
||||
$serializer = new NQuads();
|
||||
$result = $serializer->serialize($quads);
|
||||
|
||||
// Sort quads (the expected quads are already sorted)
|
||||
$result = explode("\n", trim($result));
|
||||
sort($result);
|
||||
$result = implode("\n", $result);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides conversion to RDF quads test cases.
|
||||
*/
|
||||
public function toRdfProvider()
|
||||
{
|
||||
return new TestManifestIterator(
|
||||
$this->basedir . 'toRdf-manifest.jsonld',
|
||||
$this->baseurl . 'toRdf-manifest.jsonld'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests conversion from quads.
|
||||
*
|
||||
* @param string $name The test name.
|
||||
* @param object $test The test definition.
|
||||
* @param object $options The options to configure the algorithms.
|
||||
*
|
||||
* @group fromRdf
|
||||
* @dataProvider fromRdfProvider
|
||||
*/
|
||||
public function testFromRdf($name, $test, $options)
|
||||
{
|
||||
$expected = json_decode(file_get_contents($this->basedir . $test->{'expect'}));
|
||||
|
||||
$parser = new NQuads();
|
||||
$quads = $parser->parse(file_get_contents($this->basedir . $test->{'input'}));
|
||||
|
||||
$result = JsonLD::fromRdf($quads, $options);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides conversion to quads test cases.
|
||||
*/
|
||||
public function fromRdfProvider()
|
||||
{
|
||||
return new TestManifestIterator(
|
||||
$this->basedir . 'fromRdf-manifest.jsonld',
|
||||
$this->baseurl . 'fromRdf-manifest.jsonld'
|
||||
);
|
||||
}
|
||||
}
|
||||
19
vendor/ml/json-ld/Test/bootstrap.php
vendored
Normal file
19
vendor/ml/json-ld/Test/bootstrap.php
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
if (!@include(__DIR__ . '/../vendor/autoload.php')) {
|
||||
spl_autoload_register(
|
||||
function ($class) {
|
||||
if (0 === strpos($class, 'ML\\JsonLD\\')) {
|
||||
$path = implode('/', array_slice(explode('\\', $class), 2)) . '.php';
|
||||
require_once __DIR__ . '/../' . $path;
|
||||
|
||||
return true;
|
||||
} elseif (0 === strpos($class, 'ML\\IRI\\')) {
|
||||
$path = implode('/', array_slice(explode('\\', $class), 2)) . '.php';
|
||||
require_once __DIR__ . '/../../IRI/' . $path;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user