Imported code from old repository

This commit is contained in:
2022-11-17 11:48:29 +01:00
parent 14dfa45240
commit 0e4ab60d77
31 changed files with 6486 additions and 253 deletions

View File

@@ -0,0 +1,63 @@
<?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\AccountGateway;
use ML\IRI\IRI;
class AAUIDParserTest extends \PHPUnit_Framework_TestCase {
public function testValidAccountAAUID() {
$aauid = new IRI('aauid:abcd1234abcd1234');
$this->assertEquals(AAUIDParser::AAUID_ACCOUNT, AAUIDParser::getType($aauid));
$this->assertEquals('abcd1234abcd1234', AAUIDParser::getAAUID($aauid));
}
public function testInvalidAccountAAUID() {
$aauid = new IRI('aauid:abcd1234abcd123');
$this->assertEquals(AAUIDParser::AAUID_INVALID, AAUIDParser::getType($aauid));
$this->assertNull(AAUIDParser::getAAUID($aauid));
}
public function testValidAccountConnectionAAUID() {
$aauid = new IRI('aauid:abcd1234abcd1234:connection:AA');
$this->assertEquals(AAUIDParser::AAUID_CONNECTION, AAUIDParser::getType($aauid));
$this->assertEquals('abcd1234abcd1234', AAUIDParser::getAAUID($aauid));
$this->assertEquals('AA', AAUIDParser::getQualifier($aauid));
}
public function testInvalidAccountConnectionAAUID() {
$aauid = new IRI('aauid:abcd1234abcd1234:connection:AAA');
$this->assertEquals(AAUIDParser::AAUID_INVALID, AAUIDParser::getType($aauid));
$this->assertNull(AAUIDParser::getAAUID($aauid));
$this->assertNull(AAUIDParser::getQualifier($aauid));
}
public function testValidConnectedAccountAAUID() {
$aauid = new IRI('aauid:abcd1234abcd1234:account:AA');
$this->assertEquals(AAUIDParser::AAUID_CONNECTED_ACCOUNT, AAUIDParser::getType($aauid));
$this->assertEquals('abcd1234abcd1234', AAUIDParser::getAAUID($aauid));
$this->assertEquals('AA', AAUIDParser::getQualifier($aauid));
}
public function testInvalidConnectedAccountAAUID() {
$aauid = new IRI('aauid:abcd1234abcd1234:account:X9');
$this->assertEquals(AAUIDParser::AAUID_INVALID, AAUIDParser::getType($aauid));
$this->assertNull(AAUIDParser::getAAUID($aauid));
$this->assertNull(AAUIDParser::getQualifier($aauid));
}
public function testFromStringValid() {
$aauid1 = new IRI('aauid:5678defg8765gfed');
$aauid2 = AAUIDParser::fromString('aauid:5678defg8765gfed');
$this->assertEquals($aauid1, $aauid2);
$aauid1 = new IRI('aauid:5678defg8765gfed');
$aauid2 = AAUIDParser::fromString('5678defg8765gfed');
$this->assertEquals($aauid1, $aauid2);
}
}

View File

@@ -0,0 +1,34 @@
<?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\AccountGateway;
use GuzzleHttp\Psr7\Request as GuzzlePsrRequest;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
class AccountContextParseTest extends \PHPUnit_Framework_TestCase {
public function testParsePsrRequest() {
$request = new GuzzlePsrRequest('GET', '/', [
'C-AAUID' => '1234123412341234', 'C-Access-Token' => 'test'
]);
$context = AccountContext::fromPsrRequest($request);
$this->assertNotNull($context);
$this->assertEquals('1234123412341234', AAUIDParser::getAAUID($context->getAAUID()));
}
public function testParseSymfonyRequest() {
$request = SymfonyRequest::create('/', 'GET', [], [], [], [
'HTTP_C_AAUID' => '1234123412341234', 'HTTP_C_ACCESS_TOKEN' => 'test'
]);
$context = AccountContext::fromSymfonyRequest($request);
$this->assertNotNull($context);
$this->assertEquals('1234123412341234', AAUIDParser::getAAUID($context->getAAUID()));
}
}

