Skip to content

Commit

Permalink
Fix bug with multiple call number message handling (#4159)
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz authored Dec 11, 2024
1 parent b3abb1a commit daba7b1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
11 changes: 8 additions & 3 deletions module/VuFind/src/VuFind/AjaxHandler/GetItemStatuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,28 +327,82 @@ 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.
*
* @param bool $fullStatus Whether to show full item status in results
* @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
*/
protected function getConfigIniOverrides(
bool $fullStatus,
string $multipleLocations,
bool $loadBatchWise = true,
bool $loadObservableOnly = true
bool $loadObservableOnly = true,
string $multipleCallNos = 'first'
): array {
return [
'Catalog' => [
'driver' => 'Demo',
],
'Item_Status' => [
'show_full_status' => $fullStatus,
'multiple_call_nos' => $multipleCallNos,
'multiple_locations' => $multipleLocations,
'load_batch_wise' => $loadBatchWise,
'load_observable_only' => $loadObservableOnly,
Expand Down

0 comments on commit daba7b1

Please sign in to comment.