示例#1
0
文件: Backend.php 项目: tillk/vufind
 /**
  * Retrieve a single document.
  *
  * @param string   $id     Document identifier
  * @param ParamBag $params Search backend parameters
  *
  * @return RecordCollectionInterface
  */
 public function retrieve($id, ParamBag $params = null)
 {
     $response = $this->connector->getRecord($id, $params);
     $collection = $this->createRecordCollection($response);
     $this->injectSourceIdentifier($collection);
     return $collection;
 }
示例#2
0
 /**
  * Create the WorldCat connector.
  *
  * @return Connector
  */
 protected function createConnector()
 {
     $wsKey = isset($this->config->WorldCat->apiKey) ? $this->config->WorldCat->apiKey : null;
     $connector = new Connector($wsKey, $this->serviceLocator->get('VuFind\\Http')->createClient());
     $connector->setLogger($this->logger);
     return $connector;
 }
示例#3
0
 /**
  * Get holdings information from WorldCat (false if none available).
  *
  * @return \SimpleXMLElement|bool
  */
 public function getHoldings()
 {
     $id = $this->getOCLCNum();
     return empty($id) ? false : $this->wc->getHoldings($id);
 }
示例#4
0
 /**
  * Test search
  *
  * @return void
  */
 public function testSearch()
 {
     $client = $this->getMock('Zend\\Http\\Client');
     $connector = new Connector('key', $client);
     $client->expects($this->once())->method('setMethod')->with($this->equalTo('POST'))->will($this->returnValue($client));
     $client->expects($this->once())->method('setUri')->with($this->equalTo('http://www.worldcat.org/webservices/catalog/search/sru?version=1.1&x=y&startRecord=0&maximumRecords=20&servicelevel=full&wskey=key'));
     $body = '<foo>,<numberOfRecords>1</numberOfRecords><records><record><recordData>bar</recordData></record></records></foo>';
     $response = $this->getMock('Zend\\Http\\Response');
     $response->expects($this->once())->method('getBody')->will($this->returnValue($body));
     $response->expects($this->any())->method('isSuccess')->will($this->returnValue(true));
     $client->expects($this->once())->method('send')->will($this->returnValue($response));
     $final = $connector->search(new ParamBag(['x' => 'y']), 0, 20);
     $this->assertEquals('<recordData>bar</recordData>', $final['docs'][0]);
     $this->assertEquals(1, $final['total']);
 }