View File

@@ -0,0 +1,33 @@
<?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\AccountGateway;
use ML\IRI\IRI;
class AccountContextTest extends \PHPUnit_Framework_TestCase {
private $context;
protected function setUp() {
$this->context = new AccountContext(new IRI('aauid:aaaabbbbccccdddd'), 'DUMMY');
}
public function testDefaultGatewayBaseURL() {
$this->assertEquals('https://aaaabbbbccccdddd.aauid.net', $this->context->getClient()->getConfig('base_uri'));
}
public function testSetAccountGatewayBaseURLTemplateWithPlaceholder() {
$this->context->setAccountGatewayBaseURLTemplate('http://{aauid}.localhost');
$this->assertEquals('http://aaaabbbbccccdddd.localhost', $this->context->getClient()->getConfig('base_uri'));
}
public function testSetAccountGatewayBaseURLTemplateWithoutPlaceholder() {
$this->context->setAccountGatewayBaseURLTemplate('http://localhost');
$this->assertEquals('http://localhost', $this->context->getClient()->getConfig('base_uri'));
}
}

View File

@@ -0,0 +1,130 @@
<?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;
class COIDParserTest extends \PHPUnit_Framework_TestCase {
public function testRootCOID() {
$coid = new IRI('coid://example.com');
$this->assertEquals(COIDParser::COID_ROOT, COIDParser::getType($coid));
}
public function testInvalidRootCOID() {
$coid = new IRI('coid://example');
$this->assertEquals(COIDParser::COID_INVALID, COIDParser::getType($coid));
$coid = new IRI('coid://exämple.com');
$this->assertEquals(COIDParser::COID_INVALID, COIDParser::getType($coid));
$coid = new IRI('coid://ex&mple.com');
$this->assertEquals(COIDParser::COID_INVALID, COIDParser::getType($coid));
}
public function testInvalidCOID() {
$coid = new IRI('http://example.com');
$this->assertEquals(COIDParser::COID_INVALID, COIDParser::getType($coid));
$coid = new IRI('example.com');
$this->assertEquals(COIDParser::COID_INVALID, COIDParser::getType($coid));
$coid = new IRI('COID://example.com');
$this->assertEquals(COIDParser::COID_INVALID, COIDParser::getType($coid));
$coid = new IRI('Coid://example.com');
$this->assertEquals(COIDParser::COID_INVALID, COIDParser::getType($coid));
$coid = new IRI('coid://EXAMPLE.COM');
$this->assertEquals(COIDParser::COID_INVALID, COIDParser::getType($coid));
$coid = new IRI('coid://exAMPle.CoM');
$this->assertEquals(COIDParser::COID_INVALID, COIDParser::getType($coid));
}
public function testUnversionedCOID() {
$coid = new IRI('coid://example.com/Example');
$this->assertEquals(COIDParser::COID_UNVERSIONED, COIDParser::getType($coid));
}
public function testInvalidUnversionedCOID() {
$coid = new IRI('coid://example.com/Exümple');
$this->assertEquals(COIDParser::COID_INVALID, COIDParser::getType($coid));
$coid = new IRI('coid://example.com/Examp%e');
$this->assertEquals(COIDParser::COID_INVALID, COIDParser::getType($coid));
}
public function testVersionedCOID() {
$coid = new IRI('coid://example.com/Example/1.0');
$this->assertEquals(COIDParser::COID_VERSIONED, COIDParser::getType($coid));
$coid = new IRI('coid://example.com/Example/alpha');
$this->assertEquals(COIDParser::COID_VERSIONED, COIDParser::getType($coid));
}
public function testInvalidVersionedCOID() {
$coid = new IRI('coid://example.com/Example/1.$');
$this->assertEquals(COIDParser::COID_INVALID, COIDParser::getType($coid));
}
public function testVersionWildcardCOID() {
$coid = new IRI('coid://example.com/Example/^1.0');
$this->assertEquals(COIDParser::COID_VERSION_WILDCARD, COIDParser::getType($coid));
$coid = new IRI('coid://example.com/Example/~1.0');
$this->assertEquals(COIDParser::COID_VERSION_WILDCARD, COIDParser::getType($coid));
$coid = new IRI('coid://example.com/Example/1.*');
$this->assertEquals(COIDParser::COID_VERSION_WILDCARD, COIDParser::getType($coid));
}
public function testInvalidVersionWildcardCOID() {
$coid = new IRI('coid://example.com/Example/^1.*');
$this->assertEquals(COIDParser::COID_INVALID, COIDParser::getType($coid));
$coid = new IRI('coid://example.com/Example/1.a.*');
$this->assertEquals(COIDParser::COID_INVALID, COIDParser::getType($coid));
}
public function testIRICaseSensitivity() {
$coid1 = new IRI('coid://example.com/example/1.0');
$coid2 = new IRI('coid://example.com/Example/1.0');
$this->assertFalse($coid1->equals($coid2));
}
public function testRootFromString() {
$coid1 = new IRI('coid://example.com');
$coid2 = COIDParser::fromString('coid://example.com');
$coid3 = COIDParser::fromString('example.com');
$this->assertTrue($coid1->equals($coid2));
$this->assertTrue($coid1->equals($coid3));
}
public function testUnversionedFromString() {
$coid1 = new IRI('coid://example.com/Example');
$coid2 = COIDParser::fromString('coid://example.com/Example');
$coid3 = COIDParser::fromString('example.com/Example');
$this->assertTrue($coid1->equals($coid2));
$this->assertTrue($coid1->equals($coid3));
}
public function testVersionedFromString() {
$coid1 = new IRI('coid://example.com/Example/1.0');
$coid2 = COIDParser::fromString('coid://example.com/Example/1.0');
$coid3 = COIDParser::fromString('example.com/Example/1.0');
$this->assertTrue($coid1->equals($coid2));
$this->assertTrue($coid1->equals($coid3));
}
public function testNormalizeRootFromString() {
$coid1 = new IRI('coid://example.com');
$coid2 = COIDParser::fromString('COID://example.com');
$coid3 = COIDParser::fromString('ExAmple.COM');
$this->assertTrue($coid1->equals($coid2));
$this->assertTrue($coid1->equals($coid3));
}
public function testNormalizeNonRootFromString() {
$coid1 = new IRI('coid://example.com/Example');
$coid2 = COIDParser::fromString('COID://example.com/Example');
$coid3 = COIDParser::fromString('ExAmple.COM/Example');
$coid4 = COIDParser::fromString('ExAmple.COM/EXample');
$this->assertTrue($coid1->equals($coid2));
$this->assertTrue($coid1->equals($coid3));
$this->assertFalse($coid1->equals($coid4));
}
}

