|
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 1046-1061
subtest 'UpdateTotalIssues on Invalid record' => sub {
Link Here
|
| 1046 |
plan tests => 2; |
1046 |
plan tests => 2; |
| 1047 |
|
1047 |
|
| 1048 |
my $return_record = Test::MockModule->new('Koha::Biblio::Metadata'); |
1048 |
my $return_record = Test::MockModule->new('Koha::Biblio::Metadata'); |
| 1049 |
$return_record->mock( 'record', sub { |
1049 |
$return_record->mock( |
| 1050 |
my $self = shift; |
1050 |
'record', |
| 1051 |
Koha::Exceptions::Metadata::Invalid->throw( |
1051 |
sub { |
| 1052 |
id => $self->id, |
1052 |
my $self = shift; |
| 1053 |
biblionumber => $self->biblionumber, |
1053 |
Koha::Exceptions::Metadata::Invalid->throw( |
| 1054 |
format => $self->format, |
1054 |
id => $self->id, |
| 1055 |
schema => $self->schema, |
1055 |
biblionumber => $self->biblionumber, |
| 1056 |
decoding_error => "Error goes here", |
1056 |
format => $self->format, |
| 1057 |
); |
1057 |
schema => $self->schema, |
| 1058 |
} ); |
1058 |
decoding_error => "Error goes here", |
|
|
1059 |
); |
| 1060 |
} |
| 1061 |
); |
| 1059 |
|
1062 |
|
| 1060 |
my $biblio = $builder->build_sample_biblio; |
1063 |
my $biblio = $builder->build_sample_biblio; |
| 1061 |
my $biblionumber = $biblio->biblionumber; |
1064 |
my $biblionumber = $biblio->biblionumber; |
|
Lines 1065-1071
subtest 'UpdateTotalIssues on Invalid record' => sub {
Link Here
|
| 1065 |
|
1068 |
|
| 1066 |
my $success; |
1069 |
my $success; |
| 1067 |
warnings_like { |
1070 |
warnings_like { |
| 1068 |
$success = C4::Biblio::UpdateTotalIssues( $biblio->biblionumber, $increase, '' ); |
1071 |
$success = C4::Biblio::UpdateTotalIssues( $biblio->biblionumber, $increase, undef ); |
| 1069 |
} |
1072 |
} |
| 1070 |
[ |
1073 |
[ |
| 1071 |
qr/Invalid data, cannot decode metadata object/, |
1074 |
qr/Invalid data, cannot decode metadata object/, |
|
Lines 1073-1079
subtest 'UpdateTotalIssues on Invalid record' => sub {
Link Here
|
| 1073 |
], |
1076 |
], |
| 1074 |
"Expected warning found"; |
1077 |
"Expected warning found"; |
| 1075 |
|
1078 |
|
| 1076 |
ok( !$success, 'UpdateTotalIssues fails gracefully for invalid record' ); |
1079 |
is( $success, -1, 'UpdateTotalIssues fails gracefully for invalid record' ); |
|
|
1080 |
|
| 1081 |
}; |
| 1082 |
|
| 1083 |
subtest 'UpdateTotalIssues tests' => sub { |
| 1084 |
plan tests => 5; |
| 1085 |
|
| 1086 |
my $c4_biblio = Test::MockModule->new('C4::Biblio'); |
| 1087 |
$c4_biblio->mock( |
| 1088 |
'GetMarcFromKohaField', |
| 1089 |
sub { |
| 1090 |
my $field = shift; |
| 1091 |
return ( '', '' ) if $field eq 'biblioitems.totalissues'; |
| 1092 |
return $c4_biblio->original("GetMarcFromKohaField")->($field); |
| 1093 |
} |
| 1094 |
); |
| 1095 |
|
| 1096 |
my $biblio = $builder->build_sample_biblio; |
| 1097 |
my $biblionumber = $biblio->biblionumber; |
| 1098 |
my $biblio_metadata_id = $biblio->metadata->id; |
| 1099 |
|
| 1100 |
my $increase = 1; |
| 1101 |
|
| 1102 |
my $success = C4::Biblio::UpdateTotalIssues( $biblio->biblionumber, $increase, undef ); |
| 1103 |
is( $success, 0, 'UpdateTotalIssues does nothing if totalissues tag is not mapped' ); |
| 1104 |
|
| 1105 |
$c4_biblio->mock( |
| 1106 |
'GetMarcFromKohaField', |
| 1107 |
sub { |
| 1108 |
my $field = shift; |
| 1109 |
return ( '555', 'a' ) if $field eq 'biblioitems.totalissues'; |
| 1110 |
return $c4_biblio->original("GetMarcFromKohaField")->($field); |
| 1111 |
} |
| 1112 |
); |
| 1113 |
|
| 1114 |
$c4_biblio->mock( |
| 1115 |
'GetMarcSubfieldStructure', |
| 1116 |
sub { |
| 1117 |
my @params = shift; |
| 1118 |
my $sff = $c4_biblio->original("GetMarcSubfieldStructure")->(@params); |
| 1119 |
$sff->{'biblioitems.totalissues'} = [ |
| 1120 |
{ |
| 1121 |
'tagfield' => '555', |
| 1122 |
'tagsubfield' => 'a', |
| 1123 |
'kohafield' => 'biblioitems.totalissues', |
| 1124 |
} |
| 1125 |
]; |
| 1126 |
return $sff; |
| 1127 |
} |
| 1128 |
); |
| 1129 |
|
| 1130 |
my $biblioitem = $biblio->biblioitem; |
| 1131 |
$biblioitem->totalissues(1)->store(); |
| 1132 |
|
| 1133 |
$success = C4::Biblio::UpdateTotalIssues( $biblio->biblionumber, $increase, undef ); |
| 1134 |
is( $success, 1, 'UpdateTotalIssues updates when passed an increase and no value' ); |
| 1135 |
|
| 1136 |
$biblioitem->discard_changes; |
| 1137 |
is( $biblioitem->totalissues, 2, "Total issues was increased by 1" ); |
| 1138 |
|
| 1139 |
$success = C4::Biblio::UpdateTotalIssues( $biblio->biblionumber, $increase, 5 ); |
| 1140 |
is( $success, 1, 'UpdateTotalIssues updates when passed a value' ); |
| 1141 |
|
| 1142 |
$biblioitem->discard_changes; |
| 1143 |
is( $biblioitem->totalissues, 5, "Total issues is set to the value when passed" ); |
| 1077 |
|
1144 |
|
| 1078 |
}; |
1145 |
}; |
| 1079 |
|
1146 |
|
| 1080 |
- |
|
|