Compare commits
11 Commits
0.9
...
1122b9faf5
| Author | SHA1 | Date | |
|---|---|---|---|
| 1122b9faf5 | |||
| 0cb2655494 | |||
| a9689d5a2b | |||
| 6cb8a9d603 | |||
| 4724c4988e | |||
| bb738a1d79 | |||
| fd029a79bf | |||
| 2954d9fc99 | |||
| f29af2b664 | |||
| 5584f10462 | |||
| f937f2b426 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -5,3 +5,6 @@ cache
|
|||||||
.config
|
.config
|
||||||
.local
|
.local
|
||||||
*.phar
|
*.phar
|
||||||
|
.composer
|
||||||
|
.phpunit*
|
||||||
|
.bash_history
|
||||||
152
CloudObjects/SDK/CloudObject.php
Normal file
152
CloudObjects/SDK/CloudObject.php
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
namespace CloudObjects\SDK;
|
||||||
|
|
||||||
|
use ML\IRI\IRI;
|
||||||
|
use ML\JsonLD\Node;
|
||||||
|
use CloudObjects\SDK\NodeReader;
|
||||||
|
use Webmozart\Assert\Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A CloudObject encapsulates an object node for an object stored in CloudObjects Core
|
||||||
|
* with convenience methods to access properties.
|
||||||
|
*/
|
||||||
|
class CloudObject {
|
||||||
|
|
||||||
|
private $coid;
|
||||||
|
private $node;
|
||||||
|
private $reader = null;
|
||||||
|
private $retriever = null;
|
||||||
|
|
||||||
|
public function __construct(IRI $coid, Node $node) {
|
||||||
|
Assert::eq((string)$coid, $node->getId(), "COID and Node ID must match.");
|
||||||
|
|
||||||
|
$this->coid = $coid;
|
||||||
|
$this->node = $node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify a custom NodeReader to use for this CloudObject.
|
||||||
|
* If not set, a default NodeReader will be used.
|
||||||
|
*/
|
||||||
|
public function setReader(NodeReader $reader) : self {
|
||||||
|
$this->reader = $reader;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getReader() : NodeReader {
|
||||||
|
if (!$this->reader) {
|
||||||
|
$this->reader = new NodeReader;
|
||||||
|
}
|
||||||
|
return $this->reader;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify an ObjectRetriever to use for retrieval
|
||||||
|
* of related objects.
|
||||||
|
*/
|
||||||
|
public function setObjectRetriever(ObjectRetriever $retriever) : self {
|
||||||
|
$this->retriever = $retriever;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the COID of this object.
|
||||||
|
*/
|
||||||
|
public function getCOID() : IRI {
|
||||||
|
return $this->coid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the object node encapsulated in this CloudObject.
|
||||||
|
*/
|
||||||
|
public function getAsNode() : Node {
|
||||||
|
return $this->node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a property as a string.
|
||||||
|
* If the property has multiple values, only the first is returned.
|
||||||
|
*/
|
||||||
|
public function getString($property, string $default = null) : ?string {
|
||||||
|
return $this->getReader()->getFirstValueString($this->node, $property, $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a property as an integer.
|
||||||
|
* If the property has multiple values, only the first is returned.
|
||||||
|
*/
|
||||||
|
public function getInt($property, int $default = null) : ?int {
|
||||||
|
return $this->getReader()->getFirstValueInt($this->node, $property, $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a property as a float.
|
||||||
|
* If the property has multiple values, only the first is returned.
|
||||||
|
*/
|
||||||
|
public function getFloat($property, float $default = null) : ?float {
|
||||||
|
return $this->getReader()->getFirstValueFloat($this->node, $property, $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a property as a boolean.
|
||||||
|
* If the property has multiple values, only the first is returned.
|
||||||
|
*/
|
||||||
|
public function getBool($property, bool $default = null) : ?bool {
|
||||||
|
return $this->getReader()->getFirstValueBool($this->node, $property, $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a property as an IRI.
|
||||||
|
* If the property has multiple values, only the first is returned.
|
||||||
|
*/
|
||||||
|
public function getIRI($property, IRI $default = null) : ?IRI {
|
||||||
|
return $this->getReader()->getFirstValueIRI($this->node, $property, $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a property as a Node.
|
||||||
|
* If the property has multiple values, only the first is returned.
|
||||||
|
*/
|
||||||
|
public function getNode($property, Node $default = null) : ?Node {
|
||||||
|
return $this->getReader()->getFirstValueNode($this->node, $property, $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a property and, if it's a COID, retrieve the corresponding CloudObject.
|
||||||
|
*/
|
||||||
|
public function getCloudObject($property) : ?CloudObject {
|
||||||
|
Assert::notNull($this->retriever, "No ObjectRetriever set for CloudObject. Cannot retrieve related object.");
|
||||||
|
|
||||||
|
$coid = $this->getReader()->getFirstValueIRI($this->node, $property);
|
||||||
|
|
||||||
|
if (!($coid instanceof IRI)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->retriever->getCloudObject($coid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a property and, if it's a COID, retrieve the corresponding object node.
|
||||||
|
*/
|
||||||
|
public function getObjectNode($property) : ?Node {
|
||||||
|
Assert::notNull($this->retriever, "No ObjectRetriever set for CloudObject. Cannot retrieve related object.");
|
||||||
|
|
||||||
|
$coid = $this->getReader()->getFirstValueIRI($this->node, $property);
|
||||||
|
|
||||||
|
if (!($coid instanceof IRI)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->retriever->getObjectNode($coid);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -59,7 +59,7 @@ class CryptoHelper {
|
|||||||
|
|
||||||
$this->objectRetriever = $objectRetriever;
|
$this->objectRetriever = $objectRetriever;
|
||||||
$this->namespace = isset($namespaceCoid)
|
$this->namespace = isset($namespaceCoid)
|
||||||
? $objectRetriever->getObject($namespaceCoid)
|
? $objectRetriever->getObjectNode($namespaceCoid)
|
||||||
: $objectRetriever->getAuthenticatingNamespaceObject();
|
: $objectRetriever->getAuthenticatingNamespaceObject();
|
||||||
|
|
||||||
$this->reader = new NodeReader([
|
$this->reader = new NodeReader([
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class SharedSecretAuthentication {
|
|||||||
return self::RESULT_INVALID_PASSWORD;
|
return self::RESULT_INVALID_PASSWORD;
|
||||||
|
|
||||||
// Retrieve namespace
|
// Retrieve namespace
|
||||||
$namespace = $retriever->getObject($namespaceCoid);
|
$namespace = $retriever->getObjectNode($namespaceCoid);
|
||||||
if (!isset($namespace))
|
if (!isset($namespace))
|
||||||
return self::RESULT_NAMESPACE_NOT_FOUND;
|
return self::RESULT_NAMESPACE_NOT_FOUND;
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ class SharedSecretAuthentication {
|
|||||||
return self::RESULT_INVALID_PASSWORD;
|
return self::RESULT_INVALID_PASSWORD;
|
||||||
|
|
||||||
// Retrieve namespace
|
// Retrieve namespace
|
||||||
$namespace = $this->objectRetriever->getObject($namespaceCoid);
|
$namespace = $this->objectRetriever->getObjectNode($namespaceCoid);
|
||||||
if (!isset($namespace))
|
if (!isset($namespace))
|
||||||
return self::RESULT_NAMESPACE_NOT_FOUND;
|
return self::RESULT_NAMESPACE_NOT_FOUND;
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class SchemaValidator {
|
|||||||
* @param Node $node The COID of the specification.
|
* @param Node $node The COID of the specification.
|
||||||
*/
|
*/
|
||||||
public function validateAgainstCOID($data, IRI $coid) {
|
public function validateAgainstCOID($data, IRI $coid) {
|
||||||
$object = $this->objectRetriever->getObject($coid);
|
$object = $this->objectRetriever->getObjectNode($coid);
|
||||||
Assert::true($this->reader->hasType($object, 'json:Element'),
|
Assert::true($this->reader->hasType($object, 'json:Element'),
|
||||||
"You can only validate data against JSON elements!");
|
"You can only validate data against JSON elements!");
|
||||||
$this->validateAgainstNode($data, $object);
|
$this->validateAgainstNode($data, $object);
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
|
|||||||
private $options;
|
private $options;
|
||||||
private $cache;
|
private $cache;
|
||||||
private $objects;
|
private $objects;
|
||||||
|
private $defaultReader;
|
||||||
|
|
||||||
const CO_API_URL = 'https://api.cloudobjects.net/';
|
const CO_API_URL = 'https://api.cloudobjects.net/';
|
||||||
|
|
||||||
@@ -107,6 +108,22 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
|
|||||||
$this->client = new Client($options);
|
$this->client = new Client($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a default reader for CloudObject instances.
|
||||||
|
*/
|
||||||
|
public function setDefaultReader(NodeReader $reader) : self {
|
||||||
|
$this->defaultReader = $reader;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the default reader for CloudObject instances.
|
||||||
|
*/
|
||||||
|
public function getDefaultReader() : NodeReader {
|
||||||
|
return $this->defaultReader;
|
||||||
|
}
|
||||||
|
|
||||||
public function logInfoWithTime($message, $ts) {
|
public function logInfoWithTime($message, $ts) {
|
||||||
if (isset($this->logger))
|
if (isset($this->logger))
|
||||||
$this->logger->info($message, [ 'elapsed_ms' => round((microtime(true) - $ts) * 1000) ]);
|
$this->logger->info($message, [ 'elapsed_ms' => round((microtime(true) - $ts) * 1000) ]);
|
||||||
@@ -170,15 +187,42 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an object description from CloudObjects. Attempts to get object
|
* Get an object description and return a CloudObject.
|
||||||
* from in-memory cache first, stored static configurations next,
|
*/
|
||||||
* configured external cache third, and finally calls the Object API
|
public function getCloudObject(IRI $coid) {
|
||||||
* on CloudObjects Core. Returns null if the object was not found.
|
$node = $this->getObjectNode($coid);
|
||||||
|
if (!$node) {
|
||||||
|
// Object not found
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$object = (new CloudObject($coid, $node))
|
||||||
|
->setObjectRetriever($this);
|
||||||
|
|
||||||
|
if ($this->defaultReader) {
|
||||||
|
// Initialize CloudObject with default reader if it is set
|
||||||
|
$object->setReader($this->defaultReader);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $object;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an object description and return a node.
|
||||||
|
*
|
||||||
|
* @deprecated Use getObjectNode() instead
|
||||||
|
*/
|
||||||
|
public function getObject(IRI $coid) {
|
||||||
|
return $this->getObjectNode($coid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an object description from CloudObjects and return a node.
|
||||||
*
|
*
|
||||||
* @param IRI $coid COID of the object
|
* @param IRI $coid COID of the object
|
||||||
* @return Node|null
|
* @return Node|null
|
||||||
*/
|
*/
|
||||||
public function getObject(IRI $coid) {
|
public function getObjectNode(IRI $coid) {
|
||||||
if (!COIDParser::isValidCOID($coid))
|
if (!COIDParser::isValidCOID($coid))
|
||||||
throw new Exception("Not a valid COID.");
|
throw new Exception("Not a valid COID.");
|
||||||
|
|
||||||
@@ -394,10 +438,11 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an object description from CloudObjects. Shorthand method for
|
* Get an object description from CloudObjects. Shorthand method for
|
||||||
* "getObject" which allows passing the COID as string instead of IRI.
|
* "getObjectNode" which allows passing the COID as string instead of IRI.
|
||||||
*
|
*
|
||||||
* @param any $coid
|
* @param any $coid
|
||||||
* @return Node|null
|
* @return Node|null
|
||||||
|
* @deprecated Interface may change
|
||||||
*/
|
*/
|
||||||
public function get($coid) {
|
public function get($coid) {
|
||||||
if (is_string($coid))
|
if (is_string($coid))
|
||||||
@@ -425,7 +470,7 @@ class ObjectRetriever implements CustomCacheAndLogInterface {
|
|||||||
$ts = microtime(true);
|
$ts = microtime(true);
|
||||||
|
|
||||||
$cacheId = $object->getId().'#'.$filename;
|
$cacheId = $object->getId().'#'.$filename;
|
||||||
$fileData = $this->getFromCache($cacheId);
|
$fileData = $this->getFromCache($cacheId);
|
||||||
|
|
||||||
// Parse cached data into revision and content
|
// Parse cached data into revision and content
|
||||||
if (isset($fileData)) {
|
if (isset($fileData)) {
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ class APIClientFactory {
|
|||||||
if ($this->reader->hasProperty($api, 'oauth2:hasAuthorizationServer')) {
|
if ($this->reader->hasProperty($api, 'oauth2:hasAuthorizationServer')) {
|
||||||
// We have an authorization server for this endpoint/API
|
// We have an authorization server for this endpoint/API
|
||||||
$authServerCoid = $this->reader->getFirstValueIRI($api, 'oauth2:hasAuthorizationServer');
|
$authServerCoid = $this->reader->getFirstValueIRI($api, 'oauth2:hasAuthorizationServer');
|
||||||
$authServerObject = $this->objectRetriever->getObject($authServerCoid);
|
$authServerObject = $this->objectRetriever->getObjectNode($authServerCoid);
|
||||||
if (!isset($authServerObject))
|
if (!isset($authServerObject))
|
||||||
throw new InvalidObjectConfigurationException("Authorization server object <"
|
throw new InvalidObjectConfigurationException("Authorization server object <"
|
||||||
. (string)$authServerCoid . "> not available.");
|
. (string)$authServerCoid . "> not available.");
|
||||||
@@ -220,7 +220,7 @@ class APIClientFactory {
|
|||||||
public function __construct(ObjectRetriever $objectRetriever, IRI $namespaceCoid = null) {
|
public function __construct(ObjectRetriever $objectRetriever, IRI $namespaceCoid = null) {
|
||||||
$this->objectRetriever = $objectRetriever;
|
$this->objectRetriever = $objectRetriever;
|
||||||
$this->namespace = isset($namespaceCoid)
|
$this->namespace = isset($namespaceCoid)
|
||||||
? $objectRetriever->getObject($namespaceCoid)
|
? $objectRetriever->getObjectNode($namespaceCoid)
|
||||||
: $objectRetriever->getAuthenticatingNamespaceObject();
|
: $objectRetriever->getAuthenticatingNamespaceObject();
|
||||||
|
|
||||||
$this->reader = new NodeReader([
|
$this->reader = new NodeReader([
|
||||||
@@ -242,7 +242,7 @@ class APIClientFactory {
|
|||||||
public function getClientWithCOID(IRI $apiCoid, bool $specificClient = false) {
|
public function getClientWithCOID(IRI $apiCoid, bool $specificClient = false) {
|
||||||
$idString = (string)$apiCoid.(string)$specificClient;
|
$idString = (string)$apiCoid.(string)$specificClient;
|
||||||
if (!isset($this->apiClients[$idString])) {
|
if (!isset($this->apiClients[$idString])) {
|
||||||
$object = $this->objectRetriever->getObject($apiCoid);
|
$object = $this->objectRetriever->getObjectNode($apiCoid);
|
||||||
if (!isset($object))
|
if (!isset($object))
|
||||||
throw new CoreAPIException("Could not retrieve API <".(string)$apiCoid.">.");
|
throw new CoreAPIException("Could not retrieve API <".(string)$apiCoid.">.");
|
||||||
$this->apiClients[$idString] = $this->createClient($object, $specificClient);
|
$this->apiClients[$idString] = $this->createClient($object, $specificClient);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "cloudobjects/sdk",
|
"name": "cloudobjects/sdk",
|
||||||
"description": "CloudObjects SDK for PHP for working with COIDs and object descriptions from CloudObjects.",
|
"description": "CloudObjects SDK for PHP for working with COIDs and object descriptions from CloudObjects.",
|
||||||
"keywords": ["cloudobjects", "sdk"],
|
"keywords": ["cloudobjects", "sdk"],
|
||||||
"homepage": "https://github.com/CloudObjects/CloudObjects-PHP-SDK",
|
"homepage": "https://codeberg.org/CloudObjects/CloudObjects-PHP-SDK",
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"require" : {
|
"require" : {
|
||||||
"ml/json-ld": ">=1.0.7",
|
"ml/json-ld": ">=1.0.7",
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
"doctrine/cache" : "1.*",
|
"doctrine/cache" : "1.*",
|
||||||
"guzzlehttp/guzzle" : ">=6.0",
|
"guzzlehttp/guzzle" : ">=6.0",
|
||||||
"psr/log": ">=1.1",
|
"psr/log": ">=1.1",
|
||||||
"kevinrob/guzzle-cache-middleware": "^3.2",
|
"kevinrob/guzzle-cache-middleware": "^7.0.0",
|
||||||
"webmozart/assert": "^1.6"
|
"webmozart/assert": "^1.6"
|
||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
@@ -24,16 +24,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require-dev" : {
|
"require-dev" : {
|
||||||
"phpunit/phpunit": ">=4.8.0,<5.0",
|
"phpunit/phpunit": "^10",
|
||||||
"symfony/http-foundation" : ">=4.0",
|
"symfony/http-foundation" : ">=4.0",
|
||||||
"symfony/psr-http-message-bridge" : ">=1.1.0",
|
"symfony/psr-http-message-bridge" : ">=1.1.0",
|
||||||
"nyholm/psr7" : "~1.5.1",
|
"nyholm/psr7" : "~1.5.1",
|
||||||
"defuse/php-encryption" : "^2.2"
|
"defuse/php-encryption" : "^2.2"
|
||||||
},
|
},
|
||||||
"suggest" : {
|
"suggest" : {
|
||||||
"symfony/http-foundation" : "Required to use parseSymfonyRequest() in AccountContext.",
|
"symfony/http-foundation" : "Required to use fromSymfonyRequest() in AccountContext.",
|
||||||
"symfony/psr-http-message-bridge" : "Required to use parseSymfonyRequest() in AccountContext.",
|
"symfony/psr-http-message-bridge" : "Required to use fromSymfonyRequest() in AccountContext.",
|
||||||
"nyholm/psr7" : "Required to use parseSymfonyRequest() in AccountContext.",
|
"nyholm/psr7" : "Required to use fromSymfonyRequest() in AccountContext.",
|
||||||
"defuse/php-encryption": "Required to use CryptoHelper"
|
"defuse/php-encryption": "Required to use CryptoHelper"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1870
composer.lock
generated
1870
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit backupGlobals="false"
|
<phpunit backupGlobals="false"
|
||||||
backupStaticAttributes="false"
|
|
||||||
colors="true"
|
colors="true"
|
||||||
convertErrorsToExceptions="true"
|
|
||||||
convertNoticesToExceptions="true"
|
|
||||||
convertWarningsToExceptions="true"
|
|
||||||
processIsolation="false"
|
processIsolation="false"
|
||||||
stopOnFailure="false"
|
stopOnFailure="false"
|
||||||
syntaxCheck="false"
|
|
||||||
bootstrap="./tests/bootstrap.php">
|
bootstrap="./tests/bootstrap.php">
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="OfflineTests">
|
<testsuite name="OfflineTests">
|
||||||
|
|||||||
5
run-docker.sh
Normal file
5
run-docker.sh
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
docker run -d -v .:/root --name cloudobjects-sdk-test cloudobjects/php-build-base:8.3
|
||||||
|
docker exec cloudobjects-sdk-test bash -c "cd /root && composer install"
|
||||||
|
docker exec cloudobjects-sdk-test bash -c "cd /root && vendor/bin/phpunit"
|
||||||
|
docker stop cloudobjects-sdk-test
|
||||||
|
docker rm cloudobjects-sdk-test
|
||||||
@@ -8,7 +8,7 @@ namespace CloudObjects\SDK\AccountGateway;
|
|||||||
|
|
||||||
use ML\IRI\IRI;
|
use ML\IRI\IRI;
|
||||||
|
|
||||||
class AAUIDParserTest extends \PHPUnit_Framework_TestCase {
|
class AAUIDParserTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
public function testValidAccountAAUID() {
|
public function testValidAccountAAUID() {
|
||||||
$aauid = new IRI('aauid:abcd1234abcd1234');
|
$aauid = new IRI('aauid:abcd1234abcd1234');
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace CloudObjects\SDK\AccountGateway;
|
|||||||
use GuzzleHttp\Psr7\Request as GuzzlePsrRequest;
|
use GuzzleHttp\Psr7\Request as GuzzlePsrRequest;
|
||||||
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
|
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
|
||||||
|
|
||||||
class AccountContextParseTest extends \PHPUnit_Framework_TestCase {
|
class AccountContextParseTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
public function testParsePsrRequest() {
|
public function testParsePsrRequest() {
|
||||||
$request = new GuzzlePsrRequest('GET', '/', [
|
$request = new GuzzlePsrRequest('GET', '/', [
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ namespace CloudObjects\SDK\AccountGateway;
|
|||||||
|
|
||||||
use ML\IRI\IRI;
|
use ML\IRI\IRI;
|
||||||
|
|
||||||
class AccountContextTest extends \PHPUnit_Framework_TestCase {
|
class AccountContextTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
private $context;
|
private $context;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp(): void {
|
||||||
$this->context = new AccountContext(new IRI('aauid:aaaabbbbccccdddd'), 'DUMMY');
|
$this->context = new AccountContext(new IRI('aauid:aaaabbbbccccdddd'), 'DUMMY');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace CloudObjects\SDK;
|
|||||||
|
|
||||||
use ML\IRI\IRI;
|
use ML\IRI\IRI;
|
||||||
|
|
||||||
class COIDParserTest extends \PHPUnit_Framework_TestCase {
|
class COIDParserTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
public function testRootCOID() {
|
public function testRootCOID() {
|
||||||
$coid = new IRI('coid://example.com');
|
$coid = new IRI('coid://example.com');
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler,
|
|||||||
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
|
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
|
||||||
use CloudObjects\SDK\ObjectRetriever;
|
use CloudObjects\SDK\ObjectRetriever;
|
||||||
|
|
||||||
class CryptoHelperTest extends \PHPUnit_Framework_TestCase {
|
class CryptoHelperTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
private $retriever;
|
private $retriever;
|
||||||
private $graph;
|
private $graph;
|
||||||
@@ -22,7 +22,7 @@ class CryptoHelperTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$this->retriever->setClient(new Client(['handler' => $handler]));
|
$this->retriever->setClient(new Client(['handler' => $handler]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUp() {
|
protected function setUp(): void {
|
||||||
$this->retriever = new ObjectRetriever([
|
$this->retriever = new ObjectRetriever([
|
||||||
'auth_ns' => 'test.cloudobjects.io',
|
'auth_ns' => 'test.cloudobjects.io',
|
||||||
'auth_secret' => 'TEST'
|
'auth_secret' => 'TEST'
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ use InvalidArgumentException;
|
|||||||
use ML\JsonLD\JsonLD;
|
use ML\JsonLD\JsonLD;
|
||||||
use CloudObjects\SDK\ObjectRetriever;
|
use CloudObjects\SDK\ObjectRetriever;
|
||||||
|
|
||||||
class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
class SchemaValidatorTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
private $schemaValidator;
|
private $schemaValidator;
|
||||||
private $graph;
|
private $graph;
|
||||||
|
|
||||||
public function setUp() {
|
protected function setUp(): void {
|
||||||
$this->schemaValidator = new SchemaValidator(new ObjectRetriever);
|
$this->schemaValidator = new SchemaValidator(new ObjectRetriever);
|
||||||
$this->graph = JsonLD::getDocument('{}')->getGraph();
|
$this->graph = JsonLD::getDocument('{}')->getGraph();
|
||||||
}
|
}
|
||||||
@@ -24,10 +24,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/String'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/String'));
|
||||||
$this->schemaValidator->validateAgainstNode("Test", $node);
|
$this->schemaValidator->validateAgainstNode("Test", $node);
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotString() {
|
public function testNotString() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/String'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/String'));
|
||||||
@@ -38,10 +39,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/Number'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/Number'));
|
||||||
$this->schemaValidator->validateAgainstNode(3.5, $node);
|
$this->schemaValidator->validateAgainstNode(3.5, $node);
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotNumber() {
|
public function testNotNumber() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/Number'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/Number'));
|
||||||
@@ -52,10 +54,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/Integer'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/Integer'));
|
||||||
$this->schemaValidator->validateAgainstNode(12, $node);
|
$this->schemaValidator->validateAgainstNode(12, $node);
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotInteger() {
|
public function testNotInteger() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/Integer'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/Integer'));
|
||||||
@@ -66,10 +69,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/Array'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/Array'));
|
||||||
$this->schemaValidator->validateAgainstNode([ 1, 2, "foo" ], $node);
|
$this->schemaValidator->validateAgainstNode([ 1, 2, "foo" ], $node);
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotArray() {
|
public function testNotArray() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/Array'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/Array'));
|
||||||
@@ -83,10 +87,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'a' => 'A',
|
'a' => 'A',
|
||||||
'b' => 'B'
|
'b' => 'B'
|
||||||
], $node);
|
], $node);
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotObject() {
|
public function testNotObject() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$node = $this->graph->createNode();
|
$node = $this->graph->createNode();
|
||||||
$node->setType($this->graph->createNode('coid://json.co-n.net/Object'));
|
$node->setType($this->graph->createNode('coid://json.co-n.net/Object'));
|
||||||
@@ -105,10 +110,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'a' => 'A',
|
'a' => 'A',
|
||||||
'b' => 'B'
|
'b' => 'B'
|
||||||
], $node);
|
], $node);
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testObjectWithPropertyTypeError() {
|
public function testObjectWithPropertyTypeError() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$stringNode = $this->graph->createNode();
|
$stringNode = $this->graph->createNode();
|
||||||
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
|
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
|
||||||
@@ -136,10 +142,11 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'a' => 'A',
|
'a' => 'A',
|
||||||
'b' => 'B'
|
'b' => 'B'
|
||||||
], $node);
|
], $node);
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testObjectWithRequiredPropertyTypeError() {
|
public function testObjectWithRequiredPropertyTypeError() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$stringNode = $this->graph->createNode();
|
$stringNode = $this->graph->createNode();
|
||||||
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
|
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
|
||||||
@@ -156,7 +163,7 @@ class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testObjectWithRequiredPropertyMissing() {
|
public function testObjectWithRequiredPropertyMissing() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$stringNode = $this->graph->createNode();
|
$stringNode = $this->graph->createNode();
|
||||||
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
|
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
|
||||||
|
|||||||
@@ -7,150 +7,180 @@
|
|||||||
namespace CloudObjects\SDK;
|
namespace CloudObjects\SDK;
|
||||||
|
|
||||||
use ML\IRI\IRI;
|
use ML\IRI\IRI;
|
||||||
|
use ML\JsonLD\Node;
|
||||||
use GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler,
|
use GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler,
|
||||||
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
|
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
|
||||||
|
|
||||||
class NodeReaderMockTest extends \PHPUnit_Framework_TestCase {
|
class NodeReaderMockTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
private $retriever;
|
private $retriever;
|
||||||
private $reader;
|
private $reader;
|
||||||
|
|
||||||
private function setMockResponse(Response $response) {
|
private function setMockResponse(Response $response) {
|
||||||
$mock = new MockHandler([$response]);
|
$mock = new MockHandler([$response]);
|
||||||
$handler = HandlerStack::create($mock);
|
$handler = HandlerStack::create($mock);
|
||||||
$this->retriever->setClient(new Client(['handler' => $handler]));
|
$this->retriever->setClient(new Client(['handler' => $handler]));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function useRootResourceMock() {
|
private function useRootResourceMock() {
|
||||||
$this->setMockResponse(new Response(200,
|
$this->setMockResponse(new Response(200,
|
||||||
['Content-Type' => 'application/ld+json'],
|
['Content-Type' => 'application/ld+json'],
|
||||||
'{"@context":{"co":"coid:\/\/cloudobjects.io\/","rdf":"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#","agws":"coid:\/\/aauid.net\/","rdfs":"http:\/\/www.w3.org\/2000\/01\/rdf-schema#"},"@id":"coid:\/\/cloudobjects.io","@type":["agws:Service","co:Namespace"],"co:isAtRevision":"6-fbea0c90b2c5e5300e4039ed99be9b2d","co:isVisibleTo":{"@id":"co:Public"},"co:recommendsPrefix":"co","co:wasUpdatedAt":{"@type":"http:\/\/www.w3.org\/2001\/XMLSchema#dateTime","@value":"2017-01-16T17:29:22+00:00"},"rdfs:comment":"The CloudObjects namespace defines the essential objects.","rdfs:label":"CloudObjects"}'));
|
'{"@context":{"co":"coid:\/\/cloudobjects.io\/","rdf":"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#","agws":"coid:\/\/aauid.net\/","rdfs":"http:\/\/www.w3.org\/2000\/01\/rdf-schema#"},"@id":"coid:\/\/cloudobjects.io","@type":["agws:Service","co:Namespace"],"co:isAtRevision":"6-fbea0c90b2c5e5300e4039ed99be9b2d","co:isVisibleTo":{"@id":"co:Public"},"co:recommendsPrefix":"co","co:wasUpdatedAt":{"@type":"http:\/\/www.w3.org\/2001\/XMLSchema#dateTime","@value":"2017-01-16T17:29:22+00:00"},"rdfs:comment":"The CloudObjects namespace defines the essential objects.","rdfs:label":"CloudObjects"}'
|
||||||
}
|
));
|
||||||
|
}
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp(): void {
|
||||||
$this->retriever = new ObjectRetriever;
|
$this->retriever = new ObjectRetriever;
|
||||||
$this->reader = new NodeReader([
|
$this->reader = new NodeReader([
|
||||||
'prefixes' => [
|
'prefixes' => [
|
||||||
'co' => 'coid://cloudobjects.io/',
|
'co' => 'coid://cloudobjects.io/',
|
||||||
'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#'
|
'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#'
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
}
|
$this->retriever->setDefaultReader($this->reader);
|
||||||
|
}
|
||||||
|
|
||||||
public function testHasType1() {
|
public function testHasType1() {
|
||||||
$coid = new IRI('coid://cloudobjects.io');
|
$coid = new IRI('coid://cloudobjects.io');
|
||||||
$this->useRootResourceMock();
|
$this->useRootResourceMock();
|
||||||
$object = $this->retriever->getObject($coid);
|
$object = $this->retriever->getObjectNode($coid);
|
||||||
|
|
||||||
$this->assertTrue($this->reader->hasType($object, 'coid://cloudobjects.io/Namespace'));
|
$this->assertTrue($this->reader->hasType($object, 'coid://cloudobjects.io/Namespace'));
|
||||||
$this->assertTrue($this->reader->hasType($object, 'co:Namespace'));
|
$this->assertTrue($this->reader->hasType($object, 'co:Namespace'));
|
||||||
$this->assertFalse($this->reader->hasType($object, 'coid://cloudobjects.io/MemberRole'));
|
$this->assertFalse($this->reader->hasType($object, 'coid://cloudobjects.io/MemberRole'));
|
||||||
$this->assertFalse($this->reader->hasType($object, 'co:MemberRole'));
|
$this->assertFalse($this->reader->hasType($object, 'co:MemberRole'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHasPropertyValue1() {
|
public function testHasPropertyValue1() {
|
||||||
$coid = new IRI('coid://cloudobjects.io');
|
$coid = new IRI('coid://cloudobjects.io');
|
||||||
$this->useRootResourceMock();
|
$this->useRootResourceMock();
|
||||||
$object = $this->retriever->getObject($coid);
|
$object = $this->retriever->getObjectNode($coid);
|
||||||
|
|
||||||
$this->assertTrue($this->reader->hasPropertyValue($object, 'http://www.w3.org/2000/01/rdf-schema#label', 'CloudObjects'));
|
$this->assertTrue($this->reader->hasPropertyValue($object, 'http://www.w3.org/2000/01/rdf-schema#label', 'CloudObjects'));
|
||||||
$this->assertTrue($this->reader->hasPropertyValue($object, 'rdfs:label', 'CloudObjects'));
|
$this->assertTrue($this->reader->hasPropertyValue($object, 'rdfs:label', 'CloudObjects'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetFirstValueString1() {
|
public function testGetFirstValueString1() {
|
||||||
$coid = new IRI('coid://cloudobjects.io');
|
$coid = new IRI('coid://cloudobjects.io');
|
||||||
$this->useRootResourceMock();
|
$this->useRootResourceMock();
|
||||||
$object = $this->retriever->getObject($coid);
|
$object = $this->retriever->getObjectNode($coid);
|
||||||
|
|
||||||
$this->assertEquals('CloudObjects', $this->reader->getFirstValueString($object, 'http://www.w3.org/2000/01/rdf-schema#label'));
|
$this->assertEquals('CloudObjects', $this->reader->getFirstValueString($object, 'http://www.w3.org/2000/01/rdf-schema#label'));
|
||||||
$this->assertEquals('CloudObjects', $this->reader->getFirstValueString($object, 'rdfs:label'));
|
$this->assertEquals('CloudObjects', $this->reader->getFirstValueString($object, 'rdfs:label'));
|
||||||
|
|
||||||
$this->assertNull($this->reader->getFirstValueString($object, 'coid://cloudobjects.io/makesTriplesVisibleTo'));
|
$this->assertNull($this->reader->getFirstValueString($object, 'coid://cloudobjects.io/makesTriplesVisibleTo'));
|
||||||
$this->assertNull($this->reader->getFirstValueString($object, 'co:makesTriplesVisibleTo'));
|
$this->assertNull($this->reader->getFirstValueString($object, 'co:makesTriplesVisibleTo'));
|
||||||
|
|
||||||
$this->assertEquals('theDefaultValue', $this->reader->getFirstValueString($object, 'coid://cloudobjects.io/makesTriplesVisibleTo', 'theDefaultValue'));
|
$this->assertEquals('theDefaultValue', $this->reader->getFirstValueString($object, 'coid://cloudobjects.io/makesTriplesVisibleTo', 'theDefaultValue'));
|
||||||
$this->assertEquals('theDefaultValue', $this->reader->getFirstValueString($object, 'co:makesTriplesVisibleTo', 'theDefaultValue'));
|
$this->assertEquals('theDefaultValue', $this->reader->getFirstValueString($object, 'co:makesTriplesVisibleTo', 'theDefaultValue'));
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetFirstValueIRI1() {
|
$object = $this->retriever->getCloudObject($coid);
|
||||||
$coid = new IRI('coid://cloudobjects.io');
|
|
||||||
$this->useRootResourceMock();
|
|
||||||
$object = $this->retriever->getObject($coid);
|
|
||||||
|
|
||||||
$this->assertInstanceOf('ML\IRI\IRI', $this->reader->getFirstValueIRI($object, 'coid://cloudobjects.io/isVisibleTo'));
|
$this->assertEquals('CloudObjects', $object->getString('http://www.w3.org/2000/01/rdf-schema#label'));
|
||||||
$this->assertInstanceOf('ML\IRI\IRI', $this->reader->getFirstValueIRI($object, 'co:isVisibleTo'));
|
$this->assertEquals('CloudObjects', $object->getString('rdfs:label'));
|
||||||
|
|
||||||
$this->assertEquals(new IRI('coid://cloudobjects.io/Public'), $this->reader->getFirstValueIRI($object, 'coid://cloudobjects.io/isVisibleTo'));
|
$this->assertNull($object->getString('coid://cloudobjects.io/makesTriplesVisibleTo'));
|
||||||
$this->assertEquals(new IRI('coid://cloudobjects.io/Public'), $this->reader->getFirstValueIRI($object, 'co:isVisibleTo'));
|
$this->assertNull($object->getString('co:makesTriplesVisibleTo'));
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetFirstValueNode1() {
|
$this->assertEquals('theDefaultValue', $object->getString('coid://cloudobjects.io/makesTriplesVisibleTo', 'theDefaultValue'));
|
||||||
$coid = new IRI('coid://cloudobjects.io');
|
$this->assertEquals('theDefaultValue', $object->getString('co:makesTriplesVisibleTo', 'theDefaultValue'));
|
||||||
$this->useRootResourceMock();
|
}
|
||||||
$object = $this->retriever->getObject($coid);
|
|
||||||
|
|
||||||
$this->assertInstanceOf('ML\JsonLD\Node', $this->reader->getFirstValueNode($object, 'coid://cloudobjects.io/isVisibleTo'));
|
public function testGetFirstValueIRI1() {
|
||||||
$this->assertInstanceOf('ML\JsonLD\Node', $this->reader->getFirstValueNode($object, 'co:isVisibleTo'));
|
$coid = new IRI('coid://cloudobjects.io');
|
||||||
|
$this->useRootResourceMock();
|
||||||
|
$object = $this->retriever->getObjectNode($coid);
|
||||||
|
|
||||||
$this->assertEquals('coid://cloudobjects.io/Public', $this->reader->getFirstValueNode($object, 'coid://cloudobjects.io/isVisibleTo')->getId());
|
$this->assertInstanceOf(IRI::class, $this->reader->getFirstValueIRI($object, 'coid://cloudobjects.io/isVisibleTo'));
|
||||||
$this->assertEquals('coid://cloudobjects.io/Public', $this->reader->getFirstValueNode($object, 'co:isVisibleTo')->getId());
|
$this->assertInstanceOf(IRI::class, $this->reader->getFirstValueIRI($object, 'co:isVisibleTo'));
|
||||||
}
|
|
||||||
|
|
||||||
public function testGetAllValuesString1() {
|
$this->assertEquals(new IRI('coid://cloudobjects.io/Public'), $this->reader->getFirstValueIRI($object, 'coid://cloudobjects.io/isVisibleTo'));
|
||||||
$coid = new IRI('coid://cloudobjects.io');
|
$this->assertEquals(new IRI('coid://cloudobjects.io/Public'), $this->reader->getFirstValueIRI($object, 'co:isVisibleTo'));
|
||||||
$this->useRootResourceMock();
|
|
||||||
$object = $this->retriever->getObject($coid);
|
|
||||||
|
|
||||||
$this->assertCount(1, $this->reader->getAllValuesString($object, 'http://www.w3.org/2000/01/rdf-schema#label'));
|
$object = $this->retriever->getCloudObject($coid);
|
||||||
$this->assertCount(1, $this->reader->getAllValuesString($object, 'rdfs:label'));
|
|
||||||
|
|
||||||
$this->assertEquals('CloudObjects', $this->reader->getAllValuesString($object, 'http://www.w3.org/2000/01/rdf-schema#label')[0]);
|
$this->assertInstanceOf(IRI::class, $object->getIRI('coid://cloudobjects.io/isVisibleTo'));
|
||||||
$this->assertEquals('CloudObjects', $this->reader->getAllValuesString($object, 'rdfs:label')[0]);
|
$this->assertInstanceOf(IRI::class, $object->getIRI('co:isVisibleTo'));
|
||||||
|
|
||||||
$this->assertCount(0, $this->reader->getAllValuesString($object, 'coid://cloudobjects.io/makesTriplesVisibleTo'));
|
$this->assertEquals(new IRI('coid://cloudobjects.io/Public'), $object->getIRI('coid://cloudobjects.io/isVisibleTo'));
|
||||||
$this->assertCount(0, $this->reader->getAllValuesString($object, 'co:makesTriplesVisibleTo'));
|
$this->assertEquals(new IRI('coid://cloudobjects.io/Public'), $object->getIRI('co:isVisibleTo'));
|
||||||
|
}
|
||||||
|
|
||||||
$this->assertCount(2, $this->reader->getAllValuesString($object, '@type'));
|
public function testGetFirstValueNode1() {
|
||||||
}
|
$coid = new IRI('coid://cloudobjects.io');
|
||||||
|
$this->useRootResourceMock();
|
||||||
|
$object = $this->retriever->getObjectNode($coid);
|
||||||
|
|
||||||
public function testGetAllValuesIRI1() {
|
$this->assertInstanceOf(Node::class, $this->reader->getFirstValueNode($object, 'coid://cloudobjects.io/isVisibleTo'));
|
||||||
$coid = new IRI('coid://cloudobjects.io');
|
$this->assertInstanceOf(Node::class, $this->reader->getFirstValueNode($object, 'co:isVisibleTo'));
|
||||||
$this->useRootResourceMock();
|
|
||||||
$object = $this->retriever->getObject($coid);
|
|
||||||
|
|
||||||
$this->assertCount(0, $this->reader->getAllValuesIRI($object, 'http://www.w3.org/2000/01/rdf-schema#label'));
|
$this->assertEquals('coid://cloudobjects.io/Public', $this->reader->getFirstValueNode($object, 'coid://cloudobjects.io/isVisibleTo')->getId());
|
||||||
$this->assertCount(0, $this->reader->getAllValuesIRI($object, 'rdfs:label'));
|
$this->assertEquals('coid://cloudobjects.io/Public', $this->reader->getFirstValueNode($object, 'co:isVisibleTo')->getId());
|
||||||
|
|
||||||
$this->assertCount(1, $this->reader->getAllValuesIRI($object, 'coid://cloudobjects.io/isVisibleTo'));
|
$object = $this->retriever->getCloudObject($coid);
|
||||||
$this->assertCount(1, $this->reader->getAllValuesIRI($object, 'co:isVisibleTo'));
|
|
||||||
|
|
||||||
$this->assertCount(2, $this->reader->getAllValuesIRI($object, '@type'));
|
$this->assertInstanceOf(Node::class, $object->getNode('coid://cloudobjects.io/isVisibleTo'));
|
||||||
|
$this->assertInstanceOf(Node::class, $object->getNode('co:isVisibleTo'));
|
||||||
|
|
||||||
$this->assertInstanceOf('ML\IRI\IRI', $this->reader->getAllValuesIRI($object, 'coid://cloudobjects.io/isVisibleTo')[0]);
|
$this->assertEquals('coid://cloudobjects.io/Public', $object->getNode('coid://cloudobjects.io/isVisibleTo')->getId());
|
||||||
$this->assertInstanceOf('ML\IRI\IRI', $this->reader->getAllValuesIRI($object, 'co:isVisibleTo')[0]);
|
$this->assertEquals('coid://cloudobjects.io/Public', $object->getNode('co:isVisibleTo')->getId());
|
||||||
|
}
|
||||||
|
|
||||||
$this->assertEquals(new IRI('coid://cloudobjects.io/Public'), $this->reader->getAllValuesIRI($object, 'coid://cloudobjects.io/isVisibleTo')[0]);
|
public function testGetAllValuesString1() {
|
||||||
$this->assertEquals(new IRI('coid://cloudobjects.io/Public'), $this->reader->getAllValuesIRI($object, 'co:isVisibleTo')[0]);
|
$coid = new IRI('coid://cloudobjects.io');
|
||||||
}
|
$this->useRootResourceMock();
|
||||||
|
$object = $this->retriever->getObjectNode($coid);
|
||||||
|
|
||||||
public function testGetAllValuesNode1() {
|
$this->assertCount(1, $this->reader->getAllValuesString($object, 'http://www.w3.org/2000/01/rdf-schema#label'));
|
||||||
$coid = new IRI('coid://cloudobjects.io');
|
$this->assertCount(1, $this->reader->getAllValuesString($object, 'rdfs:label'));
|
||||||
$this->useRootResourceMock();
|
|
||||||
$object = $this->retriever->getObject($coid);
|
|
||||||
|
|
||||||
$this->assertCount(0, $this->reader->getAllValuesNode($object, 'http://www.w3.org/2000/01/rdf-schema#label'));
|
$this->assertEquals('CloudObjects', $this->reader->getAllValuesString($object, 'http://www.w3.org/2000/01/rdf-schema#label')[0]);
|
||||||
$this->assertCount(0, $this->reader->getAllValuesNode($object, 'rdfs:label'));
|
$this->assertEquals('CloudObjects', $this->reader->getAllValuesString($object, 'rdfs:label')[0]);
|
||||||
|
|
||||||
$this->assertCount(1, $this->reader->getAllValuesNode($object, 'coid://cloudobjects.io/isVisibleTo'));
|
$this->assertCount(0, $this->reader->getAllValuesString($object, 'coid://cloudobjects.io/makesTriplesVisibleTo'));
|
||||||
$this->assertCount(1, $this->reader->getAllValuesNode($object, 'co:isVisibleTo'));
|
$this->assertCount(0, $this->reader->getAllValuesString($object, 'co:makesTriplesVisibleTo'));
|
||||||
|
|
||||||
$this->assertCount(2, $this->reader->getAllValuesNode($object, '@type'));
|
$this->assertCount(2, $this->reader->getAllValuesString($object, '@type'));
|
||||||
|
}
|
||||||
|
|
||||||
$this->assertInstanceOf('ML\JsonLD\Node', $this->reader->getAllValuesNode($object, 'coid://cloudobjects.io/isVisibleTo')[0]);
|
public function testGetAllValuesIRI1() {
|
||||||
$this->assertInstanceOf('ML\JsonLD\Node', $this->reader->getAllValuesNode($object, 'co:isVisibleTo')[0]);
|
$coid = new IRI('coid://cloudobjects.io');
|
||||||
|
$this->useRootResourceMock();
|
||||||
|
$object = $this->retriever->getObjectNode($coid);
|
||||||
|
|
||||||
$this->assertEquals('coid://cloudobjects.io/Public', $this->reader->getAllValuesNode($object, 'coid://cloudobjects.io/isVisibleTo')[0]->getId());
|
$this->assertCount(0, $this->reader->getAllValuesIRI($object, 'http://www.w3.org/2000/01/rdf-schema#label'));
|
||||||
$this->assertEquals('coid://cloudobjects.io/Public', $this->reader->getAllValuesNode($object, 'co:isVisibleTo')[0]->getId());
|
$this->assertCount(0, $this->reader->getAllValuesIRI($object, 'rdfs:label'));
|
||||||
}
|
|
||||||
|
$this->assertCount(1, $this->reader->getAllValuesIRI($object, 'coid://cloudobjects.io/isVisibleTo'));
|
||||||
|
$this->assertCount(1, $this->reader->getAllValuesIRI($object, 'co:isVisibleTo'));
|
||||||
|
|
||||||
|
$this->assertCount(2, $this->reader->getAllValuesIRI($object, '@type'));
|
||||||
|
|
||||||
|
$this->assertInstanceOf(IRI::class, $this->reader->getAllValuesIRI($object, 'coid://cloudobjects.io/isVisibleTo')[0]);
|
||||||
|
$this->assertInstanceOf(IRI::class, $this->reader->getAllValuesIRI($object, 'co:isVisibleTo')[0]);
|
||||||
|
|
||||||
|
$this->assertEquals(new IRI('coid://cloudobjects.io/Public'), $this->reader->getAllValuesIRI($object, 'coid://cloudobjects.io/isVisibleTo')[0]);
|
||||||
|
$this->assertEquals(new IRI('coid://cloudobjects.io/Public'), $this->reader->getAllValuesIRI($object, 'co:isVisibleTo')[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetAllValuesNode1() {
|
||||||
|
$coid = new IRI('coid://cloudobjects.io');
|
||||||
|
$this->useRootResourceMock();
|
||||||
|
$object = $this->retriever->getObjectNode($coid);
|
||||||
|
|
||||||
|
$this->assertCount(0, $this->reader->getAllValuesNode($object, 'http://www.w3.org/2000/01/rdf-schema#label'));
|
||||||
|
$this->assertCount(0, $this->reader->getAllValuesNode($object, 'rdfs:label'));
|
||||||
|
|
||||||
|
$this->assertCount(1, $this->reader->getAllValuesNode($object, 'coid://cloudobjects.io/isVisibleTo'));
|
||||||
|
$this->assertCount(1, $this->reader->getAllValuesNode($object, 'co:isVisibleTo'));
|
||||||
|
|
||||||
|
$this->assertCount(2, $this->reader->getAllValuesNode($object, '@type'));
|
||||||
|
|
||||||
|
$this->assertInstanceOf(Node::class, $this->reader->getAllValuesNode($object, 'coid://cloudobjects.io/isVisibleTo')[0]);
|
||||||
|
$this->assertInstanceOf(Node::class, $this->reader->getAllValuesNode($object, 'co:isVisibleTo')[0]);
|
||||||
|
|
||||||
|
$this->assertEquals('coid://cloudobjects.io/Public', $this->reader->getAllValuesNode($object, 'coid://cloudobjects.io/isVisibleTo')[0]->getId());
|
||||||
|
$this->assertEquals('coid://cloudobjects.io/Public', $this->reader->getAllValuesNode($object, 'co:isVisibleTo')[0]->getId());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,33 +8,46 @@ namespace CloudObjects\SDK;
|
|||||||
|
|
||||||
use ML\IRI\IRI;
|
use ML\IRI\IRI;
|
||||||
use GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler,
|
use GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler,
|
||||||
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
|
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
|
||||||
|
|
||||||
class ObjectRetrieverMockTest extends \PHPUnit_Framework_TestCase {
|
class ObjectRetrieverMockTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
private $retriever;
|
private $retriever;
|
||||||
|
|
||||||
private function setMockResponse(Response $response) {
|
private function setMockResponse(Response $response) {
|
||||||
$mock = new MockHandler([$response]);
|
$mock = new MockHandler([$response]);
|
||||||
$handler = HandlerStack::create($mock);
|
$handler = HandlerStack::create($mock);
|
||||||
$this->retriever->setClient(new Client(['handler' => $handler]));
|
$this->retriever->setClient(new Client(['handler' => $handler]));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp(): void {
|
||||||
$this->retriever = new ObjectRetriever;
|
$this->retriever = new ObjectRetriever;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetRootResource() {
|
public function testGetRootResource() {
|
||||||
$this->setMockResponse(new Response(200,
|
$this->setMockResponse(new Response(200,
|
||||||
['Content-Type' => 'application/ld+json'],
|
['Content-Type' => 'application/ld+json'],
|
||||||
'{"@context":{"cloudobjects":"coid:\/\/cloudobjects.io\/","rdf":"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#","rdfs":"http:\/\/www.w3.org\/2000\/01\/rdf-schema#"},"@id":"coid:\/\/cloudobjects.io","@type":"cloudobjects:Namespace","cloudobjects:hasPublicListing":"true","cloudobjects:revision":"1-325baa62b76105f56dc09386f5a2ec91","rdfs:comment":"The CloudObjects namespace defines the essential objects.","rdfs:label":"CloudObjects"}'));
|
'{"@context":{"cloudobjects":"coid:\/\/cloudobjects.io\/","rdf":"http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#","rdfs":"http:\/\/www.w3.org\/2000\/01\/rdf-schema#"},"@id":"coid:\/\/cloudobjects.io","@type":"cloudobjects:Namespace","cloudobjects:hasPublicListing":"true","cloudobjects:revision":"1-325baa62b76105f56dc09386f5a2ec91","rdfs:comment":"The CloudObjects namespace defines the essential objects.","rdfs:label":"CloudObjects"}'
|
||||||
|
));
|
||||||
|
|
||||||
$coid = new IRI('coid://cloudobjects.io');
|
$coid = new IRI('coid://cloudobjects.io');
|
||||||
$object = $this->retriever->getObject($coid);
|
|
||||||
$this->assertNotNull($object);
|
// Test node interface first
|
||||||
$this->assertEquals((string)$coid, $object->getID());
|
$object = $this->retriever->getObjectNode($coid);
|
||||||
$this->assertNotNull($object->getProperty('http://www.w3.org/2000/01/rdf-schema#label'));
|
$this->assertNotNull($object);
|
||||||
$this->assertEquals('CloudObjects', $object->getProperty('http://www.w3.org/2000/01/rdf-schema#label')->getValue());
|
$this->assertEquals((string)$coid, $object->getId());
|
||||||
}
|
$this->assertNotNull($object->getProperty('http://www.w3.org/2000/01/rdf-schema#label'));
|
||||||
|
$this->assertEquals('CloudObjects', $object->getProperty('http://www.w3.org/2000/01/rdf-schema#label')->getValue());
|
||||||
|
$this->assertNull($object->getProperty('urn:example:nonexistingvalue'));
|
||||||
|
|
||||||
|
// Test CloudObject interface
|
||||||
|
$object = $this->retriever->getCloudObject($coid);
|
||||||
|
$this->assertNotNull($object);
|
||||||
|
$this->assertEquals((string)$coid, $object->getAsNode()->getId());
|
||||||
|
$this->assertEquals($coid, $object->getCOID());
|
||||||
|
$this->assertNotNull($object->getString('http://www.w3.org/2000/01/rdf-schema#label'));
|
||||||
|
$this->assertEquals('CloudObjects', $object->getString('http://www.w3.org/2000/01/rdf-schema#label'));
|
||||||
|
$this->assertNull($object->getString('urn:example:nonexistingvalue'));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ use InvalidArgumentException;
|
|||||||
use ML\IRI\IRI;
|
use ML\IRI\IRI;
|
||||||
use CloudObjects\SDK\ObjectRetriever;
|
use CloudObjects\SDK\ObjectRetriever;
|
||||||
|
|
||||||
class SchemaValidatorPublicTest extends \PHPUnit_Framework_TestCase {
|
class SchemaValidatorPublicTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
private $schemaValidator;
|
private $schemaValidator;
|
||||||
|
|
||||||
public function setUp() {
|
protected function setUp(): void {
|
||||||
$this->schemaValidator = new SchemaValidator(new ObjectRetriever);
|
$this->schemaValidator = new SchemaValidator(new ObjectRetriever);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,10 +24,11 @@ class SchemaValidatorPublicTest extends \PHPUnit_Framework_TestCase {
|
|||||||
'region' => 'Hessen',
|
'region' => 'Hessen',
|
||||||
'country-name' => 'Germany'
|
'country-name' => 'Germany'
|
||||||
], new IRI('coid://json.co-n.net/Address'));
|
], new IRI('coid://json.co-n.net/Address'));
|
||||||
|
$this->addToAssertionCount(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotAddress() {
|
public function testNotAddress() {
|
||||||
$this->setExpectedException(InvalidArgumentException::class);
|
$this->expectException(InvalidArgumentException::class);
|
||||||
|
|
||||||
$this->schemaValidator->validateAgainstCOID([
|
$this->schemaValidator->validateAgainstCOID([
|
||||||
'region' => 'Hessen',
|
'region' => 'Hessen',
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ namespace CloudObjects\SDK;
|
|||||||
|
|
||||||
use ML\IRI\IRI;
|
use ML\IRI\IRI;
|
||||||
|
|
||||||
class ObjectRetrieverTest extends \PHPUnit_Framework_TestCase {
|
class ObjectRetrieverPublicTest extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
private $retriever;
|
private $retriever;
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp(): void {
|
||||||
$this->retriever = new ObjectRetriever;
|
$this->retriever = new ObjectRetriever;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,13 +26,25 @@ class ObjectRetrieverTest extends \PHPUnit_Framework_TestCase {
|
|||||||
|
|
||||||
public function testGetRootObject() {
|
public function testGetRootObject() {
|
||||||
$coid = new IRI('coid://cloudobjects.io');
|
$coid = new IRI('coid://cloudobjects.io');
|
||||||
$object = $this->retriever->getObject($coid);
|
$object = $this->retriever->getObjectNode($coid);
|
||||||
$this->assertNotNull($object);
|
$this->assertNotNull($object);
|
||||||
$this->assertEquals((string)$coid, $object->getID());
|
$this->assertEquals((string)$coid, $object->getId());
|
||||||
$this->assertNotNull($object->getProperty('http://www.w3.org/2000/01/rdf-schema#label'));
|
$this->assertNotNull($object->getProperty('http://www.w3.org/2000/01/rdf-schema#label'));
|
||||||
$this->assertEquals('CloudObjects', $object->getProperty('http://www.w3.org/2000/01/rdf-schema#label')->getValue());
|
$this->assertEquals('CloudObjects', $object->getProperty('http://www.w3.org/2000/01/rdf-schema#label')->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetRelatedObject() {
|
||||||
|
$coid = new IRI('coid://cloudobjects.io');
|
||||||
|
$object = $this->retriever->getCloudObject($coid);
|
||||||
|
$this->assertNotNull($object);
|
||||||
|
$this->assertNotNull($object->getIRI('coid://cloudobjects.io/isVisibleTo'));
|
||||||
|
$this->assertEquals('coid://cloudobjects.io/Public', $object->getString('coid://cloudobjects.io/isVisibleTo'));
|
||||||
|
|
||||||
|
$relatedObject = $object->getCloudObject('coid://cloudobjects.io/isVisibleTo');
|
||||||
|
$this->assertNotNull($relatedObject);
|
||||||
|
$this->assertEquals('coid://cloudobjects.io/Public', (string)$relatedObject->getCOID());
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetCOIDList() {
|
public function testGetCOIDList() {
|
||||||
$coid = new IRI('coid://cloudobjects.io');
|
$coid = new IRI('coid://cloudobjects.io');
|
||||||
$list = $this->stringifyItems(
|
$list = $this->stringifyItems(
|
||||||
|
|||||||
Reference in New Issue
Block a user