diff --git a/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php b/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php index 3939abf8441a2d7d466d5e66f74d1a43351f69ed..6198ee3c8d2c93395c797339bd0abce112882972 100644 --- a/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php +++ b/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php @@ -80,7 +80,7 @@ class ResultScroller extends AbstractPlugin { // Do nothing if disabled: if (!$this->enabled) { - return; + return false; } // Save the details of this search in the session diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/FollowupTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/FollowupTest.php new file mode 100644 index 0000000000000000000000000000000000000000..5ad0540f66bbd4913b8f9131110476d3744f480b --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/FollowupTest.php @@ -0,0 +1,106 @@ +<?php + +/** + * Followup controller plugin tests. + * + * 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\Controller\Plugin; + +use VuFind\Controller\Plugin\Followup; +use VuFindTest\Unit\TestCase as TestCase; + +/** + * Followup controller plugin tests. + * + * @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 FollowupTest extends TestCase +{ + /** + * Test clear behavior + * + * @return void + */ + public function testClear() + { + $f = new Followup(); + $f->setController($this->getMockController()); + $this->assertFalse($f->clear('url')); // nothing to clear yet + $f->store(); + $this->assertTrue($f->clear('url')); // clear the url set by store + $this->assertFalse($f->clear('url')); // already cleared + } + + /** + * Test retrieve + * + * @return void + */ + public function testRetrieve() + { + $f = new Followup(); + $f->setController($this->getMockController()); + $f->store(); + // standard controller-provided URL retrieval: + $this->assertEquals('http://localhost/default-url', $f->retrieve('url')); + // no parameters retrieves session object: + $this->assertEquals('Zend\Session\Container', get_class($f->retrieve())); + // test defaulting behavior: + $this->assertEquals('foo', $f->retrieve('bar', 'foo')); + } + + /** + * Test retrieve and clear + * + * @return void + */ + public function testRetrieveAndClear() + { + $f = new Followup(); + $f->store(array('foo' => 'bar'), 'baz'); + $this->assertEquals('bar', $f->retrieveAndClear('foo')); + $this->assertEquals('baz', $f->retrieveAndClear('url')); + $this->assertNull($f->retrieveAndClear('foo')); + $this->assertNull($f->retrieveAndClear('url')); + } + + /** + * Get a mock controller + * + * @param string $url URL for controller to report. + * + * @return void + */ + protected function getMockController($url = 'http://localhost/default-url') + { + $controller = $this->getMock('VuFind\Controller\AbstractBase'); + $controller->expects($this->any())->method('getServerUrl')->will($this->returnValue($url)); + return $controller; + } +} \ No newline at end of file diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..ec44cd34e8d8ddf0b8924b1c42b0ca1b9a20f03a --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php @@ -0,0 +1,91 @@ +<?php + +/** + * ResultScroller controller plugin tests. + * + * 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\Controller\Plugin; + +use VuFind\Controller\Plugin\ResultScroller; +use VuFindTest\Unit\TestCase as TestCase; + +/** + * ResultScroller controller plugin tests. + * + * @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 ResultScrollerTest extends TestCase +{ + /** + * Test disabled behavior + * + * @return void + */ + public function testDisabled() + { + $plugin = new ResultScroller(false); + $this->assertFalse($plugin->init($this->getMockResults())); + $expected = array( + 'previousRecord'=>null, 'nextRecord'=>null, + 'currentPosition'=>null, 'resultTotal'=>null + ); + $this->assertEquals($expected, $plugin->getScrollData($this->getMockRecordDriver('foo'))); + } + + /** + * Get mock record driver + * + * @param string $id ID + * @param string $source Backend + * + * @return \VuFind\RecordDriver\AbstractBase + */ + protected function getMockRecordDriver($id, $source = 'VuFind') + { + $driver = $this->getMockBuilder('VuFind\RecordDriver\AbstractBase') + ->disableOriginalConstructor() + ->getMock(); + $driver->expects($this->any())->method('getUniqueId')->will($this->returnValue($id)); + $driver->expects($this->any())->method('getResourceSource')->will($this->returnValue($source)); + return $driver; + } + + /** + * Get mock search results + * + * @return \VuFind\Search\Base\Results + */ + protected function getMockResults() + { + $results = $this->getMockBuilder('VuFind\Search\Solr\Results') + ->disableOriginalConstructor() + ->getMock(); + return $results; + } +} \ No newline at end of file