View File

@@ -0,0 +1,46 @@
<?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\Common;
use InvalidArgumentException;
use GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler,
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
use CloudObjects\SDK\ObjectRetriever;
class CryptoHelperTest extends \PHPUnit_Framework_TestCase {
private $retriever;
private $graph;
private function setMockResponse(Response $response) {
$mock = new MockHandler([$response]);
$handler = HandlerStack::create($mock);
$this->retriever->setClient(new Client(['handler' => $handler]));
}
public function setUp() {
$this->retriever = new ObjectRetriever([
'auth_ns' => 'test.cloudobjects.io',
'auth_secret' => 'TEST'
]);
}
public function testEncryptDecrypt() {
$this->setMockResponse(new Response(200,
[ 'Content-Type' => 'application/ld+json' ],
'{"@context":{"common":"coid:\/\/common.cloudobjects.io\/"},"@id":"coid:\/\/test.cloudobjects.io","common:usesSharedEncryptionKey": "def0000092c63296feb07f6b44f323351ab2e570fb04c2dff73c3119fd1103234ea03f5af094d33e8fb5122c5cf73f745957a5f8f47b4fc3c43bc86fb631969f4c591831"}'));
$cryptoHelper = new CryptoHelper($this->retriever);
$cleartext = "CLEARTEXT";
$ciphertext = $cryptoHelper->encryptWithSharedEncryptionKey($cleartext);
$encryptedDecryptedText = $cryptoHelper->decryptWithSharedEncryptionKey($ciphertext);
$this->assertEquals($cleartext, $encryptedDecryptedText);
}
}

