1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Scriptotek\Alma\Bibs; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
use Prophecy\Argument; |
7
|
|
|
use Psr\Http\Message\UriInterface; |
8
|
|
|
use Scriptotek\Alma\Bibs\Bib; |
9
|
|
|
use Scriptotek\Alma\Bibs\Bibs; |
10
|
|
|
use Scriptotek\Alma\Bibs\Holding; |
11
|
|
|
use Scriptotek\Alma\Bibs\Holdings; |
12
|
|
|
use Scriptotek\Alma\Client as AlmaClient; |
13
|
|
|
use Scriptotek\Alma\Exception\ResourceNotFound; |
14
|
|
|
use Scriptotek\Marc\Record; |
15
|
|
|
use spec\Scriptotek\Alma\SpecHelper; |
16
|
|
|
|
17
|
|
|
class BibSpec extends ObjectBehavior |
18
|
|
|
{ |
19
|
|
|
public function let(AlmaClient $client, UriInterface $url) |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
$mms_id = '999104760474702204'; |
22
|
|
|
$this->beConstructedWith($client, $mms_id); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
protected function expectRequest($client, $url) { |
26
|
|
|
$client->buildUrl('/bibs/999104760474702204', []) |
27
|
|
|
->shouldBeCalled() |
28
|
|
|
->willReturn($url); |
29
|
|
|
|
30
|
|
|
$client->getJSON($url) |
31
|
|
|
->shouldBeCalled() |
32
|
|
|
->willReturn(SpecHelper::getDummyData('bib_response_iz.json')); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function it_is_lazy(AlmaClient $client) |
36
|
|
|
{ |
37
|
|
|
SpecHelper::expectNoRequests($client); |
38
|
|
|
$this->shouldHaveType(Bib::class); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function it_loads_bib_data_when_needed(AlmaClient $client, UriInterface $url) |
42
|
|
|
{ |
43
|
|
|
$this->expectRequest($client, $url); |
44
|
|
|
|
45
|
|
|
$this->created_date->shouldBe('2015-11-05Z'); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function it_loads_bib_data_when_needed2(AlmaClient $client, UriInterface $url) |
49
|
|
|
{ |
50
|
|
|
$this->expectRequest($client, $url); |
51
|
|
|
|
52
|
|
|
$this->exists()->shouldBe(true); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function it_links_to_network_zone(AlmaClient $client, AlmaClient $nz, Bibs $bibs, Bib $nz_bib, UriInterface $url) |
56
|
|
|
{ |
57
|
|
|
$this->expectRequest($client, $url); |
58
|
|
|
|
59
|
|
|
$client->nz = $nz; |
60
|
|
|
$nz->bibs = $bibs; |
61
|
|
|
$bibs->get('999104760474702201') |
62
|
|
|
->shouldBeCalled() |
63
|
|
|
->willReturn($nz_bib); |
64
|
|
|
|
65
|
|
|
$this->getNzRecord()->shouldHaveType(Bib::class); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function it_provides_lazy_access_to_holdings(AlmaClient $client) |
69
|
|
|
{ |
70
|
|
|
SpecHelper::expectNoRequests($client); |
71
|
|
|
$this->holdings->shouldHaveType(Holdings::class); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function it_has_a_MARC_record(AlmaClient $client, UriInterface $url) |
75
|
|
|
{ |
76
|
|
|
$this->expectRequest($client, $url); |
77
|
|
|
|
78
|
|
|
$this->record->shouldHaveType(Record::class); |
|
|
|
|
79
|
|
|
$this->record->getField('245')->getSubfield('a')->getData()->shouldBe('Lonely hearts of the cosmos :'); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function it_can_be_edited(AlmaClient $client, UriInterface $url) |
83
|
|
|
{ |
84
|
|
|
$this->expectRequest($client, $url); |
85
|
|
|
|
86
|
|
|
$this->record->getField('245')->getSubfield('a')->setData('New title'); |
|
|
|
|
87
|
|
|
|
88
|
|
|
$client->putJSON('/bibs/999104760474702204', Argument::containingString('New title')) |
89
|
|
|
->shouldBeCalled(); |
90
|
|
|
$this->save(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function it_catches_resource_not_found(AlmaClient $client, UriInterface $url) |
94
|
|
|
{ |
95
|
|
|
$client->buildUrl('/bibs/999104760474702204', []) |
96
|
|
|
->shouldBeCalled() |
97
|
|
|
->willReturn($url); |
98
|
|
|
|
99
|
|
|
$client->getJSON($url) |
100
|
|
|
->shouldBeCalled() |
101
|
|
|
->willThrow(ResourceNotFound::class); |
102
|
|
|
|
103
|
|
|
$this->exists()->shouldBe(false); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.