diff --git a/module/VuFind/src/VuFindTest/Unit/RecommendDeferredTestCase.php b/module/VuFind/src/VuFindTest/Unit/RecommendDeferredTestCase.php new file mode 100644 index 0000000000000000000000000000000000000000..2720b804e4cc1e3438fea78b00674fbd4439a155 --- /dev/null +++ b/module/VuFind/src/VuFindTest/Unit/RecommendDeferredTestCase.php @@ -0,0 +1,106 @@ +<?php + +/** + * Abstract base class for PHPUnit deferred recommendation module test cases. + * + * 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\Unit; + +/** + * Abstract base class for PHPUnit deferred recommendation module test cases. + * + * @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 + */ + +abstract class RecommendDeferredTestCase extends TestCase +{ + /** + * Get a fully configured module + * + * @param string $class class to construct + * @param string $settings settings + * @param \Zend\StdLib\Parameters $request request + * @param \VuFind\Search\Solr\Results $results results object + * + * @return SideFacets + */ + protected function getRecommend($class, $settings = '', $request = null, + $results = null + ) { + if (null === $results) { + $results = $this->getMockResults(); + } + if (null === $request) { + $request = new \Zend\StdLib\Parameters(array()); + } + $mod = new $class(); + $mod->setConfig($settings); + $mod->init($results->getParams(), $request); + $mod->process($results); + return $mod; + } + + /** + * 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 diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/SummonBestBetsDeferredTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/SummonBestBetsDeferredTest.php new file mode 100644 index 0000000000000000000000000000000000000000..51f3fc68b9381adaf2ad4597b1b679c912224f99 --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/SummonBestBetsDeferredTest.php @@ -0,0 +1,53 @@ +<?php +/** + * SummonBestBetsDeferred 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; + +/** + * SummonBestBetsDeferred 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 SummonBestBetsDeferredTest extends \VuFindTest\Unit\RecommendDeferredTestCase +{ + /** + * Test standard operation + * + * @return void + */ + public function testStandardOperation() + { + $this->assertEquals( + 'mod=SummonBestBets¶ms=lookfor&lookfor=foo', + $this->getRecommend('VuFind\Recommend\SummonBestBetsDeferred')->getUrlParams() + ); + } +} \ No newline at end of file diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/SummonDatabasesDeferredTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/SummonDatabasesDeferredTest.php new file mode 100644 index 0000000000000000000000000000000000000000..124e1704315c3543e90cd4122801288e228db4b0 --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/SummonDatabasesDeferredTest.php @@ -0,0 +1,53 @@ +<?php +/** + * SummonDatabasesDeferred 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; + +/** + * SummonDatabasesDeferred 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 SummonDatabasesDeferredTest extends \VuFindTest\Unit\RecommendDeferredTestCase +{ + /** + * Test standard operation + * + * @return void + */ + public function testStandardOperation() + { + $this->assertEquals( + 'mod=SummonDatabases¶ms=lookfor&lookfor=foo', + $this->getRecommend('VuFind\Recommend\SummonDatabasesDeferred')->getUrlParams() + ); + } +} \ No newline at end of file diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/SummonResultsDeferredTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/SummonResultsDeferredTest.php new file mode 100644 index 0000000000000000000000000000000000000000..f0047a66dd5f9e2df133ecb2c20d3c0bc68e5b7c --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/SummonResultsDeferredTest.php @@ -0,0 +1,61 @@ +<?php +/** + * SummonResultsDeferred 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; + +/** + * SummonResultsDeferred 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 SummonResultsDeferredTest extends \VuFindTest\Unit\RecommendDeferredTestCase +{ + /** + * Test standard operation + * + * @return void + */ + public function testStandardOperation() + { + $results = $this->getMockResults(); + $params = $results->getParams(); + $options = $this->getMockBuilder('VuFind\Search\Solr\Options') + ->disableOriginalConstructor()->getMock(); + $options->expects($this->once())->method('getLabelForBasicHandler')->with($this->equalTo('bar'))->will($this->returnValue('baz')); + $params->expects($this->once())->method('getOptions')->will($this->returnValue($options)); + $params->expects($this->once())->method('getSearchHandler')->will($this->returnValue('bar')); + $mod = $this->getRecommend('VuFind\Recommend\SummonResultsDeferred', '', null, $results); + $this->assertEquals( + 'mod=SummonResults¶ms=lookfor%3A&lookfor=foo&typeLabel=baz', + $mod->getUrlParams() + ); + } +} \ No newline at end of file