/**
* @covers LucenePlugin
* @covers SolrSearchRequest
*/
public function testCallbackRetrieveResults()
{
// Test data.
$testCases = array(array(null => 'test AND query'), array(SUBMISSION_SEARCH_AUTHOR => 'author'), array(SUBMISSION_SEARCH_TITLE => 'title'), array(SUBMISSION_SEARCH_ABSTRACT => 'abstract'), array(SUBMISSION_SEARCH_INDEX_TERMS => 'Nicht index terms'), array(SUBMISSION_SEARCH_GALLEY_FILE => 'full OR text'), array(null => 'test query', SUBMISSION_SEARCH_AUTHOR => 'author', SUBMISSION_SEARCH_TITLE => 'title', SUBMISSION_SEARCH_DISCIPLINE => 'discipline', SUBMISSION_SEARCH_SUBJECT => 'subject', SUBMISSION_SEARCH_TYPE => 'type', SUBMISSION_SEARCH_COVERAGE => 'coverage', SUBMISSION_SEARCH_GALLEY_FILE => 'full text'));
$expectedResults = array(array('authors|title|abstract|galleyFullText|discipline|subject|type|coverage' => 'test AND query'), array('authors' => 'author'), array('title' => 'title'), array('abstract' => 'abstract'), array('discipline|subject|type|coverage' => 'Nicht index terms'), array('galleyFullText' => 'full OR text'), array('authors|title|abstract|galleyFullText|discipline|subject|type|coverage' => 'test query', 'authors' => 'author', 'title' => 'title', 'discipline' => 'discipline', 'subject' => 'subject', 'type' => 'type', 'coverage' => 'coverage', 'galleyFullText' => 'full text'));
$journal = new Journal();
$fromDate = '2000-01-01 00:00:00';
$hook = 'SubmissionSearch::retrieveResults';
$totalResults = null;
$error = null;
$facetCategories = array('discipline', 'subject', 'type', 'coverage', 'authors');
foreach ($testCases as $testNum => $testCase) {
// Build the expected search request.
$searchRequest = new SolrSearchRequest();
$searchRequest->setJournal($journal);
$searchRequest->setFromDate($fromDate);
$searchRequest->setQuery($expectedResults[$testNum]);
$searchRequest->setSpellcheck(true);
$searchRequest->setHighlighting(true);
// Facets should only be requested for categories that have no
// active filter.
$expectedFacetCategories = array_values(array_diff($facetCategories, array_keys($expectedResults[$testNum])));
$searchRequest->setFacetCategories($expectedFacetCategories);
// Mock a SolrWebService.
$webService = $this->getMock('SolrWebService', array('retrieveResults'), array(), '', false);
// Check whether the Lucene plug-in calls the web service
// with the right parameters.
$webService->expects($this->once())->method('retrieveResults')->with($this->equalTo($searchRequest), $this->equalTo($totalResults));
$this->lucenePlugin->_solrWebService = $webService;
unset($webService, $searchRequest);
// Execute the test.
$params = array($journal, $testCase, $fromDate, null, 1, 25, &$totalResults, &$error);
$this->lucenePlugin->callbackRetrieveResults($hook, $params);
}
// Test an error condition.
$webService = $this->getMock('SolrWebService', array('retrieveResults', 'getServiceMessage'), array(), '', false);
$webService->expects($this->once())->method('retrieveResults')->will($this->returnValue(null));
$webService->expects($this->any())->method('getServiceMessage')->will($this->returnValue('some error message'));
$originalWebService = $this->lucenePlugin->_solrWebService;
$this->lucenePlugin->_solrWebService = $webService;
$params = array($journal, array(null => 'test'), null, null, 1, 25, &$totalResults, &$error);
$this->assertEquals(array(), $this->lucenePlugin->callbackRetrieveResults($hook, $params));
$this->assertEquals('some error message ##plugins.generic.lucene.message.techAdminInformed##', $error);
$this->lucenePlugin->_solrWebService = $originalWebService;
}