diff --git a/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php b/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php index 0a6e35349fb87ebcc252c89b8bd82d325bf5fc72..0339706bfe278b53a59dd188a797d20472fd6c23 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php +++ b/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php @@ -293,6 +293,54 @@ class MultiBackend extends AbstractBase return []; } + /** + * Get Departments + * + * Obtain a list of departments for use in limiting the reserves list. + * + * @return array An associative array with key = dept. ID, value = dept. name. + */ + public function getDepartments() + { + $driver = $this->getDriver($this->defaultDriver); + if ($driver) { + return $driver->getDepartments(); + } + return []; + } + + /** + * Get Instructors + * + * Obtain a list of instructors for use in limiting the reserves list. + * + * @return array An associative array with key = ID, value = name. + */ + public function getInstructors() + { + $driver = $this->getDriver($this->defaultDriver); + if ($driver) { + return $driver->getInstructors(); + } + return []; + } + + /** + * Get Courses + * + * Obtain a list of courses for use in limiting the reserves list. + * + * @return array An associative array with key = ID, value = name. + */ + public function getCourses() + { + $driver = $this->getDriver($this->defaultDriver); + if ($driver) { + return $driver->getCourses(); + } + return []; + } + /** * Find Reserves * @@ -308,7 +356,11 @@ class MultiBackend extends AbstractBase { $driver = $this->getDriver($this->defaultDriver); if ($driver) { - return $driver->findReserves($course, $inst, $dept); + return $this->addIdPrefixes( + $driver->findReserves($course, $inst, $dept), + $this->defaultDriver, + ['BIB_ID'] + ); } return []; } diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php index 08700dbd610b4f945b867331dfd487ea252c026d..86de298bd4d89f33c93fa13014daaabd7aecc92d 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/ILS/Driver/MultiBackendTest.php @@ -798,27 +798,127 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase } /** - * Testing method for findReserves + * Testing method for getCourses * * @return void */ - public function testFindReserves() + public function testGetCourses() { $expected = ['test' => 'true']; $driver = $this->initSimpleMethodTest( $this->once(), $this->never(), - 'findReserves', - ['course', 'inst', 'dept'], + 'getCourses', + [], $expected, $expected ); + // getCourses only works with a default driver, so the first calls fails + $result = $driver->getCourses(); + $this->assertEquals([], $result); + + $this->setProperty($driver, 'defaultDriver', 'd1'); + $result = $driver->getCourses(); + $this->assertEquals($expected, $result); + } + + /** + * Testing method for getDepartments + * + * @return void + */ + public function testGetDepartments() + { + $expected = ['test' => 'true']; + $driver = $this->initSimpleMethodTest( + $this->once(), + $this->never(), + 'getDepartments', + [], + $expected, + $expected + ); + + // getCourses only works with a default driver, so the first calls fails + $result = $driver->getDepartments(); + $this->assertEquals([], $result); + + $this->setProperty($driver, 'defaultDriver', 'd1'); + $result = $driver->getDepartments(); + $this->assertEquals($expected, $result); + } + + /** + * Testing method for getInstructors + * + * @return void + */ + public function testGetInstructors() + { + $expected = ['test' => 'true']; + $driver = $this->initSimpleMethodTest( + $this->once(), + $this->never(), + 'getInstructors', + [], + $expected, + $expected + ); + + // getCourses only works with a default driver, so the first calls fails + $result = $driver->getInstructors(); + $this->assertEquals([], $result); + + $this->setProperty($driver, 'defaultDriver', 'd1'); + $result = $driver->getInstructors(); + $this->assertEquals($expected, $result); + } + + /** + * Testing method for findReserves + * + * @return void + */ + public function testFindReserves() + { + $driver = $this->getDriver(); + $drivers = ['d1' => 'Voyager']; + $this->setProperty($driver, 'drivers', $drivers); + $id = '123456'; + + $reservesReturn = [ + [ + 'BIB_ID' => '12345', + 'COURSE_ID' => 1, + 'DEPARTMENT_ID' => 2, + 'INSTRUCTOR_ID' => 3, + ], + [ + 'BIB_ID' => '56789', + 'COURSE_ID' => 4, + 'DEPARTMENT_ID' => 5, + 'INSTRUCTOR_ID' => 6, + ] + ]; + + $ILS = $this->getMockILS('Voyager', ['findReserves', 'init']); + $ILS->expects($this->once()) + ->method('findReserves') + ->with($this->equalTo('course'), $this->equalTo('inst'), $this->equalTo('dept')) + ->will($this->returnValue($reservesReturn)); + + $sm = $this->getMockSM($this->any(), 'Voyager', $ILS); + $driver->setServiceLocator($sm); + // findReserves only works with a default driver, so the first calls fails $result = $driver->findReserves('course', 'inst', 'dept'); $this->assertEquals([], $result); $this->setProperty($driver, 'defaultDriver', 'd1'); + $expected = $reservesReturn; + $expected[0]['BIB_ID'] = 'd1.' . $expected[0]['BIB_ID']; + $expected[1]['BIB_ID'] = 'd1.' . $expected[1]['BIB_ID']; $result = $driver->findReserves('course', 'inst', 'dept'); $this->assertEquals($expected, $result); }