View File

@@ -0,0 +1,175 @@
<?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\JSON;
use InvalidArgumentException;
use ML\JsonLD\JsonLD;
use CloudObjects\SDK\ObjectRetriever;
class SchemaValidatorTest extends \PHPUnit_Framework_TestCase {
private $schemaValidator;
private $graph;
public function setUp() {
$this->schemaValidator = new SchemaValidator(new ObjectRetriever);
$this->graph = JsonLD::getDocument('{}')->getGraph();
}
public function testString() {
$node = $this->graph->createNode();
$node->setType($this->graph->createNode('coid://json.co-n.net/String'));
$this->schemaValidator->validateAgainstNode("Test", $node);
}
public function testNotString() {
$this->setExpectedException(InvalidArgumentException::class);
$node = $this->graph->createNode();
$node->setType($this->graph->createNode('coid://json.co-n.net/String'));
$this->schemaValidator->validateAgainstNode(9, $node);
}
public function testNumber() {
$node = $this->graph->createNode();
$node->setType($this->graph->createNode('coid://json.co-n.net/Number'));
$this->schemaValidator->validateAgainstNode(3.5, $node);
}
public function testNotNumber() {
$this->setExpectedException(InvalidArgumentException::class);
$node = $this->graph->createNode();
$node->setType($this->graph->createNode('coid://json.co-n.net/Number'));
$this->schemaValidator->validateAgainstNode("ABC", $node);
}
public function testInteger() {
$node = $this->graph->createNode();
$node->setType($this->graph->createNode('coid://json.co-n.net/Integer'));
$this->schemaValidator->validateAgainstNode(12, $node);
}
public function testNotInteger() {
$this->setExpectedException(InvalidArgumentException::class);
$node = $this->graph->createNode();
$node->setType($this->graph->createNode('coid://json.co-n.net/Integer'));
$this->schemaValidator->validateAgainstNode(1.4, $node);
}
public function testArray() {
$node = $this->graph->createNode();
$node->setType($this->graph->createNode('coid://json.co-n.net/Array'));
$this->schemaValidator->validateAgainstNode([ 1, 2, "foo" ], $node);
}
public function testNotArray() {
$this->setExpectedException(InvalidArgumentException::class);
$node = $this->graph->createNode();
$node->setType($this->graph->createNode('coid://json.co-n.net/Array'));
$this->schemaValidator->validateAgainstNode("NANANA", $node);
}
public function testObject() {
$node = $this->graph->createNode();
$node->setType($this->graph->createNode('coid://json.co-n.net/Object'));
$this->schemaValidator->validateAgainstNode([
'a' => 'A',
'b' => 'B'
], $node);
}
public function testNotObject() {
$this->setExpectedException(InvalidArgumentException::class);
$node = $this->graph->createNode();
$node->setType($this->graph->createNode('coid://json.co-n.net/Object'));
$this->schemaValidator->validateAgainstNode(5, $node);
}
public function testObjectWithProperty() {
$stringNode = $this->graph->createNode();
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
$stringNode->setType($this->graph->createNode('coid://json.co-n.net/String'));
$node = $this->graph->createNode();
$node->setType($this->graph->createNode('coid://json.co-n.net/Object'));
$node->setProperty('coid://json.co-n.net/hasProperty', $stringNode);
$this->schemaValidator->validateAgainstNode([
'a' => 'A',
'b' => 'B'
], $node);
}
public function testObjectWithPropertyTypeError() {
$this->setExpectedException(InvalidArgumentException::class);
$stringNode = $this->graph->createNode();
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
$stringNode->setType($this->graph->createNode('coid://json.co-n.net/String'));
$node = $this->graph->createNode();
$node->setType($this->graph->createNode('coid://json.co-n.net/Object'));
$node->setProperty('coid://json.co-n.net/hasProperty', $stringNode);
$this->schemaValidator->validateAgainstNode([
'a' => 0,
'b' => 'B'
], $node);
}
public function testObjectWithRequiredProperty() {
$stringNode = $this->graph->createNode();
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
$stringNode->setProperty('coid://json.co-n.net/isRequired', 'true');
$stringNode->setType($this->graph->createNode('coid://json.co-n.net/String'));
$node = $this->graph->createNode();
$node->setType($this->graph->createNode('coid://json.co-n.net/Object'));
$node->setProperty('coid://json.co-n.net/hasProperty', $stringNode);
$this->schemaValidator->validateAgainstNode([
'a' => 'A',
'b' => 'B'
], $node);
}
public function testObjectWithRequiredPropertyTypeError() {
$this->setExpectedException(InvalidArgumentException::class);
$stringNode = $this->graph->createNode();
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
$stringNode->setProperty('coid://json.co-n.net/isRequired', 'true');
$stringNode->setType($this->graph->createNode('coid://json.co-n.net/String'));
$node = $this->graph->createNode();
$node->setType($this->graph->createNode('coid://json.co-n.net/Object'));
$node->setProperty('coid://json.co-n.net/hasProperty', $stringNode);
$this->schemaValidator->validateAgainstNode([
'a' => 0,
'b' => 'B'
], $node);
}
public function testObjectWithRequiredPropertyMissing() {
$this->setExpectedException(InvalidArgumentException::class);
$stringNode = $this->graph->createNode();
$stringNode->setProperty('coid://json.co-n.net/hasKey', 'a');
$stringNode->setProperty('coid://json.co-n.net/isRequired', 'true');
$stringNode->setType($this->graph->createNode('coid://json.co-n.net/String'));
$node = $this->graph->createNode();
$node->setType($this->graph->createNode('coid://json.co-n.net/Object'));
$node->setProperty('coid://json.co-n.net/hasProperty', $stringNode);
$this->schemaValidator->validateAgainstNode([
'b' => 'B',
'c' => 'C'
], $node);
}
}

