1
|
|
|
<?php namespace Scriptotek\Sru; |
2
|
|
|
|
3
|
|
|
use Mockery as m; |
|
|
|
|
4
|
|
|
|
5
|
|
|
class SearchRetrieveResponseTest extends TestCase |
6
|
|
|
{ |
7
|
|
|
public function testSingleRecordResult() |
8
|
|
|
{ |
9
|
|
|
$res = new SearchRetrieveResponse('<?xml version="1.0" encoding="UTF-8" ?> |
10
|
|
|
<srw:searchRetrieveResponse |
11
|
|
|
xmlns:srw="http://www.loc.gov/zing/srw/" |
12
|
|
|
xmlns:xcql="http://www.loc.gov/zing/cql/xcql/" |
13
|
|
|
> |
14
|
|
|
<srw:version>1.1</srw:version> |
15
|
|
|
<srw:numberOfRecords>1</srw:numberOfRecords> |
16
|
|
|
<srw:records> |
17
|
|
|
<srw:record> |
18
|
|
|
<srw:recordSchema>marcxchange</srw:recordSchema> |
19
|
|
|
<srw:recordPacking>xml</srw:recordPacking> |
20
|
|
|
<srw:recordPosition>1</srw:recordPosition> |
21
|
|
|
<srw:recordData>Record 1</srw:recordData> |
22
|
|
|
</srw:record> |
23
|
|
|
</srw:records> |
24
|
|
|
<srw:echoedSearchRetrieveRequest> |
25
|
|
|
<srw:operation>searchRetrieve</srw:operation> |
26
|
|
|
<srw:version>1.1</srw:version> |
27
|
|
|
<srw:query>bs.avdelingsamling = "urealastr" AND bs.lokal-klass = "k C11?"</srw:query> |
28
|
|
|
<srw:startRecord>1</srw:startRecord> |
29
|
|
|
<srw:maximumRecords>2</srw:maximumRecords> |
30
|
|
|
<srw:recordSchema>marcxchange</srw:recordSchema> |
31
|
|
|
</srw:echoedSearchRetrieveRequest> |
32
|
|
|
<srw:extraResponseData> |
33
|
|
|
<responseDate>2014-03-28T12:09:50Z</responseDate> |
34
|
|
|
</srw:extraResponseData> |
35
|
|
|
</srw:searchRetrieveResponse>'); |
36
|
|
|
|
37
|
|
|
$this->assertEquals('1.1', $res->version); |
38
|
|
|
$this->assertEquals(1, $res->numberOfRecords); |
39
|
|
|
$this->assertNull($res->nextRecordPosition); |
40
|
|
|
|
41
|
|
|
$this->assertCount(1, $res->records); |
42
|
|
|
$this->assertEquals(1, $res->records[0]->position); |
43
|
|
|
$this->assertEquals('marcxchange', $res->records[0]->schema); |
44
|
|
|
$this->assertEquals('xml', $res->records[0]->packing); |
45
|
|
|
$this->assertEquals('Record 1', $res->records[0]->data); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testMultipleRecordsResult() |
49
|
|
|
{ |
50
|
|
|
$res = new SearchRetrieveResponse('<?xml version="1.0" encoding="UTF-8" ?> |
51
|
|
|
<srw:searchRetrieveResponse |
52
|
|
|
xmlns:srw="http://www.loc.gov/zing/srw/" |
53
|
|
|
xmlns:xcql="http://www.loc.gov/zing/cql/xcql/" |
54
|
|
|
> |
55
|
|
|
<srw:version>1.1</srw:version> |
56
|
|
|
<srw:numberOfRecords>303</srw:numberOfRecords> |
57
|
|
|
<srw:records> |
58
|
|
|
<srw:record> |
59
|
|
|
<srw:recordSchema>marcxchange</srw:recordSchema> |
60
|
|
|
<srw:recordPacking>xml</srw:recordPacking> |
61
|
|
|
<srw:recordPosition>1</srw:recordPosition> |
62
|
|
|
<srw:recordData>Record 1</srw:recordData> |
63
|
|
|
</srw:record> |
64
|
|
|
<srw:record> |
65
|
|
|
<srw:recordSchema>marcxchange</srw:recordSchema> |
66
|
|
|
<srw:recordPacking>xml</srw:recordPacking> |
67
|
|
|
<srw:recordPosition>2</srw:recordPosition> |
68
|
|
|
<srw:recordData>Record 2</srw:recordData> |
69
|
|
|
</srw:record> |
70
|
|
|
</srw:records> |
71
|
|
|
<srw:nextRecordPosition>3</srw:nextRecordPosition> |
72
|
|
|
<srw:echoedSearchRetrieveRequest> |
73
|
|
|
<srw:operation>searchRetrieve</srw:operation> |
74
|
|
|
<srw:version>1.1</srw:version> |
75
|
|
|
<srw:query>bs.avdelingsamling = "urealastr" AND bs.lokal-klass = "k C11?"</srw:query> |
76
|
|
|
<srw:startRecord>1</srw:startRecord> |
77
|
|
|
<srw:maximumRecords>2</srw:maximumRecords> |
78
|
|
|
<srw:recordSchema>marcxchange</srw:recordSchema> |
79
|
|
|
</srw:echoedSearchRetrieveRequest> |
80
|
|
|
<srw:extraResponseData> |
81
|
|
|
<responseDate>2014-03-28T12:09:50Z</responseDate> |
82
|
|
|
</srw:extraResponseData> |
83
|
|
|
</srw:searchRetrieveResponse>'); |
84
|
|
|
|
85
|
|
|
$this->assertEquals('1.1', $res->version); |
86
|
|
|
$this->assertEquals(303, $res->numberOfRecords); |
87
|
|
|
$this->assertEquals(3, $res->nextRecordPosition); |
88
|
|
|
|
89
|
|
|
$this->assertCount(2, $res->records); |
90
|
|
|
$this->assertEquals(1, $res->records[0]->position); |
91
|
|
|
$this->assertEquals('marcxchange', $res->records[0]->schema); |
92
|
|
|
$this->assertEquals('xml', $res->records[0]->packing); |
93
|
|
|
$this->assertEquals('Record 1', $res->records[0]->data); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testErrorWithDetails() |
97
|
|
|
{ |
98
|
|
|
$this->expectException(\Scriptotek\Sru\Exceptions\SruErrorException::class); |
99
|
|
|
$this->expectExceptionMessage("Unknown schema for retrieval (Invalid parameter: 'marcxml' for service: 'biblio'"); |
100
|
|
|
|
101
|
|
|
$res = new SearchRetrieveResponse('<srw:searchRetrieveResponse xmlns:srw="http://www.loc.gov/zing/srw/"> |
|
|
|
|
102
|
|
|
<srw:version>1.1</srw:version> |
103
|
|
|
<srw:numberOfRecords>0</srw:numberOfRecords> |
104
|
|
|
<srw:diagnostics xmlns="http://www.loc.gov/zing/srw/diagnostic/"> |
105
|
|
|
<diagnostic > |
106
|
|
|
<uri>info:srw/diagnostic/1/66</uri> |
107
|
|
|
<details>Invalid parameter: \'marcxml\' for service: \'biblio\'</details> |
108
|
|
|
</diagnostic> |
109
|
|
|
</srw:diagnostics> |
110
|
|
|
</srw:searchRetrieveResponse>'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function testErrorWithoutDetails() |
114
|
|
|
{ |
115
|
|
|
$this->expectException(\Scriptotek\Sru\Exceptions\SruErrorException::class); |
116
|
|
|
$this->expectExceptionMessage("General system error"); |
117
|
|
|
|
118
|
|
|
$res = new SearchRetrieveResponse('<srw:searchRetrieveResponse xmlns:srw="http://www.loc.gov/zing/srw/"> |
|
|
|
|
119
|
|
|
<srw:version>1.1</srw:version> |
120
|
|
|
<srw:numberOfRecords>0</srw:numberOfRecords> |
121
|
|
|
<srw:diagnostics xmlns="http://www.loc.gov/zing/srw/diagnostic/"> |
122
|
|
|
<diagnostic > |
123
|
|
|
<uri>info:srw/diagnostic/1/1</uri> |
124
|
|
|
</diagnostic> |
125
|
|
|
</srw:diagnostics> |
126
|
|
|
</srw:searchRetrieveResponse>'); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function testErrorWithCustomMessage() |
130
|
|
|
{ |
131
|
|
|
$this->expectException(\Scriptotek\Sru\Exceptions\SruErrorException::class); |
132
|
|
|
$this->expectExceptionMessage("Too many boolean operators, the maximum is 10. Please try a less complex query. (10)"); |
133
|
|
|
|
134
|
|
|
$res = new SearchRetrieveResponse('<srw:searchRetrieveResponse xmlns:srw="http://www.loc.gov/zing/srw/"> |
|
|
|
|
135
|
|
|
<srw:version>1.1</srw:version> |
136
|
|
|
<srw:numberOfRecords>0</srw:numberOfRecords> |
137
|
|
|
<srw:diagnostics xmlns="http://www.loc.gov/zing/srw/diagnostic/"> |
138
|
|
|
<diagnostic > |
139
|
|
|
<uri>info:srw/diagnostic/1/10</uri> |
140
|
|
|
<message>Too many boolean operators, the maximum is 10. Please try a less complex query.</message> |
141
|
|
|
<details>10</details> |
142
|
|
|
</diagnostic> |
143
|
|
|
</srw:diagnostics> |
144
|
|
|
</srw:searchRetrieveResponse>'); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
// Should not throw error |
148
|
|
|
public function testDiagnosticsWithoutError() |
149
|
|
|
{ |
150
|
|
|
$res = new SearchRetrieveResponse('<srw:searchRetrieveResponse xmlns:srw="http://www.loc.gov/zing/srw/"> |
151
|
|
|
<srw:version>1.1</srw:version> |
152
|
|
|
<srw:numberOfRecords>0</srw:numberOfRecords> |
153
|
|
|
<srw:diagnostics xmlns="http://www.loc.gov/zing/srw/diagnostic/"> |
154
|
|
|
</srw:diagnostics> |
155
|
|
|
</srw:searchRetrieveResponse>'); |
156
|
|
|
$this->assertCount(0, $res->records); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function testCanBeInitializedWithoutAnyData() |
160
|
|
|
{ |
161
|
|
|
$res = new SearchRetrieveResponse; |
162
|
|
|
$this->assertNull($res->version); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
} |
166
|
|
|
|
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