View | Details | Raw Unified | Return to bug 40542
Collapse All | Expand All

(-)a/Koha/Hold.pm (-3 / +27 lines)
Lines 1067-1076 Returns a map of column name to string representations including the string. Link Here
1067
=cut
1067
=cut
1068
1068
1069
sub strings_map {
1069
sub strings_map {
1070
    my ($self) = @_;
1070
    my ( $self, $params ) = @_;
1071
    return {
1071
1072
        pickup_library_id => { str => $self->branch->branchname, type => 'library' },
1072
    my $strings = {
1073
        pickup_library_id => { str => $self->pickup_library->branchname, type => 'library' },
1073
    };
1074
    };
1075
1076
    if ( defined $self->cancellation_reason ) {
1077
        my $av = Koha::AuthorisedValues->search(
1078
            {
1079
                category         => 'HOLD_CANCELLATION',
1080
                authorised_value => $self->cancellation_reason,
1081
            }
1082
        );
1083
        my $cancellation_reason_str =
1084
              $av->count
1085
            ? $params->{public}
1086
                ? $av->next->opac_description
1087
                : $av->next->lib
1088
            : $self->cancellation_reason;
1089
1090
        $strings->{cancellation_reason} = {
1091
            category => 'HOLD_CANCELLATION',
1092
            str      => $cancellation_reason_str,
1093
            type     => 'av',
1094
        };
1095
    }
1096
1097
    return $strings;
1074
}
1098
}
1075
1099
1076
=head2 Internal methods
1100
=head2 Internal methods
(-)a/t/db_dependent/Koha/Hold.t (-2 / +60 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::NoWarnings;
22
use Test::NoWarnings;
23
use Test::More tests => 15;
23
use Test::More tests => 16;
24
24
25
use Test::Exception;
25
use Test::Exception;
26
use Test::MockModule;
26
use Test::MockModule;
Lines 1200-1202 subtest 'change_type() tests' => sub { Link Here
1200
1200
1201
    $schema->storage->txn_rollback;
1201
    $schema->storage->txn_rollback;
1202
};
1202
};
1203
- 
1203
1204
subtest 'strings_map() tests' => sub {
1205
1206
    plan tests => 3;
1207
1208
    $schema->txn_begin;
1209
1210
    my $av = Koha::AuthorisedValue->new(
1211
        {
1212
            category         => 'HOLD_CANCELLATION',
1213
            authorised_value => 'JUST_BECAUSE',
1214
            lib              => 'Just because',
1215
            lib_opac         => 'Serious reasons',
1216
        }
1217
    )->store;
1218
1219
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
1220
1221
    my $hold = $builder->build_object(
1222
        {
1223
            class => 'Koha::Holds',
1224
            value => { cancellation_reason => $av->authorised_value, branchcode => $library->id }
1225
        }
1226
    );
1227
1228
    my $strings_map = $hold->strings_map( { public => 0 } );
1229
    is_deeply(
1230
        $strings_map,
1231
        {
1232
            pickup_library_id   => { str => $library->branchname, type => 'library' },
1233
            cancellation_reason => { str => $av->lib, type => 'av', category => 'HOLD_CANCELLATION' },
1234
        },
1235
        'Strings map is correct'
1236
    );
1237
1238
    $strings_map = $hold->strings_map( { public => 1 } );
1239
    is_deeply(
1240
        $strings_map,
1241
        {
1242
            pickup_library_id   => { str => $library->branchname, type => 'library' },
1243
            cancellation_reason => { str => $av->lib_opac, type => 'av', category => 'HOLD_CANCELLATION' },
1244
        },
1245
        'Strings map is correct (OPAC)'
1246
    );
1247
1248
    $av->delete();
1249
1250
    $strings_map = $hold->strings_map( { public => 1 } );
1251
    is_deeply(
1252
        $strings_map,
1253
        {
1254
            pickup_library_id   => { str => $library->branchname, type => 'library' },
1255
            cancellation_reason => { str => $hold->cancellation_reason, type => 'av', category => 'HOLD_CANCELLATION' },
1256
        },
1257
        'Strings map shows the cancellation_value when AV not present'
1258
    );
1259
1260
    $schema->txn_rollback;
1261
};

Return to bug 40542