View File

@@ -0,0 +1,156 @@
<?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 GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler,
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
class NodeReaderMockTest extends \PHPUnit_Framework_TestCase {
private $retriever;
private $reader;
private function setMockResponse(Response $response) {
$mock = new MockHandler([$response]);
$handler = HandlerStack::create($mock);
$this->retriever->setClient(new Client(['handler' => $handler]));
}
private function useRootResourceMock() {
$this->setMockResponse(new Response(200,
['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"}'));
}
protected function setUp() {
$this->retriever = new ObjectRetriever;
$this->reader = new NodeReader([
'prefixes' => [
'co' => 'coid://cloudobjects.io/',
'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#'
]
]);
}
public function testHasType1() {
$coid = new IRI('coid://cloudobjects.io');
$this->useRootResourceMock();
$object = $this->retriever->getObject($coid);
$this->assertTrue($this->reader->hasType($object, 'coid://cloudobjects.io/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, 'co:MemberRole'));
}
public function testHasPropertyValue1() {
$coid = new IRI('coid://cloudobjects.io');
$this->useRootResourceMock();
$object = $this->retriever->getObject($coid);
$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'));
}
public function testGetFirstValueString1() {
$coid = new IRI('coid://cloudobjects.io');
$this->useRootResourceMock();
$object = $this->retriever->getObject($coid);
$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->assertNull($this->reader->getFirstValueString($object, 'coid://cloudobjects.io/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, 'co:makesTriplesVisibleTo', 'theDefaultValue'));
}
public function testGetFirstValueIRI1() {
$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->assertInstanceOf('ML\IRI\IRI', $this->reader->getFirstValueIRI($object, 'co:isVisibleTo'));
$this->assertEquals(new IRI('coid://cloudobjects.io/Public'), $this->reader->getFirstValueIRI($object, 'coid://cloudobjects.io/isVisibleTo'));
$this->assertEquals(new IRI('coid://cloudobjects.io/Public'), $this->reader->getFirstValueIRI($object, 'co:isVisibleTo'));
}
public function testGetFirstValueNode1() {
$coid = new IRI('coid://cloudobjects.io');
$this->useRootResourceMock();
$object = $this->retriever->getObject($coid);
$this->assertInstanceOf('ML\JsonLD\Node', $this->reader->getFirstValueNode($object, 'coid://cloudobjects.io/isVisibleTo'));
$this->assertInstanceOf('ML\JsonLD\Node', $this->reader->getFirstValueNode($object, 'co:isVisibleTo'));
$this->assertEquals('coid://cloudobjects.io/Public', $this->reader->getFirstValueNode($object, 'coid://cloudobjects.io/isVisibleTo')->getId());
$this->assertEquals('coid://cloudobjects.io/Public', $this->reader->getFirstValueNode($object, 'co:isVisibleTo')->getId());
}
public function testGetAllValuesString1() {
$coid = new IRI('coid://cloudobjects.io');
$this->useRootResourceMock();
$object = $this->retriever->getObject($coid);
$this->assertCount(1, $this->reader->getAllValuesString($object, 'http://www.w3.org/2000/01/rdf-schema#label'));
$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->assertEquals('CloudObjects', $this->reader->getAllValuesString($object, 'rdfs:label')[0]);
$this->assertCount(0, $this->reader->getAllValuesString($object, 'coid://cloudobjects.io/makesTriplesVisibleTo'));
$this->assertCount(0, $this->reader->getAllValuesString($object, 'co:makesTriplesVisibleTo'));
$this->assertCount(2, $this->reader->getAllValuesString($object, '@type'));
}
public function testGetAllValuesIRI1() {
$coid = new IRI('coid://cloudobjects.io');
$this->useRootResourceMock();
$object = $this->retriever->getObject($coid);
$this->assertCount(0, $this->reader->getAllValuesIRI($object, 'http://www.w3.org/2000/01/rdf-schema#label'));
$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('ML\IRI\IRI', $this->reader->getAllValuesIRI($object, 'coid://cloudobjects.io/isVisibleTo')[0]);
$this->assertInstanceOf('ML\IRI\IRI', $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->getObject($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('ML\JsonLD\Node', $this->reader->getAllValuesNode($object, 'coid://cloudobjects.io/isVisibleTo')[0]);
$this->assertInstanceOf('ML\JsonLD\Node', $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());
}
}

View File

@@ -0,0 +1,40 @@
<?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 GuzzleHttp\Client, GuzzleHttp\Handler\MockHandler,
GuzzleHttp\HandlerStack, GuzzleHttp\Psr7\Response;
class ObjectRetrieverMockTest extends \PHPUnit_Framework_TestCase {
private $retriever;
private function setMockResponse(Response $response) {
$mock = new MockHandler([$response]);
$handler = HandlerStack::create($mock);
$this->retriever->setClient(new Client(['handler' => $handler]));
}
protected function setUp() {
$this->retriever = new ObjectRetriever;
}
public function testGetRootResource() {
$this->setMockResponse(new Response(200,
['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"}'));
$coid = new IRI('coid://cloudobjects.io');
$object = $this->retriever->getObject($coid);
$this->assertNotNull($object);
$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());
}
}