/**
  * @covers PKPRequest::redirectUrl
  */
 public function testRedirectUrl()
 {
     HookRegistry::register('Request::redirect', array($this, 'redirectUrlHook'));
     $this->request->redirectUrl('http://some.url/');
     self::assertEquals(array(array('Request::redirect', array('http://some.url/'))), HookRegistry::getCalledHooks());
     HookRegistry::clear('Request::redirect');
 }
Пример #2
0
 /**
  * @covers ArticleSearchIndex
  */
 public function testIndexSubmissionFilesViaPluginHook()
 {
     // Diverting to the search plugin hook.
     HookRegistry::register('ArticleSearchIndex::submissionFilesChanged', array($this, 'callbackIndexSubmissionFiles'));
     // The file DAOs should not be called.
     $this->registerFileDAOs(false);
     // Simulate indexing via hook.
     $article = new Article();
     $articleSearchIndex = new ArticleSearchIndex();
     $articleSearchIndex->submissionFilesChanged($article);
     // Test whether the hook was called.
     $calledHooks = HookRegistry::getCalledHooks();
     $lastHook = array_pop($calledHooks);
     self::assertEquals('ArticleSearchIndex::submissionFilesChanged', $lastHook[0]);
     // Remove the test hook.
     HookRegistry::clear('ArticleSearchIndex::submissionFilesChanged');
 }
Пример #3
0
 /**
  * @covers ArticleSearch
  */
 public function testRetrieveResultsViaPluginHook()
 {
     // Diverting a search to the search plugin hook.
     HookRegistry::register('SubmissionSearch::retrieveResults', array($this, 'callbackRetrieveResults'));
     $testCases = array(array(null => 'query'), array('1' => 'author'), array('2' => 'title'), array(null => 'query', 1 => 'author', 2 => 'title'));
     $testFromDate = date('Y-m-d H:i:s', strtotime('2011-03-15 00:00:00'));
     $testToDate = date('Y-m-d H:i:s', strtotime('2012-03-15 18:30:00'));
     $error = '';
     foreach ($testCases as $testCase) {
         // Test a simple search with the simulated callback.
         $journal = new Journal();
         $keywords = $testCase;
         $articleSearch = new ArticleSearch();
         $searchResult = $articleSearch->retrieveResults($journal, $keywords, $error, $testFromDate, $testToDate);
         // Check the parameters passed into the callback.
         $expectedPage = 1;
         $expectedItemsPerPage = 20;
         $expectedTotalResults = 3;
         $expectedError = '';
         $expectedParams = array($journal, $testCase, $testFromDate, $testToDate, $expectedPage, $expectedItemsPerPage, $expectedTotalResults, $expectedError);
         self::assertEquals($expectedParams, $this->_retrieveResultsParams);
         // Test and clear the call history of the hook registry.
         $calledHooks = HookRegistry::getCalledHooks();
         self::assertEquals('SubmissionSearch::retrieveResults', $calledHooks[0][0]);
         HookRegistry::resetCalledHooks(true);
         // Test whether the result from the hook is being returned.
         self::assertInstanceOf('VirtualArrayIterator', $searchResult);
         // Test the total count.
         self::assertEquals(3, $searchResult->getCount());
         // Test the search result.
         $firstResult = $searchResult->next();
         self::assertArrayHasKey('article', $firstResult);
         self::assertEquals(SUBMISSION_SEARCH_TEST_ARTICLE_FROM_PLUGIN, $firstResult['article']->getId());
         self::assertEquals('', $error);
     }
     // Remove the test hook.
     HookRegistry::clear('SubmissionSearch::retrieveResults');
 }