From daba7b141af28fcf24a36779df358e2e1e1ef4b2 Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Wed, 11 Dec 2024 02:25:31 -0500 Subject: [PATCH] Fix bug with multiple call number message handling (#4159) --- .../VuFind/AjaxHandler/GetItemStatuses.php | 11 +++- .../src/VuFindTest/Mink/HoldingsTest.php | 56 ++++++++++++++++++- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php index 8356cffd85b..5b58e8a539e 100644 --- a/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php +++ b/module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php @@ -241,10 +241,15 @@ protected function renderCallnumbers(string $callnumberSetting, array $callnumbe $callnumberHandler = $this->getCallnumberHandler($callnumbers, $callnumberSetting); foreach ($callnumbers as $number) { - $displayCallnumber = $actualCallnumber = $number['callnumber']; + // Call number is usually an array, but it could be a flat string if we're in "msg" mode: + if (is_array($number)) { + $displayCallnumber = $actualCallnumber = $number['callnumber']; - if (!empty($number['prefix'])) { - $displayCallnumber = $number['prefix'] . ' ' . $displayCallnumber; + if (!empty($number['prefix'])) { + $displayCallnumber = $number['prefix'] . ' ' . $displayCallnumber; + } + } else { + $displayCallnumber = $actualCallnumber = $number; } $html[] = $this->renderer->render( diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/HoldingsTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/HoldingsTest.php index 723f62560da..dcf1d8b5abf 100644 --- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/HoldingsTest.php +++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/HoldingsTest.php @@ -327,6 +327,57 @@ public function testHoldings( $this->assertEquals($expected, $this->findCssAndGetText($page, ".holdings-tab span.text-$expectedType")); } + /** + * Data provider for testCallNoDisplay(). + * + * @return array[] + */ + public static function callNoDisplayProvider(): array + { + return [ + 'first' => ['first', 'Test1 A1234'], + 'all' => ['all', 'Test1 A1234, Test2 B1234'], + 'msg' => ['msg', 'Multiple Call Numbers'], + ]; + } + + /** + * Test call number display + * + * @param string $mode Call number mode to configure + * @param string $expectedCallNo Expected call number output + * + * @return void + * + * @dataProvider callNoDisplayProvider + */ + public function testCallNoDisplay(string $mode, string $expectedCallNo): void + { + $items = [ + ['callnumber' => 'A1234', 'callnumber_prefix' => 'Test1'], + ['callnumber' => 'B1234', 'callnumber_prefix' => 'Test2'], + ]; + $demoSettings = [ + 'Records' => [ + 'services' => [], + ], + 'Failure_Probabilities' => [ + 'getStatuses' => 0, + ], + 'StaticHoldings' => ['testsample1' => json_encode($items)], + ]; + + $this->changeConfigs( + [ + 'config' => $this->getConfigIniOverrides(false, 'msg', multipleCallNos: $mode), + 'Demo' => $demoSettings, + ] + ); + + $page = $this->goToSearchResults(); + $this->assertEquals($expectedCallNo, $this->findCssAndGetText($page, '.callnumAndLocation .callnumber')); + } + /** * Get config.ini override settings for testing ILS functions. * @@ -334,6 +385,7 @@ public function testHoldings( * @param string $multipleLocations Setting to use for multiple locations * @param bool $loadBatchWise If status should be loaded batch wise * @param bool $loadObservableOnly If status of only observable records should be loaded + * @param string $multipleCallNos Setting to use for multiple call numbers * * @return array */ @@ -341,7 +393,8 @@ protected function getConfigIniOverrides( bool $fullStatus, string $multipleLocations, bool $loadBatchWise = true, - bool $loadObservableOnly = true + bool $loadObservableOnly = true, + string $multipleCallNos = 'first' ): array { return [ 'Catalog' => [ @@ -349,6 +402,7 @@ protected function getConfigIniOverrides( ], 'Item_Status' => [ 'show_full_status' => $fullStatus, + 'multiple_call_nos' => $multipleCallNos, 'multiple_locations' => $multipleLocations, 'load_batch_wise' => $loadBatchWise, 'load_observable_only' => $loadObservableOnly,