Skip to content

Commit

Permalink
Merge pull request #24 from ruebot/issue-8
Browse files Browse the repository at this point in the history
Implement getResourceOptions -- Address #8
  • Loading branch information
daniel-dgi committed Dec 7, 2015
2 parents 33edb8f + 2d95fb3 commit 0d65aae
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Chullo.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ public function getResourceHeaders($uri = "",
return $response->getHeaders();
}

/**
* Gets information about the supported HTTP methods, etc., for a Fedora resource.
*
* @param string $uri Resource URI
*
* @return string Options of a resource.
*/
public function getResourceOptions($uri = "") {
$response = $this->client->request(
'OPTIONS',
$uri
);

return $response->getHeaders();
}

/**
* Gets RDF metadata from Fedora.
*
Expand Down
9 changes: 9 additions & 0 deletions src/IFedoraClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ public function getResource($uri = "",
*/
public function getResourceHeaders($uri = "",
$transaction = "");
/**
* Gets information about the supported HTTP methods, etc., for a Fedora resource.
*
* @param string $uri Resource URI
*
* @return string Options of a resource.
*/
public function getResourceOptions($uri = "");

/**
* Gets RDF metadata from Fedora.
*
Expand Down
27 changes: 27 additions & 0 deletions test/GetResourceOptionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Islandora\Chullo\Chullo;

class GetResourceOptionsTest extends \PHPUnit_Framework_TestCase {

/**
* @covers Islandora\Fedora\Chullo::getResourceOptions
* @uses GuzzleHttp\Client
*/
public function testReturnsHeadersOn200() {
$mock = new MockHandler([
new Response(200, ['Status: 200 OK', 'Accept-Patch: application/sparql-update', 'Allow: MOVE,COPY,DELETE,POST,HEAD,GET,PUT,PATCH,OPTIONS', 'Accept-Post: text/turtle,text/rdf+n3,application/n3,text/n3,application/rdf+xml,application/n-triples,multipart/form-data,application/sparql-update']),
]);

$handler = HandlerStack::create($mock);
$guzzle = new Client(['handler' => $handler, 'base_uri' => 'http://localhost:8080/fcrepo/rest']);
$client = new Chullo($guzzle);

$result = $client->getResourceOptions("");
$this->assertSame((array)$result, [['Status: 200 OK'], ['Accept-Patch: application/sparql-update'], ['Allow: MOVE,COPY,DELETE,POST,HEAD,GET,PUT,PATCH,OPTIONS'], ['Accept-Post: text/turtle,text/rdf+n3,application/n3,text/n3,application/rdf+xml,application/n-triples,multipart/form-data,application/sparql-update']]);
}
}

0 comments on commit 0d65aae

Please sign in to comment.