diff --git a/module/VuFind/src/VuFind/Recommend/ExpandFacets.php b/module/VuFind/src/VuFind/Recommend/ExpandFacets.php index 8482c39c2bd4876b4b4fedff0f0a9d25a64439e8..a3e2add4a2cd49a4af4c6e705692de6e4deaf8b3 100644 --- a/module/VuFind/src/VuFind/Recommend/ExpandFacets.php +++ b/module/VuFind/src/VuFind/Recommend/ExpandFacets.php @@ -153,13 +153,9 @@ class ExpandFacets implements RecommendInterface } /** - * process - * - * Called after the SearchObject has performed its main search. This may be - * used to extract necessary information from the SearchObject or to perform - * completely unrelated processing. + * Get the facet data * - * @return void + * @return array */ public function getExpandedSet() { diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/ExpandFacetsTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/ExpandFacetsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..61bfed135c0ca93798ec5859006d410af9c82497 --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/ExpandFacetsTest.php @@ -0,0 +1,162 @@ +<?php +/** + * ExpandFacets recommendation module Test Class + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:unit_tests Wiki + */ +namespace VuFindTest\Recommend; +use VuFind\Recommend\ExpandFacets; + +/** + * ExpandFacets recommendation module Test Class + * + * @category VuFind2 + * @package Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:unit_tests Wiki + */ +class ExpandFacetsTest extends \VuFindTest\Unit\TestCase +{ + /** + * Test getEmptyResults() + * + * @return void + */ + public function testGetEmptyResults() + { + $results = $this->getMockResults(); + $ef = $this->getExpandFacets(null, null, $results); + $this->assertEquals($results, $ef->getEmptyResults()); + } + + /** + * Test facet initialization. + * + * @return void + */ + public function testFacetInit() + { + $configLoader = $this->getMockConfigLoader( + array( + 'Results' => array( + 'format' => 'Format', + ), + ) + ); + $results = $this->getMockResults(); + $params = $results->getParams(); + $params->expects($this->once())->method('addFacet')->with($this->equalTo('format'), $this->equalTo('Format')); + $results->expects($this->once())->method('getFacetList')->with($this->equalTo(array('format' => 'Format')))->will($this->returnValue(array('foo'))); + $ef = $this->getExpandFacets($configLoader, $results); + $this->assertEquals(array('foo'), $ef->getExpandedSet()); + } + + /** + * Get a fully configured module + * + * @param \VuFind\Config\PluginManager $configLoader config loader + * @param \VuFind\Search\Solr\Results $results populated results object + * @param \VuFind\Search\Solr\Results $emptyResults empty results object + * @param string $settings settings + * @param \Zend\StdLib\Parameters $request request + * + * @return ExpandFacets + */ + protected function getExpandFacets($configLoader = null, $results = null, $emptyResults = null, $settings = '', $request = null) + { + if (null === $configLoader) { + $configLoader = $this->getMockConfigLoader(); + } + if (null === $results) { + $results = $this->getMockResults(); + } + if (null === $emptyResults) { + $emptyResults = $this->getMockResults(); + } + if (null === $request) { + $request = new \Zend\StdLib\Parameters(array()); + } + $sf = new ExpandFacets($configLoader, $emptyResults); + $sf->setConfig($settings); + $sf->init($results->getParams(), $request); + $sf->process($results); + return $sf; + } + + /** + * Get a mock config loader. + * + * @param array $config Configuration to return + * @param string $key Key to store configuration under + * + * @return \VuFind\Config\PluginManager + */ + protected function getMockConfigLoader($config = array(), $key = 'facets') + { + $loader = $this->getMockBuilder('VuFind\Config\PluginManager') + ->disableOriginalConstructor()->getMock(); + $loader->expects($this->once())->method('get')->with($this->equalTo($key)) + ->will($this->returnValue(new \Zend\Config\Config($config))); + return $loader; + } + + /** + * Get a mock results object. + * + * @param \VuFind\Search\Solr\Params $params Params to include in container. + * + * @return \VuFind\Search\Solr\Results + */ + protected function getMockResults($params = null) + { + if (null === $params) { + $params = $this->getMockParams(); + } + $results = $this->getMockBuilder('VuFind\Search\Solr\Results') + ->disableOriginalConstructor()->getMock(); + $results->expects($this->any())->method('getParams') + ->will($this->returnValue($params)); + return $results; + } + + /** + * Get a mock params object. + * + * @param \VuFindSearch\Query\Query $query Query to include in container. + * + * @return \VuFind\Search\Solr\Params + */ + protected function getMockParams($query = null) + { + if (null === $query) { + $query = new \VuFindSearch\Query\Query('foo', 'bar'); + } + $params = $this->getMockBuilder('VuFind\Search\Solr\Params') + ->disableOriginalConstructor()->getMock(); + $params->expects($this->any())->method('getQuery') + ->will($this->returnValue($query)); + return $params; + } +} \ No newline at end of file