Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 23; |
20 |
use Test::More tests => 24; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
use List::MoreUtils qw( uniq ); |
23 |
use List::MoreUtils qw( uniq ); |
Lines 1031-1046
subtest 'UpdateTotalIssues on Invalid record' => sub {
Link Here
|
1031 |
plan tests => 2; |
1031 |
plan tests => 2; |
1032 |
|
1032 |
|
1033 |
my $return_record = Test::MockModule->new('Koha::Biblio::Metadata'); |
1033 |
my $return_record = Test::MockModule->new('Koha::Biblio::Metadata'); |
1034 |
$return_record->mock( 'record', sub { |
1034 |
$return_record->mock( |
1035 |
my $self = shift; |
1035 |
'record', |
1036 |
Koha::Exceptions::Metadata::Invalid->throw( |
1036 |
sub { |
1037 |
id => $self->id, |
1037 |
my $self = shift; |
1038 |
biblionumber => $self->biblionumber, |
1038 |
Koha::Exceptions::Metadata::Invalid->throw( |
1039 |
format => $self->format, |
1039 |
id => $self->id, |
1040 |
schema => $self->schema, |
1040 |
biblionumber => $self->biblionumber, |
1041 |
decoding_error => "Error goes here", |
1041 |
format => $self->format, |
1042 |
); |
1042 |
schema => $self->schema, |
1043 |
} ); |
1043 |
decoding_error => "Error goes here", |
|
|
1044 |
); |
1045 |
} |
1046 |
); |
1044 |
|
1047 |
|
1045 |
my $biblio = $builder->build_sample_biblio; |
1048 |
my $biblio = $builder->build_sample_biblio; |
1046 |
my $biblionumber = $biblio->biblionumber; |
1049 |
my $biblionumber = $biblio->biblionumber; |
Lines 1050-1056
subtest 'UpdateTotalIssues on Invalid record' => sub {
Link Here
|
1050 |
|
1053 |
|
1051 |
my $success; |
1054 |
my $success; |
1052 |
warnings_like { |
1055 |
warnings_like { |
1053 |
$success = C4::Biblio::UpdateTotalIssues( $biblio->biblionumber, $increase, '' ); |
1056 |
$success = C4::Biblio::UpdateTotalIssues( $biblio->biblionumber, $increase, undef ); |
1054 |
} |
1057 |
} |
1055 |
[ |
1058 |
[ |
1056 |
qr/Invalid data, cannot decode metadata object/, |
1059 |
qr/Invalid data, cannot decode metadata object/, |
Lines 1058-1064
subtest 'UpdateTotalIssues on Invalid record' => sub {
Link Here
|
1058 |
], |
1061 |
], |
1059 |
"Expected warning found"; |
1062 |
"Expected warning found"; |
1060 |
|
1063 |
|
1061 |
ok( !$success, 'UpdateTotalIssues fails gracefully for invalid record' ); |
1064 |
is( $success, -1, 'UpdateTotalIssues fails gracefully for invalid record' ); |
|
|
1065 |
|
1066 |
}; |
1067 |
|
1068 |
subtest 'UpdateTotalIssues tests' => sub { |
1069 |
plan tests => 5; |
1070 |
|
1071 |
my $c4_biblio = Test::MockModule->new('C4::Biblio'); |
1072 |
$c4_biblio->mock( |
1073 |
'GetMarcFromKohaField', |
1074 |
sub { |
1075 |
my $field = shift; |
1076 |
return ( '', '' ) if $field eq 'biblioitems.totalissues'; |
1077 |
return $c4_biblio->original("GetMarcFromKohaField")->($field); |
1078 |
} |
1079 |
); |
1080 |
|
1081 |
my $biblio = $builder->build_sample_biblio; |
1082 |
my $biblionumber = $biblio->biblionumber; |
1083 |
my $biblio_metadata_id = $biblio->metadata->id; |
1084 |
|
1085 |
my $increase = 1; |
1086 |
|
1087 |
my $success = C4::Biblio::UpdateTotalIssues( $biblio->biblionumber, $increase, undef ); |
1088 |
is( $success, 0, 'UpdateTotalIssues does nothing if totalissues tag is not mapped' ); |
1089 |
|
1090 |
$c4_biblio->mock( |
1091 |
'GetMarcFromKohaField', |
1092 |
sub { |
1093 |
my $field = shift; |
1094 |
return ( '555', 'a' ) if $field eq 'biblioitems.totalissues'; |
1095 |
return $c4_biblio->original("GetMarcFromKohaField")->($field); |
1096 |
} |
1097 |
); |
1098 |
|
1099 |
$c4_biblio->mock( |
1100 |
'GetMarcSubfieldStructure', |
1101 |
sub { |
1102 |
my @params = shift; |
1103 |
my $sff = $c4_biblio->original("GetMarcSubfieldStructure")->(@params); |
1104 |
$sff->{'biblioitems.totalissues'} = [ |
1105 |
{ |
1106 |
'tagfield' => '555', |
1107 |
'tagsubfield' => 'a', |
1108 |
'kohafield' => 'biblioitems.totalissues', |
1109 |
} |
1110 |
]; |
1111 |
return $sff; |
1112 |
} |
1113 |
); |
1114 |
|
1115 |
my $biblioitem = $biblio->biblioitem; |
1116 |
$biblioitem->totalissues(1)->store(); |
1117 |
|
1118 |
$success = C4::Biblio::UpdateTotalIssues( $biblio->biblionumber, $increase, undef ); |
1119 |
is( $success, 1, 'UpdateTotalIssues updates when passed an increase and no value' ); |
1120 |
|
1121 |
$biblioitem->discard_changes; |
1122 |
is( $biblioitem->totalissues, 2, "Total issues was increased by 1" ); |
1123 |
|
1124 |
$success = C4::Biblio::UpdateTotalIssues( $biblio->biblionumber, $increase, 5 ); |
1125 |
is( $success, 1, 'UpdateTotalIssues updates when passed a value' ); |
1126 |
|
1127 |
$biblioitem->discard_changes; |
1128 |
is( $biblioitem->totalissues, 5, "Total issues is set to the value when passed" ); |
1062 |
|
1129 |
|
1063 |
}; |
1130 |
}; |
1064 |
|
1131 |
|
1065 |
- |
|
|