Skip to content
Snippets Groups Projects
Commit 8a41e14e authored by Demian Katz's avatar Demian Katz
Browse files

Added test.

parent ebe46b1a
No related merge requests found
<?php
/**
* FacetCloud 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\FacetCloud;
/**
* FacetCloud 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 FacetCloudTest extends \VuFindTest\Unit\TestCase
{
/**
* Test getEmptyResults()
*
* @return void
*/
public function testGetFacetLimit()
{
$results = $this->getMockResults();
$results->getParams()->expects($this->once())->method('getFacetSettings')
->will($this->returnValue(array('limit' => 50)));
$fc = $this->getFacetCloud(null,$results);
$this->assertEquals(49, $fc->getFacetLimit());
}
/**
* 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 FacetCloud
*/
protected function getFacetCloud($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());
}
$fc = new FacetCloud($configLoader, $emptyResults);
$fc->setConfig($settings);
$fc->init($results->getParams(), $request);
$fc->process($results);
return $fc;
}
/**
* 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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment