1
|
|
|
<?php namespace Scriptotek\Sru; |
2
|
|
|
|
3
|
|
|
use GuzzleHttp\Psr7\Response as HttpResponse; |
4
|
|
|
use function GuzzleHttp\Psr7\stream_for; |
5
|
|
|
use Mockery as m; |
|
|
|
|
6
|
|
|
use Http\Mock\Client as MockHttp; |
7
|
|
|
|
8
|
|
|
class ClientTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
protected $url = 'http://sru.my_fictive_host.net'; |
11
|
|
|
|
12
|
|
|
protected $simple_response = '<?xml version="1.0" encoding="UTF-8" ?> |
13
|
|
|
<srw:searchRetrieveResponse xmlns:srw="http://www.loc.gov/zing/srw/" xmlns:xcql="http://www.loc.gov/zing/cql/xcql/"> |
14
|
|
|
</srw:searchRetrieveResponse>'; |
15
|
|
|
|
16
|
|
|
protected $simple_explain_response = '<?xml version="1.0" encoding="UTF-8"?> |
17
|
|
|
<sru:explainResponse xmlns:sru="http://www.loc.gov/zing/srw/"> |
18
|
|
|
</sru:explainResponse>'; |
19
|
|
|
|
20
|
|
|
public function testUrlTo() |
21
|
|
|
{ |
22
|
|
|
$sru1 = new Client($this->url); |
23
|
|
|
$expectedUrl1 = $this->url . '?operation=searchRetrieve&version=1.1&recordSchema=marcxml&maximumRecords=10&query=isbn%3D123'; |
24
|
|
|
$expectedUrl2 = $this->url . '?operation=searchRetrieve&version=1.1&recordSchema=marcxml&maximumRecords=50&query=isbn%3D123&startRecord=2'; |
25
|
|
|
$expectedUrl5 = $this->url . '?operation=searchRetrieve&version=1.1&recordSchema=marcxml&maximumRecords=10&query=isbn%3D123&httpAccept=application%2Fxml'; |
26
|
|
|
|
27
|
|
|
$sru3 = new Client($this->url, array('schema' => 'CUSTOMSCHEMA')); |
28
|
|
|
$expectedUrl3 = $this->url . '?operation=searchRetrieve&version=1.1&recordSchema=CUSTOMSCHEMA&maximumRecords=10&query=isbn%3D123'; |
29
|
|
|
|
30
|
|
|
$sru4 = new Client($this->url, array('version' => '0.9')); |
31
|
|
|
$expectedUrl4 = $this->url . '?operation=searchRetrieve&version=0.9&recordSchema=marcxml&maximumRecords=10&query=isbn%3D123'; |
32
|
|
|
|
33
|
|
|
$this->assertEquals($expectedUrl1, $sru1->urlTo('isbn=123')); |
34
|
|
|
$this->assertEquals($expectedUrl2, $sru1->urlTo('isbn=123', 2, 50)); |
35
|
|
|
$this->assertEquals($expectedUrl3, $sru3->urlTo('isbn=123')); |
36
|
|
|
$this->assertEquals($expectedUrl4, $sru4->urlTo('isbn=123')); |
37
|
|
|
$this->assertEquals($expectedUrl5, $sru1->urlTo('isbn=123', 1, 10, array('httpAccept' => 'application/xml'))); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testSearch() |
41
|
|
|
{ |
42
|
|
|
$http = $this->httpMockWithResponses($this->simple_response); |
43
|
|
|
$sru = new Client($this->url, null, $http); |
44
|
|
|
|
45
|
|
|
$this->assertXmlStringEqualsXmlString( |
46
|
|
|
$this->simple_response, |
47
|
|
|
$sru->search('test')->asXml() |
|
|
|
|
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testNext() |
52
|
|
|
{ |
53
|
|
|
$cql = 'dc.title="Joda jada isjda"'; |
54
|
|
|
|
55
|
|
|
$http = new MockHttp(); |
56
|
|
|
$http->addResponse( |
57
|
|
|
(new HttpResponse()) |
58
|
|
|
->withBody(stream_for('<?xml version="1.0" encoding="UTF-8" ?> |
|
|
|
|
59
|
|
|
<srw:searchRetrieveResponse |
60
|
|
|
xmlns:srw="http://www.loc.gov/zing/srw/" |
61
|
|
|
xmlns:xcql="http://www.loc.gov/zing/cql/xcql/" |
62
|
|
|
> |
63
|
|
|
<srw:version>1.1</srw:version> |
64
|
|
|
<srw:numberOfRecords>3</srw:numberOfRecords> |
65
|
|
|
<srw:records> |
66
|
|
|
<srw:record> |
67
|
|
|
<srw:recordSchema>marcxchange</srw:recordSchema> |
68
|
|
|
<srw:recordPacking>xml</srw:recordPacking> |
69
|
|
|
<srw:recordPosition>1</srw:recordPosition> |
70
|
|
|
<srw:recordData>Record 1</srw:recordData> |
71
|
|
|
</srw:record> |
72
|
|
|
<srw:record> |
73
|
|
|
<srw:recordSchema>marcxchange</srw:recordSchema> |
74
|
|
|
<srw:recordPacking>xml</srw:recordPacking> |
75
|
|
|
<srw:recordPosition>2</srw:recordPosition> |
76
|
|
|
<srw:recordData>Record 2</srw:recordData> |
77
|
|
|
</srw:record> |
78
|
|
|
</srw:records> |
79
|
|
|
<srw:nextRecordPosition>3</srw:nextRecordPosition> |
80
|
|
|
<srw:echoedSearchRetrieveRequest> |
81
|
|
|
<srw:operation>searchRetrieve</srw:operation> |
82
|
|
|
<srw:version>1.1</srw:version> |
83
|
|
|
<srw:query>\' . $cql . \'</srw:query> |
84
|
|
|
<srw:startRecord>1</srw:startRecord> |
85
|
|
|
<srw:maximumRecords>2</srw:maximumRecords> |
86
|
|
|
<srw:recordSchema>marcxchange</srw:recordSchema> |
87
|
|
|
</srw:echoedSearchRetrieveRequest> |
88
|
|
|
<srw:extraResponseData> |
89
|
|
|
<responseDate>2014-03-28T12:09:50Z</responseDate> |
90
|
|
|
</srw:extraResponseData> |
91
|
|
|
</srw:searchRetrieveResponse> |
92
|
|
|
') |
93
|
|
|
) |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
$sru = new Client($this->url, null, $http); |
97
|
|
|
$response = $sru->search($cql); |
|
|
|
|
98
|
|
|
$this->assertCount(2, $response->records); |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
$http->addResponse( |
102
|
|
|
(new HttpResponse()) |
103
|
|
|
->withBody(stream_for('<?xml version="1.0" encoding="UTF-8" ?> |
|
|
|
|
104
|
|
|
<srw:searchRetrieveResponse |
105
|
|
|
xmlns:srw="http://www.loc.gov/zing/srw/" |
106
|
|
|
xmlns:xcql="http://www.loc.gov/zing/cql/xcql/" |
107
|
|
|
> |
108
|
|
|
<srw:version>1.1</srw:version> |
109
|
|
|
<srw:numberOfRecords>3</srw:numberOfRecords> |
110
|
|
|
<srw:records> |
111
|
|
|
<srw:record> |
112
|
|
|
<srw:recordSchema>marcxchange</srw:recordSchema> |
113
|
|
|
<srw:recordPacking>xml</srw:recordPacking> |
114
|
|
|
<srw:recordPosition>3</srw:recordPosition> |
115
|
|
|
<srw:recordData>Record 3</srw:recordData> |
116
|
|
|
</srw:record> |
117
|
|
|
</srw:records> |
118
|
|
|
<srw:echoedSearchRetrieveRequest> |
119
|
|
|
<srw:operation>searchRetrieve</srw:operation> |
120
|
|
|
<srw:version>1.1</srw:version> |
121
|
|
|
<srw:query>' . $cql . '</srw:query> |
122
|
|
|
<srw:startRecord>3</srw:startRecord> |
123
|
|
|
<srw:maximumRecords>2</srw:maximumRecords> |
124
|
|
|
<srw:recordSchema>marcxchange</srw:recordSchema> |
125
|
|
|
</srw:echoedSearchRetrieveRequest> |
126
|
|
|
<srw:extraResponseData> |
127
|
|
|
<responseDate>2014-03-28T12:09:50Z</responseDate> |
128
|
|
|
</srw:extraResponseData> |
129
|
|
|
</srw:searchRetrieveResponse> |
130
|
|
|
')) |
131
|
|
|
); |
132
|
|
|
|
133
|
|
|
$response = $response->next(); |
134
|
|
|
$this->assertCount(1, $response->records); |
135
|
|
|
|
136
|
|
|
$response = $response->next(); |
137
|
|
|
$this->assertNull($response); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function testHttpHeaders() |
141
|
|
|
{ |
142
|
|
|
$sru1 = new Client($this->url, array( |
143
|
|
|
'user-agent' => 'Blablabla/0.1', |
144
|
|
|
)); |
145
|
|
|
|
146
|
|
|
$opts = $sru1->headers; |
147
|
|
|
|
148
|
|
|
$this->assertEquals('application/xml', $opts['Accept']); |
149
|
|
|
$this->assertEquals('Blablabla/0.1', $opts['User-Agent']); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function testRecords() |
153
|
|
|
{ |
154
|
|
|
$http = $this->httpMockWithResponses($this->makeDummyResponse(1)); |
155
|
|
|
|
156
|
|
|
$sru1 = new Client($this->url, [], $http); |
157
|
|
|
$r = $sru1->records('test', 1); |
|
|
|
|
158
|
|
|
|
159
|
|
|
$this->assertInstanceOf('Scriptotek\Sru\Records', $r); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function testExplain() |
163
|
|
|
{ |
164
|
|
|
$http = $this->httpMockWithResponses($this->simple_explain_response); |
165
|
|
|
$sru = new Client($this->url, null, $http); |
166
|
|
|
$exp = $sru->explain(); |
167
|
|
|
|
168
|
|
|
$this->assertInstanceOf('Scriptotek\Sru\ExplainResponse', $exp); |
169
|
|
|
|
170
|
|
|
$this->assertXmlStringEqualsXmlString( |
171
|
|
|
$this->simple_explain_response, |
172
|
|
|
$exp->asXml() |
173
|
|
|
); |
174
|
|
|
} |
175
|
|
|
} |
176
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths