17 require_mock_env(
'env1');
19 import(
'lib.pkp.tests.PKPTestCase');
20 import(
'lib.pkp.classes.core.ArrayItemIterator');
21 import(
'classes.search.ArticleSearch');
22 import(
'lib.pkp.classes.core.PKPRouter');
24 define(
'SUBMISSION_SEARCH_TEST_DEFAULT_ARTICLE', 1);
25 define(
'SUBMISSION_SEARCH_TEST_ARTICLE_FROM_PLUGIN', 2);
29 private $_retrieveResultsParams;
38 $mockedDaos = parent::getMockedDAOs();
40 'ArticleSearchDAO',
'SubmissionDAO',
41 'JournalDAO',
'SectionDAO'
49 protected function setUp() : void {
54 $this->registerMockArticleSearchDAO();
55 $this->registerMockSubmissionDAO();
56 $this->registerMockJournalDAO();
57 $this->registerMockSectionDAO();
60 if (is_null($request->getRouter())) {
62 $request->setRouter($router);
69 protected function tearDown() : void {
82 $this->markTestSkipped();
89 $keywords = array(
null =>
'test');
93 $searchResult = $articleSearch->retrieveResults($request, $journal, $keywords, $error);
96 self::assertInstanceOf(
'ItemIterator', $searchResult);
97 $firstResult = $searchResult->next();
98 self::assertArrayHasKey(
'article', $firstResult);
99 self::assertEquals(SUBMISSION_SEARCH_TEST_DEFAULT_ARTICLE, $firstResult[
'article']->getId());
100 self::assertEquals(
'', $error);
102 $this->registerMockArticleSearchDAO();
103 $keywords = array(
null =>
'test');
104 $searchResult = $articleSearch->retrieveResults($request, $journal, $keywords, $error);
105 self::assertTrue($searchResult->eof());
112 $this->markTestSkipped();
118 array (
null =>
'query'),
119 array (
'1' =>
'author'),
120 array (
'2' =>
'title'),
128 $testFromDate = date(
'Y-m-d H:i:s', strtotime(
'2011-03-15 00:00:00'));
129 $testToDate = date(
'Y-m-d H:i:s', strtotime(
'2012-03-15 18:30:00'));
134 foreach($testCases as $testCase) {
137 $keywords = $testCase;
139 $searchResult = $articleSearch->retrieveResults($request, $journal, $keywords, $error, $testFromDate, $testToDate);
143 $expectedItemsPerPage = 20;
144 $expectedTotalResults = 3;
146 $expectedParams = array(
147 $journal, $testCase, $testFromDate, $testToDate,
148 $expectedPage, $expectedItemsPerPage, $expectedTotalResults,
151 self::assertEquals($expectedParams, $this->_retrieveResultsParams);
155 self::assertEquals(
'SubmissionSearch::retrieveResults', $calledHooks[0][0]);
159 self::assertInstanceOf(
'VirtualArrayIterator', $searchResult);
162 self::assertEquals(3, $searchResult->getCount());
165 $firstResult = $searchResult->next();
166 self::assertArrayHasKey(
'article', $firstResult);
167 self::assertEquals(SUBMISSION_SEARCH_TEST_ARTICLE_FROM_PLUGIN, $firstResult[
'article']->getId());
168 self::assertEquals(
'', $error);
185 $this->_retrieveResultsParams = $params;
188 $totalCount =& $params[6];
193 3 => SUBMISSION_SEARCH_TEST_ARTICLE_FROM_PLUGIN
204 public function callbackGetArticle($articleId, $journalId =
null, $useCache =
false) {
207 $article->setId($articleId);
219 private function registerMockArticleSearchDAO() {
221 $articleSearchDAO = $this->getMockBuilder(ArticleSearchDAO::class)
222 ->setMethods(array(
'getPhraseResults'))
226 $searchResult = array(
227 SUBMISSION_SEARCH_TEST_DEFAULT_ARTICLE => array(
230 'publicationDate' =>
'2013-05-01 20:30:00'
235 $articleSearchDAO->expects($this->any())
236 ->method(
'getPhraseResults')
237 ->will($this->returnValue($searchResult));
247 private function registerMockSubmissionDAO() {
249 $submissionDao = $this->getMockBuilder(SubmissionDAO::class)
250 ->setMethods(array(
'getArticle'))
257 $submissionDao->expects($this->any())
258 ->method(
'getArticle')
259 ->will($this->returnCallback(array($this,
'callbackGetArticle')));
269 private function registerMockJournalDAO() {
271 $journalDAO = $this->getMockBuilder(JournalDAO::class)
272 ->setMethods(array(
'getById'))
279 $journalDAO->expects($this->any())
281 ->will($this->returnValue($journal));
291 private function registerMockSectionDAO() {
293 $sectionDAO = $this->getMockBuilder(SectionDAO::class)
294 ->setMethods(array(
'getSection'))
301 $sectionDAO->expects($this->any())
302 ->method(
'getSection')
303 ->will($this->returnValue($section));