/** * Perform a search and return record collection. * * @param AbstractQuery $query Search query * @param integer $offset Search offset * @param integer $limit Search limit * @param ParamBag $params Search backend parameters * * @return RecordCollectionInterface */ public function search(AbstractQuery $query, $offset, $limit, ParamBag $params = null) { if (null === $params) { $params = new ParamBag(); } $params->mergeWith($this->getQueryBuilder()->build($query)); $response = $this->connector->search($params, $offset, $limit); $collection = $this->createRecordCollection($response); $this->injectSourceIdentifier($collection); return $collection; }
/** * 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']); }