diff --git a/module/VuFind/src/VuFind/Tests/TestCase.php b/module/VuFind/src/VuFind/Tests/TestCase.php index 5f48900482b88765c7ed66f712dc8792f8f6dd7b..b5284f1cb325a75991e7b96a56b56e04c8d55c3c 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 e072e78f82c06c5cf01b816cf48631d3e10372b4..0bebb47638bbbb517dd339acdbb97fe671734e8c 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 32c23958de864fb421605b93538c09cd2c0c0abb..de7aa5a21c1a088fef01df47284f775facb9d2a6 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) {