-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
349 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
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,47 @@ | ||
<?php | ||
|
||
namespace spec\Scriptotek\Alma\CodeTable; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
use Scriptotek\Alma\Conf\CodeTable; | ||
use Scriptotek\Alma\Conf\CodeTables; | ||
use Scriptotek\Alma\Client as AlmaClient; | ||
use Scriptotek\Alma\Exception\ResourceNotFound; | ||
use spec\Scriptotek\Alma\SpecHelper; | ||
|
||
class CodeTableSpec extends ObjectBehavior | ||
{ | ||
public function let(AlmaClient $client) | ||
{ | ||
$this->beConstructedWith($client, 'systemJobStatus'); | ||
} | ||
|
||
protected function expectRequest($client) | ||
{ | ||
$client->getXML('/conf/code-table/systemJobStatus') | ||
->shouldBeCalled() | ||
->willReturn(SpecHelper::getDummyData('codetable_response.json')); | ||
} | ||
|
||
public function it_is_lazy(AlmaClient $client) | ||
{ | ||
SpecHelper::expectNoRequests($client); | ||
$this->shouldHaveType(CodeTable::class); | ||
} | ||
|
||
public function it_fetches_record_data_when_needed(AlmaClient $client) | ||
{ | ||
$this->expectRequest($client); | ||
|
||
$this->name->('systemJobStatus'); | ||
$this->subSystem->value->shouldBe('INFRA'); | ||
} | ||
|
||
public function it_can_exist(AlmaClient $client) | ||
{ | ||
$this->expectRequest($client); | ||
|
||
$this->exists()->shouldBe(true); | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace spec\Scriptotek\Alma\CodeTables; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Prophecy\Argument; | ||
use Scriptotek\Alma\Conf\CodeTable; | ||
use Scriptotek\Alma\Client as AlmaClient; | ||
use spec\Scriptotek\Alma\SpecHelper; | ||
|
||
class CodeTablesSpec extends ObjectBehavior | ||
{ | ||
public function let(AlmaClient $client) | ||
{ | ||
$this->beConstructedWith($client); | ||
} | ||
|
||
public function it_provides_a_lazy_interface_to_codetable_objects(AlmaClient $client) | ||
{ | ||
SpecHelper::expectNoRequests($client); | ||
|
||
$ctid = 'myCodeTable'; // str_random(); | ||
$bib = $this->get($ctid); | ||
|
||
$bib->shouldHaveType(CodeTable::class); | ||
$bib->code->shouldBe($ctid); | ||
} | ||
|
||
public function it_provides_a_lazy_array_interface_to_codetable_objects(AlmaClient $client) | ||
{ | ||
SpecHelper::expectNoRequests($client); | ||
|
||
$ctid = 'myCodeTable'; // str_random(); | ||
$ct = $this[$ctid]; | ||
|
||
$ct->shouldHaveType(CodeTable::class); | ||
$ct->code->shouldBe($ctid); | ||
} | ||
|
||
} |
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,109 @@ | ||
{ | ||
"name": "systemJobStatus", | ||
"description": "System Job Status", | ||
"sub_system": { | ||
"value": "INFRA", | ||
"desc": "Infra" | ||
}, | ||
"patron_facing": true, | ||
"language": { | ||
"value": "en", | ||
"desc": "English" | ||
}, | ||
"scope": { | ||
"institution_id": { | ||
"value": "01MY_INST", | ||
"desc": "My Institution" | ||
}, | ||
"library_id": { | ||
"value": "", | ||
"desc": "" | ||
} | ||
}, | ||
"row": [ | ||
{ | ||
"code": "QUEUED", | ||
"description": "Queued", | ||
"default": false, | ||
"enabled": true | ||
}, | ||
{ | ||
"code": "PENDING", | ||
"description": "Pending", | ||
"default": false, | ||
"enabled": true | ||
}, | ||
{ | ||
"code": "INITIALIZING", | ||
"description": "Initializing", | ||
"default": false, | ||
"enabled": true | ||
}, | ||
{ | ||
"code": "RUNNING", | ||
"description": "Running", | ||
"default": false, | ||
"enabled": true | ||
}, | ||
{ | ||
"code": "MANUAL_HANDLING_REQUIRED", | ||
"description": "Manual Handling Required", | ||
"default": false, | ||
"enabled": true | ||
}, | ||
{ | ||
"code": "FINALIZING", | ||
"description": "Finalizing", | ||
"default": false, | ||
"enabled": true | ||
}, | ||
{ | ||
"code": "COMPLETED_SUCCESS", | ||
"description": "Completed Successfully", | ||
"default": false, | ||
"enabled": true | ||
}, | ||
{ | ||
"code": "COMPLETED_NO_BULKS", | ||
"description": "Completed with no Bulks", | ||
"default": false, | ||
"enabled": true | ||
}, | ||
{ | ||
"code": "COMPLETED_FAILED", | ||
"description": "Completed with Errors", | ||
"default": false, | ||
"enabled": true | ||
}, | ||
{ | ||
"code": "FAILED", | ||
"description": "Failed", | ||
"default": false, | ||
"enabled": true | ||
}, | ||
{ | ||
"code": "COMPLETED_WARNING", | ||
"description": "Completed with Warnings", | ||
"default": false, | ||
"enabled": true | ||
}, | ||
{ | ||
"code": "USER_ABORTED", | ||
"description": "Aborted by User", | ||
"default": false, | ||
"enabled": true | ||
}, | ||
{ | ||
"code": "SYSTEM_ABORTED", | ||
"description": "Aborted by System", | ||
"default": false, | ||
"enabled": true | ||
}, | ||
{ | ||
"code": "SKIPPED", | ||
"description": "Skipped", | ||
"default": false, | ||
"enabled": true | ||
} | ||
] | ||
} |
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,69 @@ | ||
<?php | ||
|
||
namespace Scriptotek\Alma\Conf; | ||
|
||
use Scriptotek\Alma\Client; | ||
use Scriptotek\Alma\Model\LazyResource; | ||
|
||
/** | ||
* A single CodeTable resource. | ||
*/ | ||
class CodeTable extends LazyResource | ||
{ | ||
/** @var string */ | ||
public $code; | ||
|
||
/** | ||
* CodeTable constructor. | ||
* | ||
* @param Client $client | ||
* @param string $code | ||
*/ | ||
public function __construct(Client $client, $code) | ||
{ | ||
parent::__construct($client); | ||
$this->code = $code; | ||
} | ||
|
||
/** | ||
* Return a list of rows referring to the code of the rows in the table. | ||
* | ||
* @param string $code - The code of the row in the Table we want to pull. | ||
* | ||
* @return array $found - The rows in the code table that match the code passed in. | ||
*/ | ||
public function getRowByCode($code) | ||
{ | ||
$found = array(); | ||
$codeTable = json_decode($this->client->get($this->urlBase())); | ||
foreach ($codeTable->row as $row) { | ||
if ($row->code == $code) { | ||
array_push($found,$row); | ||
} | ||
} | ||
return($found); | ||
} | ||
|
||
/** | ||
* Check if we have the full representation of our data object. | ||
* | ||
* @param \stdClass $data | ||
* | ||
* @return bool | ||
*/ | ||
protected function isInitialized($data) | ||
{ | ||
return isset($data->name); | ||
} | ||
|
||
/** | ||
* Generate the base URL for this resource. | ||
* | ||
* @return string | ||
*/ | ||
protected function urlBase() | ||
{ | ||
return "/conf/code-tables/{$this->code}"; | ||
} | ||
|
||
} |
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 Scriptotek\Alma\Conf; | ||
|
||
use Scriptotek\Alma\Client; | ||
use Scriptotek\Alma\Model\ReadOnlyArrayAccess; | ||
|
||
/** | ||
* A non-iterable collection of CodeTable resources | ||
*/ | ||
class CodeTables implements \ArrayAccess | ||
{ | ||
use ReadOnlyArrayAccess; | ||
|
||
protected $client; | ||
|
||
/** | ||
* CodeTables constructor. | ||
* | ||
* @param Client $client | ||
*/ | ||
public function __construct(Client $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* Get a CodeTable by identifier | ||
* | ||
* @param $code The identifier of a CodeTable | ||
* | ||
* @return CodeTable | ||
*/ | ||
public function get($code) | ||
{ | ||
return CodeTable::make($this->client, $code); | ||
} | ||
|
||
/** | ||
* Return a object containing a list of code tables. | ||
* | ||
* @return CodeTable ojbect list. | ||
*/ | ||
public function getCodeTables() | ||
{ | ||
return json_decode($this->client->get($this->urlBase())); | ||
} | ||
|
||
/** | ||
* Generate the base URL for this resource. | ||
* | ||
* @return string | ||
*/ | ||
protected function urlBase() | ||
{ | ||
return '/conf/code-tables'; | ||
} | ||
|
||
} |
Oops, something went wrong.