Skip to content
Snippets Groups Projects
Commit 1e4dbce8 authored by Chris Hallberg's avatar Chris Hallberg
Browse files

Merge branch 'master' of https://github.com/vufind-org/vufind

parents 0e063ac5 d080941b
No related merge requests found
...@@ -80,7 +80,7 @@ class ResultScroller extends AbstractPlugin ...@@ -80,7 +80,7 @@ class ResultScroller extends AbstractPlugin
{ {
// Do nothing if disabled: // Do nothing if disabled:
if (!$this->enabled) { if (!$this->enabled) {
return; return false;
} }
// Save the details of this search in the session // Save the details of this search in the session
......
<?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
<?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
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