Skip to content

Commit 33807d4

Browse files
committed
Add tests
1 parent c42d8c7 commit 33807d4

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

src/Client.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ public function search($cql, $start = 1, $count = 10) {
145145
*
146146
* @param string $cql
147147
* @param int $count Number of records to request per request
148+
* @param mixed $httpClient A http client
148149
* @return Records
149150
*/
150-
public function records($cql, $count = 10)
151+
public function records($cql, $count = 10, $httpClient = null)
151152
{
152-
return new Records($cql, $this, $count);
153+
return new Records($cql, $this, $count, $httpClient);
153154
}
154155

155156
/**

src/ExplainResponse.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ public function __construct($text, &$client = null)
2929
{
3030
parent::__construct($text, $client);
3131

32+
$this->indexes = array();
33+
3234
$explain = $this->response->first('/srw:explainResponse/srw:record/sru:recordData/exp:explain');
35+
if (!$explain) return;
36+
3337
$serverInfo = $explain->first('exp:serverInfo');
3438
$dbInfo = $explain->first('exp:databaseInfo');
3539
$indexInfo = $explain->first('exp:indexInfo');
@@ -41,7 +45,6 @@ public function __construct($text, &$client = null)
4145
$this->database->title = $dbInfo->text('exp:title');
4246
$this->database->description = $dbInfo->text('exp:description');
4347

44-
$this->indexes = array();
4548
foreach ($indexInfo->xpath('exp:index') as $index) {
4649
$ind = new \StdClass;
4750
$ind->scan = ($index->attr('scan') == 'true');

tests/ClientTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class ClientTest extends TestCase {
1111
<srw:searchRetrieveResponse xmlns:srw="http://www.loc.gov/zing/srw/" xmlns:xcql="http://www.loc.gov/zing/cql/xcql/">
1212
</srw:searchRetrieveResponse>';
1313

14+
protected $simple_explain_response = '<?xml version="1.0" encoding="UTF-8"?>
15+
<sru:explainResponse xmlns:sru="http://www.loc.gov/zing/srw/">
16+
</sru:explainResponse>';
17+
1418
public function testUrlTo()
1519
{
1620
$sru1 = new Client($this->url);
@@ -156,5 +160,45 @@ public function testNext()
156160

157161
}
158162

163+
public function testHttpOptions()
164+
{
165+
$sru1 = new Client($this->url, array(
166+
'user-agent' => 'Blablabla/0.1',
167+
'credentials' => array('myuser', 'mypass'),
168+
'proxy' => 'proxyhost:80'
169+
));
170+
171+
$opts = $sru1->getHttpOptions();
172+
173+
$this->assertEquals('application/xml', $opts['headers']['Accept']);
174+
$this->assertEquals('Blablabla/0.1', $opts['headers']['User-Agent']);
175+
$this->assertEquals(array('myuser', 'mypass'), $opts['auth']);
176+
$this->assertEquals('proxyhost:80', $opts['proxy']);
177+
}
178+
179+
public function testRecords()
180+
{
181+
$http = $this->httpMockSingleResponse($this->makeDummyResponse(1));
182+
183+
$sru1 = new Client($this->url);
184+
$r = $sru1->records('test', 1, $http);
185+
186+
$this->assertInstanceOf('Scriptotek\Sru\Records', $r);
187+
}
188+
189+
public function testExplain()
190+
{
191+
$http = $this->httpMockSingleResponse($this->simple_explain_response);
192+
$sru = new Client($this->url, null, $http);
193+
$exp = $sru->explain();
194+
195+
$this->assertInstanceOf('Scriptotek\Sru\ExplainResponse', $exp);
196+
197+
$this->assertXmlStringEqualsXmlString(
198+
$this->simple_explain_response,
199+
$exp->asXml()
200+
);
201+
}
202+
159203
}
160204

0 commit comments

Comments
 (0)