From 184b46cf11fb4674e2aae87889c8f036e2011e27 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 14 Aug 2015 08:50:29 -0400 Subject: [PATCH] Fixed MultiBackend support for getNewItems. --- .../src/VuFind/ILS/Driver/MultiBackend.php | 7 ++++- .../ILS/Driver/MultiBackendTest.php | 30 +++++++++++++------ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php b/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php index 0339706bfe2..594f19eaac4 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php +++ b/module/VuFind/src/VuFind/ILS/Driver/MultiBackend.php @@ -288,7 +288,12 @@ class MultiBackend extends AbstractBase { $driver = $this->getDriver($this->defaultDriver); if ($driver) { - return $driver->getNewItems($page, $limit, $daysOld, $fundId); + $result = $driver->getNewItems($page, $limit, $daysOld, $fundId); + if (isset($result['results'])) { + $result['results'] + = $this->addIdPrefixes($result['results'], $this->defaultDriver); + } + return $result; } 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 86de298bd4d..8fec96624ff 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 @@ -778,20 +778,32 @@ class MultiBackendTest extends \VuFindTest\Unit\TestCase */ public function testGetNewItems() { - $expected = ['test' => 'true']; - $driver = $this->initSimpleMethodTest( - $this->once(), - $this->never(), - 'getNewItems', - [1, 10, 5, 0], - $expected, - $expected - ); + $driver = $this->getDriver(); + $drivers = ['d1' => 'Voyager']; + $this->setProperty($driver, 'drivers', $drivers); + + $return = [ + 'count' => 2, + 'results' => ['id' => '1', 'id' => '2'] + ]; + + $ILS = $this->getMockILS('Voyager', ['getNewItems', 'init']); + $ILS->expects($this->once()) + ->method('getNewItems') + ->with($this->equalTo('1'), $this->equalTo('10'), $this->equalTo('5'), $this->equalTo('0')) + ->will($this->returnValue($return)); + + $sm = $this->getMockSM($this->any(), 'Voyager', $ILS); + $driver->setServiceLocator($sm); // getNewItems only works with a default driver, so the first calls fails $result = $driver->getNewItems(1, 10, 5, 0); $this->assertEquals([], $result); + $expected = [ + 'count' => 2, + 'results' => ['id' => 'd1.1', 'id' => 'd1.2'] + ]; $this->setProperty($driver, 'defaultDriver', 'd1'); $result = $driver->getNewItems(1, 10, 5, 0); $this->assertEquals($expected, $result); -- GitLab