-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add createVersion method and interface * add a getVersions method, instead of passing in the versioning URI, pass in the resource URI * get timemap uri from headers * move getting the timemap uri from the headers so a separate function so we don't have to repeat it in createVersion and getVersion * allow for content to be passed for createversion method * update docs to specify datetime format * simplifying/improving to use trim instead of str_replace and array_search instead of a loop and if statement * phpcs fixes, adding test for getTimemapURI, and making it public * other phpcs fixes * move trim inside if, makes more sense * check for null timemapURI and check body and timestamp together * rename test * add getVersions test * add createVersion test * add dev branch to travis * update createVersion test * adding test for getBaseUri and adding doc comments * adding optional params for createVersion test to be sure that it tests that scenario also
- Loading branch information
Showing
7 changed files
with
303 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ matrix: | |
branches: | ||
only: | ||
- /master/ | ||
- /^dev/ | ||
|
||
before_install: | ||
- export SCRIPT_DIR=$HOME/CLAW/.scripts | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Islandora\Chullo; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Handler\MockHandler; | ||
use GuzzleHttp\HandlerStack; | ||
use GuzzleHttp\Psr7\Response; | ||
use Islandora\Chullo\FedoraApi; | ||
use \RuntimeException; | ||
use \DateTime; | ||
|
||
class CreateVersionTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
/** | ||
* @covers Islandora\Chullo\FedoraApi::createVersion | ||
* @uses GuzzleHttp\Client | ||
*/ | ||
public function testReturns201withVersions() | ||
{ | ||
$mock = new MockHandler( | ||
[ | ||
new Response(200, ['Link' => '<http://localhost:8080/rest/path/to/resource/fcr:versions>;rel="timemap"']), | ||
new Response(201, ['Location' => "SOME URI"]) | ||
] | ||
); | ||
|
||
$handler = HandlerStack::create($mock); | ||
$guzzle = new Client(['handler' => $handler]); | ||
$api = new FedoraApi($guzzle); | ||
$date = new DateTime(); | ||
$timestamp = $date->format("D, d M Y H:i:s O"); | ||
$content = "test"; | ||
$result = $api->createVersion('', $timestamp, $content); | ||
$this->assertEquals(201, $result->getStatusCode()); | ||
} | ||
|
||
/** | ||
* @covers Islandora\Chullo\FedoraApi::createVersion Exception | ||
* @uses GuzzleHttp\Client | ||
*/ | ||
public function testThrowsExceptionWithoutTimemapUri() | ||
{ | ||
$mock = new MockHandler( | ||
[ | ||
new Response(200, []), | ||
new Response(201, ['Location' => "SOME URI"]) | ||
] | ||
); | ||
|
||
$handler = HandlerStack::create($mock); | ||
$guzzle = new Client(['handler' => $handler]); | ||
$api = new FedoraApi($guzzle); | ||
|
||
$this->expectException(\RuntimeException::class); | ||
$result = $api->createVersion(''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Islandora\Chullo; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Handler\MockHandler; | ||
use GuzzleHttp\HandlerStack; | ||
use GuzzleHttp\Psr7\Response; | ||
use Islandora\Chullo\FedoraApi; | ||
|
||
class GetBaseUriTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
/** | ||
* @covers Islandora\Chullo\FedoraApi::getBaseUri | ||
* @uses GuzzleHttp\Client | ||
*/ | ||
public function testReturnsUri() | ||
{ | ||
$guzzle = new Client(['base_uri'=>'http://localhost:8080/fcrepo/rest']); | ||
$api = new FedoraApi($guzzle); | ||
|
||
$baseUri = $api->getBaseUri(); | ||
$this->assertEquals($baseUri, 'http://localhost:8080/fcrepo/rest'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Islandora\Chullo; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Handler\MockHandler; | ||
use GuzzleHttp\HandlerStack; | ||
use GuzzleHttp\Psr7\Response; | ||
use Islandora\Chullo\FedoraApi; | ||
|
||
class GetTimemapURITest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
/** | ||
* @covers Islandora\Chullo\FedoraApi::getTimemapURI | ||
* @uses GuzzleHttp\Client | ||
*/ | ||
public function testReturnsTimemapHeaderOn200() | ||
{ | ||
|
||
$headers = [ | ||
'Status' => '200 OK', | ||
'ETag' => "bbdd92e395800153a686773f773bcad80a51f47b", | ||
'Last-Modified' => 'Wed, 28 May 2014 18:31:36 GMT', | ||
'Link' => '<http://www.w3.org/ns/ldp#Resource>;rel="type"', | ||
'Link' => '<http://www.w3.org/ns/ldp#Container>;rel="type"', | ||
'Link' => '<http://localhost:8080/rest/path/to/resource/fcr:versions>;rel="timemap"', | ||
]; | ||
|
||
$mock = new MockHandler( | ||
[ | ||
new Response(200, $headers) | ||
] | ||
); | ||
|
||
$handler = HandlerStack::create($mock); | ||
$guzzle = new Client(['handler' => $handler]); | ||
$api = new FedoraApi($guzzle); | ||
|
||
$timemapuri = $api->getTimemapURI(""); | ||
|
||
$this->assertEquals("http://localhost:8080/rest/path/to/resource/fcr:versions", $timemapuri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Islandora\Chullo; | ||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Handler\MockHandler; | ||
use GuzzleHttp\HandlerStack; | ||
use GuzzleHttp\Psr7\Response; | ||
use Islandora\Chullo\FedoraApi; | ||
use \RuntimeException; | ||
|
||
class GetVersionsTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
/** | ||
* @covers Islandora\Chullo\FedoraApi::getVersions | ||
* @uses GuzzleHttp\Client | ||
*/ | ||
public function testReturnsVersionsOn200() | ||
{ | ||
|
||
$headers = [ | ||
'Status' => '200 OK', | ||
'Link' => '<http://localhost:8080/rest/path/to/resource/fcr:versions>;rel="timemap"' | ||
]; | ||
|
||
$mock = new MockHandler( | ||
[ | ||
new Response(200, $headers), | ||
new Response(200, $headers) | ||
] | ||
); | ||
|
||
$handler = HandlerStack::create($mock); | ||
$guzzle = new Client(['handler' => $handler]); | ||
$api = new FedoraApi($guzzle); | ||
|
||
$result = $api->getVersions(); | ||
|
||
$this->assertEquals(200, $result->getStatusCode()); | ||
} | ||
|
||
/** | ||
* @covers Islandora\Chullo\FedoraApi::getVersions Exception | ||
* @uses GuzzleHttp\Client | ||
*/ | ||
public function testThrowErrorWithNoTimemapURI() | ||
{ | ||
$headers = [ | ||
'Status' => '200 OK' | ||
]; | ||
|
||
$mock = new MockHandler( | ||
[ | ||
new Response(200, $headers) | ||
] | ||
); | ||
$handler = HandlerStack::create($mock); | ||
$guzzle = new Client(['handler' => $handler]); | ||
$api = new FedoraApi($guzzle); | ||
|
||
$this->expectException(\RuntimeException::class); | ||
$result = $api->getVersions(); | ||
} | ||
} |