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

Merge pull request #200 from KDK-Alli/multibackend2

Rewrite of MultiBackend driver with separate functions for all ILS drive...
parents 140e2e7b 4d2a823a
No related merge requests found
[General] [General]
; This setting controls the MultiBackend driver's behavior when it can't
; determine which specific driver should be used to service a particular
; request. Select "use_first" if you would like MultiBackend to return
; the value generated by the first driver capable of responding to the
; specified method; select "merge" if you would like all potentially
; relevant responses to be combined into a single response (only works
; for array-oriented data).
default_fallback_driver_selection = use_first
; (Optional) The name of a driver instance to use by default if no specific ; (Optional) The name of a driver instance to use by default if no specific
; instance can be determined as the best option (must correspond with a key ; instance can be determined as the best option (must correspond with a key
; from the [Drivers] section below if set -- omit to have no default driver) ; from the [Drivers] section below if set -- omit to have no default driver)
...@@ -35,12 +26,6 @@ default_fallback_driver_selection = use_first ...@@ -35,12 +26,6 @@ default_fallback_driver_selection = use_first
[Delimiters] [Delimiters]
login = " " login = " "
; This section allows you to override the default functionality set by
; default_fallback_driver_selection on a method-by-method basis. See above
; for explanations of legal values (merge/use_first)
[FallbackDriverSelectionOverride]
;getMyFines = merge
; This section defines the driver instances that are enabled for login. ; This section defines the driver instances that are enabled for login.
; Used together with MultiILS authentication method that allows selecting ; Used together with MultiILS authentication method that allows selecting
; the login target. ; the login target.
......
...@@ -227,7 +227,7 @@ class Connection implements TranslatorAwareInterface ...@@ -227,7 +227,7 @@ class Connection implements TranslatorAwareInterface
* if the system supports a particular function. * if the system supports a particular function.
* *
* @param string $function The name of the function to check. * @param string $function The name of the function to check.
* @param string $id (optional) A record id used to identify the used * @param string $id (optional) A record id used to e.g. identify the used
* backend with MultiBackend driver * backend with MultiBackend driver
* *
* @return mixed On success, an associative array with specific function keys * @return mixed On success, an associative array with specific function keys
...@@ -236,8 +236,10 @@ class Connection implements TranslatorAwareInterface ...@@ -236,8 +236,10 @@ class Connection implements TranslatorAwareInterface
public function checkFunction($function, $id = null) public function checkFunction($function, $id = null)
{ {
// Extract the configuration from the driver if available: // Extract the configuration from the driver if available:
$functionConfig = $this->checkCapability('getConfig') $functionConfig = $this->checkCapability(
? $this->getDriver()->getConfig($function, $id) : false; 'getConfig',
compact('function', 'id')
) ? $this->getDriver()->getConfig($function, $id) : false;
// See if we have a corresponding check method to analyze the response: // See if we have a corresponding check method to analyze the response:
$checkMethod = "checkMethod".$function; $checkMethod = "checkMethod".$function;
...@@ -255,7 +257,7 @@ class Connection implements TranslatorAwareInterface ...@@ -255,7 +257,7 @@ class Connection implements TranslatorAwareInterface
* A support method for checkFunction(). This is responsible for checking * A support method for checkFunction(). This is responsible for checking
* the driver configuration to determine if the system supports Holds. * the driver configuration to determine if the system supports Holds.
* *
* @param string $functionConfig The Hold configuration values * @param array $functionConfig The Hold configuration values
* *
* @return mixed On success, an associative array with specific function keys * @return mixed On success, an associative array with specific function keys
* and values either for placing holds via a form or a URL; on failure, false. * and values either for placing holds via a form or a URL; on failure, false.
...@@ -294,7 +296,7 @@ class Connection implements TranslatorAwareInterface ...@@ -294,7 +296,7 @@ class Connection implements TranslatorAwareInterface
* A support method for checkFunction(). This is responsible for checking * A support method for checkFunction(). This is responsible for checking
* the driver configuration to determine if the system supports Cancelling Holds. * the driver configuration to determine if the system supports Cancelling Holds.
* *
* @param string $functionConfig The Cancel Hold configuration values * @param array $functionConfig The Cancel Hold configuration values
* *
* @return mixed On success, an associative array with specific function keys * @return mixed On success, an associative array with specific function keys
* and values either for cancelling holds via a form or a URL; * and values either for cancelling holds via a form or a URL;
...@@ -325,7 +327,7 @@ class Connection implements TranslatorAwareInterface ...@@ -325,7 +327,7 @@ class Connection implements TranslatorAwareInterface
* A support method for checkFunction(). This is responsible for checking * A support method for checkFunction(). This is responsible for checking
* the driver configuration to determine if the system supports Renewing Items. * the driver configuration to determine if the system supports Renewing Items.
* *
* @param string $functionConfig The Renewal configuration values * @param array $functionConfig The Renewal configuration values
* *
* @return mixed On success, an associative array with specific function keys * @return mixed On success, an associative array with specific function keys
* and values either for renewing items via a form or a URL; on failure, false. * and values either for renewing items via a form or a URL; on failure, false.
...@@ -356,7 +358,7 @@ class Connection implements TranslatorAwareInterface ...@@ -356,7 +358,7 @@ class Connection implements TranslatorAwareInterface
* the driver configuration to determine if the system supports storage * the driver configuration to determine if the system supports storage
* retrieval requests. * retrieval requests.
* *
* @param string $functionConfig The storage retrieval request configuration * @param array $functionConfig The storage retrieval request configuration
* values * values
* *
* @return mixed On success, an associative array with specific function keys * @return mixed On success, an associative array with specific function keys
...@@ -390,7 +392,7 @@ class Connection implements TranslatorAwareInterface ...@@ -390,7 +392,7 @@ class Connection implements TranslatorAwareInterface
* the driver configuration to determine if the system supports Cancelling * the driver configuration to determine if the system supports Cancelling
* Storage Retrieval Requests. * Storage Retrieval Requests.
* *
* @param string $functionConfig The Cancel function configuration values * @param array $functionConfig The Cancel function configuration values
* *
* @return mixed On success, an associative array with specific function keys * @return mixed On success, an associative array with specific function keys
* and values either for cancelling requests via a form or a URL; * and values either for cancelling requests via a form or a URL;
...@@ -423,7 +425,7 @@ class Connection implements TranslatorAwareInterface ...@@ -423,7 +425,7 @@ class Connection implements TranslatorAwareInterface
* the driver configuration to determine if the system supports storage * the driver configuration to determine if the system supports storage
* retrieval requests. * retrieval requests.
* *
* @param string $functionConfig The ILL request configuration values * @param array $functionConfig The ILL request configuration values
* *
* @return mixed On success, an associative array with specific function keys * @return mixed On success, an associative array with specific function keys
* and values either for placing requests via a form; on failure, false. * and values either for placing requests via a form; on failure, false.
...@@ -456,7 +458,7 @@ class Connection implements TranslatorAwareInterface ...@@ -456,7 +458,7 @@ class Connection implements TranslatorAwareInterface
* the driver configuration to determine if the system supports Cancelling * the driver configuration to determine if the system supports Cancelling
* ILL Requests. * ILL Requests.
* *
* @param string $functionConfig The Cancel function configuration values * @param array $functionConfig The Cancel function configuration values
* *
* @return mixed On success, an associative array with specific function keys * @return mixed On success, an associative array with specific function keys
* and values either for cancelling requests via a form or a URL; * and values either for cancelling requests via a form or a URL;
...@@ -517,7 +519,9 @@ class Connection implements TranslatorAwareInterface ...@@ -517,7 +519,9 @@ class Connection implements TranslatorAwareInterface
*/ */
public function checkRequestIsValid($id, $data, $patron) public function checkRequestIsValid($id, $data, $patron)
{ {
if ($this->checkCapability('checkRequestIsValid')) { if ($this->checkCapability(
'checkRequestIsValid', compact('id', 'data', 'patron')
)) {
return $this->getDriver()->checkRequestIsValid($id, $data, $patron); return $this->getDriver()->checkRequestIsValid($id, $data, $patron);
} }
// If the driver has no checkRequestIsValid method, we will assume that // If the driver has no checkRequestIsValid method, we will assume that
...@@ -540,7 +544,9 @@ class Connection implements TranslatorAwareInterface ...@@ -540,7 +544,9 @@ class Connection implements TranslatorAwareInterface
*/ */
public function checkStorageRetrievalRequestIsValid($id, $data, $patron) public function checkStorageRetrievalRequestIsValid($id, $data, $patron)
{ {
if ($this->checkCapability('checkStorageRetrievalRequestIsValid')) { if ($this->checkCapability(
'checkStorageRetrievalRequestIsValid', compact('id', 'data', 'patron')
)) {
return $this->getDriver()->checkStorageRetrievalRequestIsValid( return $this->getDriver()->checkStorageRetrievalRequestIsValid(
$id, $data, $patron $id, $data, $patron
); );
...@@ -564,7 +570,9 @@ class Connection implements TranslatorAwareInterface ...@@ -564,7 +570,9 @@ class Connection implements TranslatorAwareInterface
*/ */
public function checkILLRequestIsValid($id, $data, $patron) public function checkILLRequestIsValid($id, $data, $patron)
{ {
if ($this->checkCapability('checkILLRequestIsValid')) { if ($this->checkCapability(
'checkILLRequestIsValid', compact('id', 'data', 'patron')
)) {
return $this->getDriver()->checkILLRequestIsValid( return $this->getDriver()->checkILLRequestIsValid(
$id, $data, $patron $id, $data, $patron
); );
...@@ -625,7 +633,7 @@ class Connection implements TranslatorAwareInterface ...@@ -625,7 +633,7 @@ class Connection implements TranslatorAwareInterface
public function hasHoldings($id) public function hasHoldings($id)
{ {
// Graceful degradation -- return true if no method supported. // Graceful degradation -- return true if no method supported.
return $this->checkCapability('hasHoldings') return $this->checkCapability('hasHoldings', compact('id'))
? $this->getDriver()->hasHoldings($id) : true; ? $this->getDriver()->hasHoldings($id) : true;
} }
...@@ -654,19 +662,18 @@ class Connection implements TranslatorAwareInterface ...@@ -654,19 +662,18 @@ class Connection implements TranslatorAwareInterface
*/ */
public function checkCapability($method, $params = array()) public function checkCapability($method, $params = array())
{ {
// If possible, we want to try to check the capability without the expense // First check that the function is callable without the expense of
// of instantiating an object: // initializing the driver:
if (is_callable(array($this->getDriverClass(), $method))) { if (is_callable(array($this->getDriverClass(), $method))) {
// At least drivers implementing the __call() magic method must also
// implement supportsMethod() to verify that the method is actually
// usable:
if (method_exists($this->getDriverClass(), 'supportsMethod')) {
return $this->getDriver()->supportsMethod($method, $params);
}
return true; return true;
} }
// The problem with is_callable is that it doesn't work well for classes
// implementing the __call() magic method; to compensate for this, ILS
// drivers using __call() must also implement supportsMethod().
if (is_callable(array($this->getDriverClass(), 'supportsMethod'))) {
return $this->getDriver()->supportsMethod($method, $params);
}
// If we got this far, the feature is unsupported: // If we got this far, the feature is unsupported:
return false; return false;
} }
......
This diff is collapsed.
...@@ -91,41 +91,6 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase ...@@ -91,41 +91,6 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase
$this->assertEquals(array(), $val); $this->assertEquals(array(), $val);
} }
/**
* Test that MultiBackend can pull instance information from parameters.
*
* @return void
*/
public function testGetInstanceFromParams()
{
//Case: Can't find the delimiter
//Result: Null
$driver = $this->getDriver();
$patronParam = array(array(
$this->getUserObject('username', 'institution')
));
$delimiters = array('login' => "thiswillnotbefound");
$this->setProperty($driver, 'delimiters', $delimiters);
$instance = $this->callMethod(
$driver,
'getInstanceFromParams',
$patronParam
);
$this->assertNull($instance);
//Case: Can find the delimiter
//Result: Return part before the delimiter
$delimiters['login'] = "\t";
$this->setProperty($driver, 'delimiters', $delimiters);
$instance = $this->callMethod(
$driver,
'getInstanceFromParams',
$patronParam
);
$this->assertSame('institution', $instance);
}
/** /**
* Test that MultiBackend can properly find a driver and pass * Test that MultiBackend can properly find a driver and pass
* log in credentials to it * log in credentials to it
...@@ -148,11 +113,6 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase ...@@ -148,11 +113,6 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase
->method('patronLogin') ->method('patronLogin')
->with('username', 'password') ->with('username', 'password')
->will($this->returnValue($patronReturn)); ->will($this->returnValue($patronReturn));
$ILS->expects($this->at(2))
->method('patronLogin')
->with('bad', 'info')
->will($this->returnValue(null));
//Prep MultiBackend with values it will need //Prep MultiBackend with values it will need
$drivers = array($instance => 'Voyager'); $drivers = array($instance => 'Voyager');
...@@ -165,7 +125,7 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase ...@@ -165,7 +125,7 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase
$this->setproperty($driver, 'delimiters', $delimiters); $this->setproperty($driver, 'delimiters', $delimiters);
//Call the method //Call the method
$patron = $driver->patronLogin('username', 'password'); $patron = $driver->patronLogin("$instance\tusername", 'password');
//Check that it added username info properly. //Check that it added username info properly.
$this->assertSame( $this->assertSame(
...@@ -179,8 +139,8 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase ...@@ -179,8 +139,8 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase
$patron['cat_username'] $patron['cat_username']
); );
$patron = $driver->patronLogin("bad", "info"); $this->setExpectedException('VuFind\Exception\ILS');
$this->assertNull($patron); $driver->patronLogin("bad", "info");
} }
/** /**
...@@ -308,16 +268,17 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase ...@@ -308,16 +268,17 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase
{ {
$driver = $this->getDriver(); $driver = $this->getDriver();
//Set up the mock driver to be retrieved //Set up the mock driver to be retrieved
$ILS = $this->getMockILS('Voyager', array('setConfig')); $ILS = $this->getMockILS('Voyager', array('setConfig', 'init'));
$ILS->expects($this->once()) $ILS->expects($this->once())
->method('setConfig') ->method('setConfig')
->with(array('config' => 'values')); ->with(array('config' => 'values'));
$ILS->expects($this->once())
->method('init');
//Set up the ServiceLocator so it returns our mock driver //Set up the ServiceLocator so it returns our mock driver
$sm = $this->getMockSM($this->once(), 'Voyager', $ILS); $sm = $this->getMockSM($this->once(), 'Voyager', $ILS);
$driver->setServiceLocator($sm); $driver->setServiceLocator($sm);
//Add an entry for our test driver to the array of drivers //Add an entry for our test driver to the array of drivers
$drivers = array('testing3' => 'Voyager'); $drivers = array('testing3' => 'Voyager');
$this->setProperty($driver, 'drivers', $drivers); $this->setProperty($driver, 'drivers', $drivers);
...@@ -356,317 +317,8 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase ...@@ -356,317 +317,8 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase
$methodReturn = $driver->supportsMethod('fail', null); $methodReturn = $driver->supportsMethod('fail', null);
$this->assertFalse($methodReturn); $this->assertFalse($methodReturn);
//Case: The method exists in at least 1 of the drivers
//Result: A return of true
$methodReturn = $driver->supportsMethod('getStatus', null);
$this->assertTrue($methodReturn);
}
/**
* Test that MultiBackend can properly tell whether or not
* a driver is has contains a specified method.
*
* @return void
*/
public function testRunIfPossible()
{
$driver = $this->getDriver();
//Set up the mock driver to be retrieved
$ILS = $this->getMockILS('Voyager', array('init', 'getStatus'));
$ILS->expects($this->once())
->method('getStatus')
->with('custID')
->will($this->returnValue('worked'));
//Set up the ServiceLocator so it returns our mock driver
$sm = $this->getMockSM($this->once(), 'Voyager', $ILS);
$driver->setServiceLocator($sm);
//Add an entry for our test driver to the array of drivers
$drivers = array('testing4' => 'Voyager');
$this->setProperty($driver, 'drivers', $drivers);
//Prepare variables
$called = false;
$params = array('testing4', //$instName
'getStatus', //$methodName
array('custID'), //$params
&$called); //&$called
//Case: Method should be called
//Result: $called is true, we return the called functions return
$returnVal = $this->callMethod($driver, 'runIfPossible', $params);
$this->assertTrue($called);
$this->assertSame('worked', $returnVal);
//Case: Method does not exist
//Result: $called is false, returns false
$called = false;
$params[1] = 'fakeMethod';
$returnVal = $this->callMethod($driver, 'runIfPossible', $params);
$this->assertFalse($called);
$this->assertFalse($returnVal);
//Case: No instance is given to run the method on
//Result: Same as previous case
$params[0] = null;
$params[1] = 'getStatus';
$returnVal = $this->callMethod($driver, 'runIfPossible', $params);
$this->assertFalse($called);
$this->assertFalse($returnVal);
}
/**
* Test that MultiBackend can properly tell what functionality a
* method should use for their return values.
*
* @return void
*/
public function testGetMethodBehavior()
{
//Case: There is no configured behavior
//Result: We use 'use_first', hardcoded into MultiBackend.
$driver = $this->getDriver();
$returnVal = $this->callMethod(
$driver,
'getMethodBehavior',
array('method')
);
$this->assertSame('use_first', $returnVal);
//Case: The default is overridden by the config
//Result: We use the value for the default selection method.
$var = 'default_fallback_driver_selection';
$config = array(
'General'=> array(
$var => 'usingThis'),
);
$this->setProperty($driver, 'config', $config);
$returnVal = $this->callMethod(
$driver,
'getMethodBehavior',
array('method')
);
$this->assertSame('usingThis', $returnVal);
//Case: A specific function is overridden in the config
//Result: That fuction will use that specific functionality
$section = 'FallbackDriverSelectionOverride';
$config[$section] = array('method' => 'overridden');
$this->setProperty($driver, 'config', $config);
$returnVal = $this->callMethod(
$driver,
'getMethodBehavior',
array('method')
);
$this->assertSame('overridden', $returnVal);
} }
/**
* Test that MultiBackend can find and use the correct ILS driver if it is given
* a method and parameters, but no direction as towards what driver to use.
*
* @return void
*/
public function testRunMethodNoILS()
{
$driver = $this->getDriver();
$config = array(
'General'=> array(
'default_fallback_driver_selection' => 'use_first'),
'FallbackDriverSelectionOverride' =>array(
'getStatuses' => 'merge')
);
$this->setProperty($driver, 'config', $config);
//Case: Nonexistent method
//Result: return false, $called false
//Set up the mock driver to be retrieved
$ILS = $this->getMockILS('Voyager', array('getStatus', 'init'));
$ILS->expects($this->once())
->method('getStatus')
->with('custID')
->will($this->returnValue('worked'));
//Set up the ServiceLocator so it returns our mock driver
$sm = $this->getMockSM($this->any(), 'Voyager', $ILS);
$driver->setServiceLocator($sm);
//Add an entry for our test driver to the array of drivers
$drivers = array('testing5' => 'Voyager');
$this->setProperty($driver, 'drivers', $drivers);
$called = false;
$params = array('fake method', array('custID'), &$called);
$returnVal = $this->callMethod($driver, 'runMethodNoILS', $params);
$this->assertFalse($called);
$this->assertFalse($returnVal);
//Case: Method use_first/not an array
//Result: return method data, $called true
$params[0] = 'getStatus';
$returnVal = $this->callMethod($driver, 'runMethodNoILS', $params);
$this->assertTrue($called);
$this->assertSame('worked', $returnVal);
//Case: Method merge, need a second ILS to test
//Result: return combined data in an array, $called true
$ILS = $this->getMockILS('Voyager', array('getStatuses', 'init'));
$ILS->expects($this->once())
->method('getStatuses')
->with('custID')
->will($this->returnValue(array('worked1', 'worked2')));
$ILS2 = $this->getMockILS('Voyager', array('getStatuses', 'init'));
$ILS2->expects($this->once())
->method('getStatuses')
->with('custID')
->will($this->returnValue(array('worked3', 'worked4')));
// We have to do it this way because we're not actualy setting different
// configurations. Can't use out method because we're doing tricky stuff
// with PHPunit
$sm = $this->getMockForAbstractClass(
'Zend\ServiceManager\ServiceLocatorInterface'
);
$sm->expects($this->exactly(2))
->method('get')
->with('Voyager')
->will($this->onConsecutiveCalls($ILS, $ILS2));
$driver->setServiceLocator($sm);
$drivers = array('testing6' => 'Voyager', 'testing7' => 'Voyager');
$this->setProperty($driver, 'drivers', $drivers);
$params[0] = 'getStatuses';
$called = false;
$returnVal = $this->callMethod($driver, 'runMethodNoILS', $params);
$this->assertTrue($called);
$shouldReturn = array('worked1', 'worked2', 'worked3', 'worked4');
$this->assertSame($shouldReturn, $returnVal);
}
/**
* Test that MultiBackend can find and use the correct ILS driver given a call
* to a function that it does not know about
*
* @return void
*/
public function testCall()
{
$driver = $this->getDriver();
//Case: The parameters let it know what driver to use
//Result: return the function results for that driver
$patron = $this->getUserObject('username', 'institution');
$delimiters = array('login' => "\t");
$drivers = array(
'otherinst' => 'Unicorn',
'institution' => 'Voyager'
);
$this->setProperty($driver, 'delimiters', $delimiters);
$this->setProperty($driver, 'drivers', $drivers);
$ILS = $this->getMockILS('Voyager', array('getMyTransactions', 'init'));
$ILS->expects($this->atLeastOnce())
->method('getMyTransactions')
->with($patron)
->will($this->returnValue(true));
$sm = $this->getMockSM($this->any(), 'Voyager', $ILS);
$driver->setServiceLocator($sm);
//Run the method invoking the __call method on our $user object
//which has the instance set to 'institution'
$returnVal = $driver->getMyTransactions($patron);
$this->assertTrue($returnVal);
//Case: There is a default driver set in the configuration
//Result: return the function results for that driver
// We need to clear patron login information so __call has to fall back on
// the defaultDriver implementation
$patron['cat_username'] = 'username';
$ILS = $this->getMockILS('Unicorn', array('getMyTransactions', 'init'));
$ILS->expects($this->atLeastOnce())
->method('getMyTransactions')
->with($patron)
->will($this->returnValue(true));
$sm = $this->getMockSM($this->any(), 'Unicorn', $ILS);
$driver->setServiceLocator($sm);
$this->setProperty($driver, 'defaultDriver', 'otherinst');
$returnVal = $driver->getMyTransactions($patron);
$this->assertTrue($returnVal);
//Case: No idea what ILS to use
//Result: the result of runMethodNoILS
$config = array(
'General'=> array(
'default_fallback_driver_selection' => 'use_first')
);
// Need to clear the default driver. We already cleared patron
// information in the last set of asserts
// Koha has "getHoldLink" and Horizon does not, we can use this to test
// to make sure that it won't call the function on a driver that
// does not have that method.
$drivers = array(
'inst1' => 'Horizon',
'inst2' => 'Koha'
);
$this->setProperty($driver, 'drivers', $drivers);
$this->setProperty($driver, 'defaultDriver', null);
$this->setProperty($driver, 'config', $config);
// It'll use the first driver it hits, so we want to prep
// our mocks to use that one. Have to do a manual SM setup
// for this one.
$ILS = $this->getMockILS('Koha', array('getHoldLink', 'init'));
$ILS->expects($this->once())
->method('getHoldLink')
->with('id', 'details')
->will($this->returnValue(true));
$ILS2 = $this->getMockILS('Horizon');
$ILS2->expects($this->never())
->method('getHoldLink');
$sm = $this->getMockForAbstractClass(
'Zend\ServiceManager\ServiceLocatorInterface'
);
$sm->expects($this->at(0))
->method('get')
->with('Horizon')
->will($this->returnValue($ILS2));
$sm->expects($this->at(1))
->method('get')
->with('Koha')
->will($this->returnValue($ILS));
$sm->expects($this->exactly(2))
->method('get');
$driver->setServiceLocator($sm);
$returnVal = $driver->getHoldLink('id', 'details');
$this->assertTrue($returnVal);
//Case: Nothing to do
//Result: new ILSException
$this->setExpectedException('VuFind\Exception\ILS');
$returnVal = $driver->ThisIsNotAMethodOfAnyDriver($patron);
}
/** /**
* Testing method for addIdPrefixes * Testing method for addIdPrefixes
* *
...@@ -739,13 +391,15 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase ...@@ -739,13 +391,15 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase
= $this->callMethod($driver, 'stripIdPrefixes', array($data, $source)); = $this->callMethod($driver, 'stripIdPrefixes', array($data, $source));
$this->assertEquals("record", $result); $this->assertEquals("record", $result);
$delimiters = array('login' => "\t");
$this->setproperty($driver, 'delimiters', $delimiters);
$expected = array( $expected = array(
"id" => "record1", "id" => "record1",
"cat_username" => "record2" "cat_username" => "record2"
); );
$data = array( $data = array(
"id" => "$source.record1", "id" => "$source.record1",
"cat_username" => "$source.record2"); "cat_username" => "$source\trecord2");
$result $result
= $this->callMethod($driver, 'stripIdPrefixes', array($data, $source)); = $this->callMethod($driver, 'stripIdPrefixes', array($data, $source));
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
...@@ -766,7 +420,7 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase ...@@ -766,7 +420,7 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase
"id" => "$source.record2", "id" => "$source.record2",
"cat_username" => array( "cat_username" => array(
"id" => "$source.record3", "id" => "$source.record3",
"cat_username" => "$source.record4"), "cat_username" => "$source\trecord4"),
"cat_info" => "$source.record5"), "cat_info" => "$source.record5"),
"cat_info" => "$source.record6" "cat_info" => "$source.record6"
); );
...@@ -805,7 +459,7 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase ...@@ -805,7 +459,7 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase
if ($param == '123456') { if ($param == '123456') {
return array("id" => "123456", "status" => "in"); return array("id" => "123456", "status" => "in");
} }
return null; return array();
} }
) )
); );
...@@ -851,7 +505,7 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase ...@@ -851,7 +505,7 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase
$this->assertEquals($driverReturn, $return); $this->assertEquals($driverReturn, $return);
$return = $driver->getPurchaseHistory("fail.$id"); $return = $driver->getPurchaseHistory("fail.$id");
$this->assertNull($return); $this->assertEquals(array(), $return);
} }
...@@ -930,6 +584,65 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase ...@@ -930,6 +584,65 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase
$this->assertEquals($term, $return); $this->assertEquals($term, $return);
} }
/**
* Test that MultiBackend can find and use the default ILS driver if parameters
* don't include a detectable source id
*
* @return void
*/
public function testDefaultDriver()
{
$driver = $this->getDriver();
//Case: The parameters let it know what driver to use
//Result: return the function results for that driver
$patron = $this->getUserObject('username', 'institution');
$delimiters = array('login' => "\t");
$drivers = array(
'otherinst' => 'Unicorn',
'institution' => 'Voyager'
);
$this->setProperty($driver, 'delimiters', $delimiters);
$this->setProperty($driver, 'drivers', $drivers);
$patronPrefixless = $this->callMethod(
$driver, 'stripIdPrefixes', array($patron, 'institution')
);
$ILS = $this->getMockILS('Voyager', array('getMyTransactions', 'init'));
$ILS->expects($this->atLeastOnce())
->method('getMyTransactions')
->with($patronPrefixless)
->will($this->returnValue(true));
$sm = $this->getMockSM($this->any(), 'Voyager', $ILS);
$driver->setServiceLocator($sm);
$returnVal = $driver->getMyTransactions($patron);
$this->assertTrue($returnVal);
//Case: There is a default driver set in the configuration
//Result: return the function results for that driver
// We need to clear patron login information so that MultiBackend has to
// fall back on the defaultDriver implementation
$patron['cat_username'] = 'username';
$ILS = $this->getMockILS('Unicorn', array('getMyTransactions', 'init'));
$ILS->expects($this->atLeastOnce())
->method('getMyTransactions')
->with($patron)
->will($this->returnValue(true));
$sm = $this->getMockSM($this->any(), 'Unicorn', $ILS);
$driver->setServiceLocator($sm);
$this->setProperty($driver, 'defaultDriver', 'otherinst');
$returnVal = $driver->getMyTransactions($patron);
$this->assertTrue($returnVal);
}
/** /**
* Method to get a fresh MultiBackend Driver. * Method to get a fresh MultiBackend Driver.
* *
......
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