Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 2; |
20 |
use Test::More tests => 4; |
21 |
use t::lib::TestBuilder; |
21 |
use t::lib::TestBuilder; |
22 |
use t::lib::Mocks; |
22 |
use t::lib::Mocks; |
23 |
|
23 |
|
Lines 47-54
subtest 'transfer a non-existant item' => sub {
Link Here
|
47 |
); |
47 |
); |
48 |
}; |
48 |
}; |
49 |
|
49 |
|
|
|
50 |
#subtest 'UseBranchTransferLimits tests' => sub { |
51 |
# plan tests => 0; |
52 |
#}; |
53 |
|
54 |
subtest 'transfer already at destination' => sub { |
55 |
plan tests => 5; |
56 |
|
57 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } )->store; |
58 |
t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode } ); |
59 |
|
60 |
my $patron = $builder->build_object( |
61 |
{ |
62 |
class => 'Koha::Patrons', |
63 |
value => { branchcode => $library->branchcode } |
64 |
} |
65 |
); |
66 |
|
67 |
my $item = $builder->build_sample_item( |
68 |
{ |
69 |
library => $library->branchcode, |
70 |
} |
71 |
); |
72 |
|
73 |
my ($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode ); |
74 |
is( $dotransfer, 0, 'Transfer of reserved item failed with ignore reserves: true' ); |
75 |
is_deeply( |
76 |
$messages, |
77 |
{ 'DestinationEqualsHolding' => 1 }, |
78 |
"We got the expected failure message: DestinationEqualsHolding" |
79 |
); |
80 |
|
81 |
# We are making sure there is no regression, feel free to change the behavior if needed. |
82 |
# * Contrary to the POD, if ignore_reserves is not passed (or is false), any item reserve |
83 |
# found will override all other measures that may prevent transfer and force a transfer. |
84 |
AddReserve({ |
85 |
branchcode => $item->homebranch, |
86 |
borrowernumber => $patron->borrowernumber, |
87 |
biblionumber => $item->biblionumber, |
88 |
itemnumber => $item->itemnumber, |
89 |
}); |
90 |
|
91 |
($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode ); |
92 |
is( $dotransfer, 1, 'Transfer of reserved item succeeded without ignore reserves' ); |
93 |
is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve"); |
94 |
is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info"); |
95 |
}; |
96 |
|
50 |
subtest 'transfer an issued item' => sub { |
97 |
subtest 'transfer an issued item' => sub { |
51 |
plan tests => 3; |
98 |
plan tests => 5; |
52 |
|
99 |
|
53 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } )->store; |
100 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } )->store; |
54 |
t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode } ); |
101 |
t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode } ); |
Lines 75-89
subtest 'transfer an issued item' => sub {
Link Here
|
75 |
my ($dotransfer, $messages) = transferbook( $library->branchcode, $item->barcode ); |
122 |
my ($dotransfer, $messages) = transferbook( $library->branchcode, $item->barcode ); |
76 |
is( $messages->{WasReturned}, $patron->borrowernumber, 'transferbook should have return a WasReturned flag is the item was issued before the transferbook call'); |
123 |
is( $messages->{WasReturned}, $patron->borrowernumber, 'transferbook should have return a WasReturned flag is the item was issued before the transferbook call'); |
77 |
|
124 |
|
|
|
125 |
# Reset issue |
126 |
$issue = AddIssue( $patron->unblessed, $item->barcode, $dt_to ); |
127 |
|
128 |
# We are making sure there is no regression, feel free to change the behavior if needed. |
129 |
# * Contrary to the POD, if ignore_reserves is not passed (or is false), any item reserve |
130 |
# found will override all other measures that may prevent transfer and force a transfer. |
78 |
AddReserve({ |
131 |
AddReserve({ |
79 |
branchcode => $item->homebranch, |
132 |
branchcode => $item->homebranch, |
80 |
borrowernumber => $patron->borrowernumber, |
133 |
borrowernumber => $patron->borrowernumber, |
81 |
biblionumber => $item->biblionumber, |
134 |
biblionumber => $item->biblionumber, |
82 |
itemnumber => $item->itemnumber, |
135 |
itemnumber => $item->itemnumber, |
83 |
}); |
136 |
}); |
|
|
137 |
|
84 |
($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode ); |
138 |
($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode ); |
|
|
139 |
is( $dotransfer, 1, 'Transfer of reserved item succeeded without ignore reserves' ); |
140 |
is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve"); |
141 |
is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info"); |
142 |
is( $messages->{WasReturned}, $patron->borrowernumber, "We got the return info"); |
143 |
}; |
144 |
|
145 |
subtest 'ignore_reserves flag' => sub { |
146 |
plan tests => 10; |
147 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } )->store; |
148 |
t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode } ); |
149 |
|
150 |
my $patron = $builder->build_object( |
151 |
{ |
152 |
class => 'Koha::Patrons', |
153 |
value => { branchcode => $library->branchcode } |
154 |
} |
155 |
); |
156 |
|
157 |
my $item = $builder->build_sample_item( |
158 |
{ |
159 |
library => $library->branchcode, |
160 |
} |
161 |
); |
162 |
|
163 |
AddReserve({ |
164 |
branchcode => $item->homebranch, |
165 |
borrowernumber => $patron->borrowernumber, |
166 |
biblionumber => $item->biblionumber, |
167 |
itemnumber => $item->itemnumber, |
168 |
}); |
169 |
|
170 |
# We are making sure there is no regression, feel free to change the behavior if needed. |
171 |
# * Contrary to the POD, if ignore_reserves is not passed (or is false), any item reserve |
172 |
# found will override all other measures that may prevent transfer and force a transfer. |
173 |
my ($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode ); |
174 |
is( $dotransfer, 1, 'Transfer of reserved item succeeded without ignore reserves' ); |
85 |
is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve"); |
175 |
is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve"); |
86 |
is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info"); |
176 |
is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info"); |
|
|
177 |
|
178 |
my $ignore_reserves = 0; |
179 |
($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode, $ignore_reserves ); |
180 |
is( $dotransfer, 1, 'Transfer of reserved item succeeded with ignore reserves: false' ); |
181 |
is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve"); |
182 |
is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info"); |
183 |
|
184 |
$ignore_reserves = 1; |
185 |
($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode, $ignore_reserves ); |
186 |
is( $dotransfer, 0, 'Transfer of reserved item failed with ignore reserves: true' ); |
187 |
is_deeply( |
188 |
$messages, |
189 |
{ 'DestinationEqualsHolding' => 1 }, |
190 |
"We got the expected failure message: DestinationEqualsHolding" |
191 |
); |
192 |
isnt( $messages->{ResFound}->{ResFound}, 'Reserved', "We did not return that we found a reserve"); |
193 |
isnt( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We did not return the reserve info"); |
87 |
}; |
194 |
}; |
88 |
|
195 |
|
89 |
|
196 |
|
90 |
- |
|
|