Bug 40542: Add cancellation_reason to Koha::Hold->strings_map
This patch adds the mentioned AV to the returned strings structure.
It also adds tests for the method.
To test:
1. Apply this patch
2. Run:
$ ktd --shell
k$ prove t/db_dependent/Koha/Hold.t
=> SUCCESS: Tests pass!
3. Sign off :-D
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 0f533c1ceb)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
parent
cb504d5cc7
commit
e991fc4057
30
Koha/Hold.pm
30
Koha/Hold.pm
|
|
@ -1067,10 +1067,34 @@ Returns a map of column name to string representations including the string.
|
|||
=cut
|
||||
|
||||
sub strings_map {
|
||||
my ($self) = @_;
|
||||
return {
|
||||
pickup_library_id => { str => $self->branch->branchname, type => 'library' },
|
||||
my ( $self, $params ) = @_;
|
||||
|
||||
my $strings = {
|
||||
pickup_library_id => { str => $self->pickup_library->branchname, type => 'library' },
|
||||
};
|
||||
|
||||
if ( defined $self->cancellation_reason ) {
|
||||
my $av = Koha::AuthorisedValues->search(
|
||||
{
|
||||
category => 'HOLD_CANCELLATION',
|
||||
authorised_value => $self->cancellation_reason,
|
||||
}
|
||||
);
|
||||
my $cancellation_reason_str =
|
||||
$av->count
|
||||
? $params->{public}
|
||||
? $av->next->opac_description
|
||||
: $av->next->lib
|
||||
: $self->cancellation_reason;
|
||||
|
||||
$strings->{cancellation_reason} = {
|
||||
category => 'HOLD_CANCELLATION',
|
||||
str => $cancellation_reason_str,
|
||||
type => 'av',
|
||||
};
|
||||
}
|
||||
|
||||
return $strings;
|
||||
}
|
||||
|
||||
=head2 Internal methods
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
use Modern::Perl;
|
||||
|
||||
use Test::NoWarnings;
|
||||
use Test::More tests => 15;
|
||||
use Test::More tests => 16;
|
||||
|
||||
use Test::Exception;
|
||||
use Test::MockModule;
|
||||
|
|
@ -1200,3 +1200,62 @@ subtest 'change_type() tests' => sub {
|
|||
|
||||
$schema->storage->txn_rollback;
|
||||
};
|
||||
|
||||
subtest 'strings_map() tests' => sub {
|
||||
|
||||
plan tests => 3;
|
||||
|
||||
$schema->txn_begin;
|
||||
|
||||
my $av = Koha::AuthorisedValue->new(
|
||||
{
|
||||
category => 'HOLD_CANCELLATION',
|
||||
authorised_value => 'JUST_BECAUSE',
|
||||
lib => 'Just because',
|
||||
lib_opac => 'Serious reasons',
|
||||
}
|
||||
)->store;
|
||||
|
||||
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
|
||||
|
||||
my $hold = $builder->build_object(
|
||||
{
|
||||
class => 'Koha::Holds',
|
||||
value => { cancellation_reason => $av->authorised_value, branchcode => $library->id }
|
||||
}
|
||||
);
|
||||
|
||||
my $strings_map = $hold->strings_map( { public => 0 } );
|
||||
is_deeply(
|
||||
$strings_map,
|
||||
{
|
||||
pickup_library_id => { str => $library->branchname, type => 'library' },
|
||||
cancellation_reason => { str => $av->lib, type => 'av', category => 'HOLD_CANCELLATION' },
|
||||
},
|
||||
'Strings map is correct'
|
||||
);
|
||||
|
||||
$strings_map = $hold->strings_map( { public => 1 } );
|
||||
is_deeply(
|
||||
$strings_map,
|
||||
{
|
||||
pickup_library_id => { str => $library->branchname, type => 'library' },
|
||||
cancellation_reason => { str => $av->lib_opac, type => 'av', category => 'HOLD_CANCELLATION' },
|
||||
},
|
||||
'Strings map is correct (OPAC)'
|
||||
);
|
||||
|
||||
$av->delete();
|
||||
|
||||
$strings_map = $hold->strings_map( { public => 1 } );
|
||||
is_deeply(
|
||||
$strings_map,
|
||||
{
|
||||
pickup_library_id => { str => $library->branchname, type => 'library' },
|
||||
cancellation_reason => { str => $hold->cancellation_reason, type => 'av', category => 'HOLD_CANCELLATION' },
|
||||
},
|
||||
'Strings map shows the cancellation_value when AV not present'
|
||||
);
|
||||
|
||||
$schema->txn_rollback;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue