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 'IssueDAO',
'JournalDAO',
'SectionDAO'
49 protected function setUp() : void {
54 $this->registerMockArticleSearchDAO();
55 $this->registerMockSubmissionDAO();
56 $this->registerMockIssueDAO();
57 $this->registerMockJournalDAO();
58 $this->registerMockSectionDAO();
61 if (is_null($request->getRouter())) {
63 $request->setRouter($router);
70 protected function tearDown() : void {
83 $this->markTestSkipped();
90 $keywords = array(
null =>
'test');
94 $searchResult = $articleSearch->retrieveResults($request, $journal, $keywords, $error);
97 self::assertInstanceOf(
'ItemIterator', $searchResult);
98 $firstResult = $searchResult->next();
99 self::assertArrayHasKey(
'article', $firstResult);
100 self::assertEquals(SUBMISSION_SEARCH_TEST_DEFAULT_ARTICLE, $firstResult[
'article']->getId());
101 self::assertEquals(
'', $error);
105 $this->registerMockIssueDAO(
false);
106 $this->registerMockArticleSearchDAO();
107 $keywords = array(
null =>
'test');
108 $searchResult = $articleSearch->retrieveResults($request, $journal, $keywords, $error);
109 self::assertTrue($searchResult->eof());
116 $this->markTestSkipped();
122 array (
null =>
'query'),
123 array (
'1' =>
'author'),
124 array (
'2' =>
'title'),
132 $testFromDate = date(
'Y-m-d H:i:s', strtotime(
'2011-03-15 00:00:00'));
133 $testToDate = date(
'Y-m-d H:i:s', strtotime(
'2012-03-15 18:30:00'));
138 foreach($testCases as $testCase) {
141 $keywords = $testCase;
143 $searchResult = $articleSearch->retrieveResults($request, $journal, $keywords, $error, $testFromDate, $testToDate);
147 $expectedItemsPerPage = 20;
148 $expectedTotalResults = 3;
150 $expectedParams = array(
151 $journal, $testCase, $testFromDate, $testToDate,
152 $expectedPage, $expectedItemsPerPage, $expectedTotalResults,
155 self::assertEquals($expectedParams, $this->_retrieveResultsParams);
159 self::assertEquals(
'SubmissionSearch::retrieveResults', $calledHooks[0][0]);
163 self::assertInstanceOf(
'VirtualArrayIterator', $searchResult);
166 self::assertEquals(3, $searchResult->getCount());
169 $firstResult = $searchResult->next();
170 self::assertArrayHasKey(
'article', $firstResult);
171 self::assertEquals(SUBMISSION_SEARCH_TEST_ARTICLE_FROM_PLUGIN, $firstResult[
'article']->getId());
172 self::assertEquals(
'', $error);
189 $this->_retrieveResultsParams = $params;
192 $totalCount =& $params[6];
197 3 => SUBMISSION_SEARCH_TEST_ARTICLE_FROM_PLUGIN
208 public function callbackGetArticle($articleId, $journalId =
null, $useCache =
false) {
211 $article->setId($articleId);
223 private function registerMockArticleSearchDAO() {
225 $articleSearchDAO = $this->getMockBuilder(ArticleSearchDAO::class)
226 ->setMethods(array(
'getPhraseResults'))
230 $searchResult = array(
231 SUBMISSION_SEARCH_TEST_DEFAULT_ARTICLE => array(
234 'issuePublicationDate' =>
'2013-05-01 20:30:00',
235 'publicationDate' =>
'2013-05-01 20:30:00'
240 $articleSearchDAO->expects($this->any())
241 ->method(
'getPhraseResults')
242 ->will($this->returnValue($searchResult));
252 private function registerMockSubmissionDAO() {
254 $submissionDao = $this->getMockBuilder(SubmissionDAO::class)
255 ->setMethods(array(
'getArticle'))
262 $submissionDao->expects($this->
any())
263 ->method(
'getArticle')
264 ->will($this->returnCallback(array($this,
'callbackGetArticle')));
274 private function registerMockIssueDAO($published =
true) {
276 $issueDAO = $this->getMockBuilder(IssueDAO::class)
277 ->setMethods(array(
'getById'))
281 $issue = $issueDAO->newDataObject();
282 $issue->setPublished($published);
285 $issueDAO->expects($this->
any())
287 ->will($this->returnValue($issue));
297 private function registerMockJournalDAO() {
299 $journalDAO = $this->getMockBuilder(JournalDAO::class)
300 ->setMethods(array(
'getById'))
307 $journalDAO->expects($this->
any())
309 ->will($this->returnValue($journal));
319 private function registerMockSectionDAO() {
321 $sectionDAO = $this->getMockBuilder(SectionDAO::class)
322 ->setMethods(array(
'getSection'))
329 $sectionDAO->expects($this->
any())
330 ->method(
'getSection')
331 ->will($this->returnValue($section));