From 7821c5ff6afb33081fadf07c26a3fc17f4da5e48 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Wed, 5 Sep 2012 15:10:11 -0400 Subject: [PATCH] Updated test cases to use search manager. --- module/VuFind/src/VuFind/Tests/TestCase.php | 18 ++++++++++++++++++ module/VuFind/tests/Search/Base/ParamsTest.php | 5 +++-- .../tests/Theme/Root/Helper/ResultFeedTest.php | 5 +++-- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/module/VuFind/src/VuFind/Tests/TestCase.php b/module/VuFind/src/VuFind/Tests/TestCase.php index 5f48900482b..b5284f1cb32 100644 --- a/module/VuFind/src/VuFind/Tests/TestCase.php +++ b/module/VuFind/src/VuFind/Tests/TestCase.php @@ -41,6 +41,7 @@ namespace VuFind\Tests; abstract class TestCase extends \PHPUnit_Framework_TestCase { + protected $searchManager = false; /** * Call protected or private method for side-effect and result. @@ -100,4 +101,21 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase $reflectionProperty->setAccessible(true); return $reflectionProperty->setValue($object, $value); } + + /** + * Get a search manager instance for testing search objects. + * + * @return \VuFind\Search\Manager + */ + public function getSearchManager() + { + if (!$this->searchManager) { + $this->searchManager = new \VuFind\Search\Manager( + array('default_namespace' => 'VuFind\Search') + ); + $serviceManager = new \Zend\ServiceManager\ServiceManager(); + $this->searchManager->setServiceLocator($serviceManager); + } + return $this->searchManager; + } } \ No newline at end of file diff --git a/module/VuFind/tests/Search/Base/ParamsTest.php b/module/VuFind/tests/Search/Base/ParamsTest.php index e072e78f82c..0bebb47638b 100644 --- a/module/VuFind/tests/Search/Base/ParamsTest.php +++ b/module/VuFind/tests/Search/Base/ParamsTest.php @@ -49,10 +49,11 @@ class ParamsTest extends \VuFind\Tests\TestCase public function testSpellingReplacements() { // Use Solr options since base options is an abstract class. - $options = new \VuFind\Search\Solr\Options(); + $sm = $this->getSearchManager()->setSearchClassId('Solr'); + $options = $sm->getOptionsInstance(); // Create Params object for testing purposes. - $params = new \VuFind\Search\Base\Params($options); + $params = $sm->setSearchClassId('Base')->getParams($options); // Key test: word boundaries: $params->setBasicSearch('go good googler'); diff --git a/module/VuFind/tests/Theme/Root/Helper/ResultFeedTest.php b/module/VuFind/tests/Theme/Root/Helper/ResultFeedTest.php index 32c23958de8..de7aa5a21c1 100644 --- a/module/VuFind/tests/Theme/Root/Helper/ResultFeedTest.php +++ b/module/VuFind/tests/Theme/Root/Helper/ResultFeedTest.php @@ -70,10 +70,11 @@ class ResultFeedTest extends \VuFind\Tests\ViewHelperTestCase $request->set('sort', 'title'); $request->set('view', 'rss'); - $params = new \VuFind\Search\Solr\Params(); + $sm = $this->getSearchManager()->setSearchClassId('Solr'); + $params = $sm->getParams(); $params->initFromRequest($request); - $results = new \VuFind\Search\Solr\Results($params); + $results = $sm->getResults($params); $helper = new ResultFeed(); $helper->setView($this->getPhpRenderer($this->getPlugins())); $mockTranslator = function ($str) { -- GitLab