|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 9; |
22 |
use Test::More tests => 10; |
| 23 |
|
23 |
|
| 24 |
use C4::Circulation; |
24 |
use C4::Circulation; |
| 25 |
use Koha::Checkouts; |
25 |
use Koha::Checkouts; |
|
Lines 32-61
use t::lib::Mocks;
Link Here
|
| 32 |
my $schema = Koha::Database->new->schema; |
32 |
my $schema = Koha::Database->new->schema; |
| 33 |
$schema->storage->txn_begin; |
33 |
$schema->storage->txn_begin; |
| 34 |
|
34 |
|
| 35 |
my $builder = t::lib::TestBuilder->new; |
35 |
my $builder = t::lib::TestBuilder->new; |
| 36 |
my $library = $builder->build( { source => 'Branch' } ); |
36 |
my $library = $builder->build( { source => 'Branch' } ); |
| 37 |
my $patron = $builder->build( { source => 'Borrower', value => { branchcode => $library->{branchcode} } } ); |
37 |
my $patron = $builder->build( |
|
|
38 |
{ source => 'Borrower', value => { branchcode => $library->{branchcode} } } |
| 39 |
); |
| 38 |
my $item_1 = $builder->build_sample_item; |
40 |
my $item_1 = $builder->build_sample_item; |
| 39 |
my $item_2 = $builder->build_sample_item; |
41 |
my $item_2 = $builder->build_sample_item; |
| 40 |
my $nb_of_checkouts = Koha::Checkouts->search->count; |
42 |
my $nb_of_checkouts = Koha::Checkouts->search->count; |
| 41 |
my $new_checkout_1 = Koha::Checkout->new( |
43 |
my $new_checkout_1 = Koha::Checkout->new( |
| 42 |
{ borrowernumber => $patron->{borrowernumber}, |
44 |
{ |
|
|
45 |
borrowernumber => $patron->{borrowernumber}, |
| 43 |
itemnumber => $item_1->itemnumber, |
46 |
itemnumber => $item_1->itemnumber, |
| 44 |
branchcode => $library->{branchcode}, |
47 |
branchcode => $library->{branchcode}, |
| 45 |
} |
48 |
} |
| 46 |
)->store; |
49 |
)->store; |
| 47 |
my $new_checkout_2 = Koha::Checkout->new( |
50 |
my $new_checkout_2 = Koha::Checkout->new( |
| 48 |
{ borrowernumber => $patron->{borrowernumber}, |
51 |
{ |
|
|
52 |
borrowernumber => $patron->{borrowernumber}, |
| 49 |
itemnumber => $item_2->itemnumber, |
53 |
itemnumber => $item_2->itemnumber, |
| 50 |
branchcode => $library->{branchcode}, |
54 |
branchcode => $library->{branchcode}, |
| 51 |
} |
55 |
} |
| 52 |
)->store; |
56 |
)->store; |
| 53 |
|
57 |
|
| 54 |
like( $new_checkout_1->issue_id, qr|^\d+$|, 'Adding a new checkout should have set the issue_id' ); |
58 |
like( $new_checkout_1->issue_id, qr|^\d+$|, |
| 55 |
is( Koha::Checkouts->search->count, $nb_of_checkouts + 2, 'The 2 checkouts should have been added' ); |
59 |
'Adding a new checkout should have set the issue_id' ); |
|
|
60 |
is( |
| 61 |
Koha::Checkouts->search->count, |
| 62 |
$nb_of_checkouts + 2, |
| 63 |
'The 2 checkouts should have been added' |
| 64 |
); |
| 56 |
|
65 |
|
| 57 |
my $retrieved_checkout_1 = Koha::Checkouts->find( $new_checkout_1->issue_id ); |
66 |
my $retrieved_checkout_1 = Koha::Checkouts->find( $new_checkout_1->issue_id ); |
| 58 |
is( $retrieved_checkout_1->itemnumber, $new_checkout_1->itemnumber, 'Find a checkout by id should return the correct checkout' ); |
67 |
is( |
|
|
68 |
$retrieved_checkout_1->itemnumber, |
| 69 |
$new_checkout_1->itemnumber, |
| 70 |
'Find a checkout by id should return the correct checkout' |
| 71 |
); |
| 59 |
|
72 |
|
| 60 |
subtest 'is_overdue' => sub { |
73 |
subtest 'is_overdue' => sub { |
| 61 |
plan tests => 6; |
74 |
plan tests => 6; |
|
Lines 91-107
subtest 'is_overdue' => sub {
Link Here
|
| 91 |
subtest 'item' => sub { |
104 |
subtest 'item' => sub { |
| 92 |
plan tests => 2; |
105 |
plan tests => 2; |
| 93 |
my $item = $retrieved_checkout_1->item; |
106 |
my $item = $retrieved_checkout_1->item; |
| 94 |
is( ref( $item ), 'Koha::Item', 'Koha::Checkout->item should return a Koha::Item' ); |
107 |
is( ref($item), 'Koha::Item', |
| 95 |
is( $item->itemnumber, $item_1->itemnumber, 'Koha::Checkout->item should return the correct item' ); |
108 |
'Koha::Checkout->item should return a Koha::Item' ); |
|
|
109 |
is( $item->itemnumber, $item_1->itemnumber, |
| 110 |
'Koha::Checkout->item should return the correct item' ); |
| 96 |
}; |
111 |
}; |
| 97 |
|
112 |
|
| 98 |
subtest 'patron' => sub { |
113 |
subtest 'patron' => sub { |
| 99 |
plan tests => 3; |
114 |
plan tests => 3; |
| 100 |
my $patron = $builder->build_object({class=>'Koha::Patrons', value => {branchcode => $library->{branchcode}}}); |
115 |
my $patron = $builder->build_object( |
|
|
116 |
{ |
| 117 |
class => 'Koha::Patrons', |
| 118 |
value => { branchcode => $library->{branchcode} } |
| 119 |
} |
| 120 |
); |
| 101 |
|
121 |
|
| 102 |
my $item = $builder->build_sample_item; |
122 |
my $item = $builder->build_sample_item; |
| 103 |
my $checkout = Koha::Checkout->new( |
123 |
my $checkout = Koha::Checkout->new( |
| 104 |
{ borrowernumber => $patron->borrowernumber, |
124 |
{ |
|
|
125 |
borrowernumber => $patron->borrowernumber, |
| 105 |
itemnumber => $item->itemnumber, |
126 |
itemnumber => $item->itemnumber, |
| 106 |
branchcode => $library->{branchcode}, |
127 |
branchcode => $library->{branchcode}, |
| 107 |
} |
128 |
} |
|
Lines 115-143
subtest 'patron' => sub {
Link Here
|
| 115 |
|
136 |
|
| 116 |
# Testing Koha::Old::Checkout->patron now |
137 |
# Testing Koha::Old::Checkout->patron now |
| 117 |
my $issue_id = $checkout->issue_id; |
138 |
my $issue_id = $checkout->issue_id; |
| 118 |
C4::Circulation::MarkIssueReturned( $p->borrowernumber, $checkout->itemnumber ); |
139 |
C4::Circulation::MarkIssueReturned( $p->borrowernumber, |
|
|
140 |
$checkout->itemnumber ); |
| 119 |
$p->delete; |
141 |
$p->delete; |
| 120 |
my $old_issue = Koha::Old::Checkouts->find($issue_id); |
142 |
my $old_issue = Koha::Old::Checkouts->find($issue_id); |
| 121 |
is( $old_issue->patron, undef, |
143 |
is( $old_issue->patron, undef, |
| 122 |
'Koha::Checkout->patron should return undef if the patron record has been deleted' |
144 |
'Koha::Checkout->patron should return undef if the patron record has been deleted' |
| 123 |
); |
145 |
); |
| 124 |
}; |
146 |
}; |
| 125 |
|
147 |
|
| 126 |
$retrieved_checkout_1->delete; |
148 |
$retrieved_checkout_1->delete; |
| 127 |
is( Koha::Checkouts->search->count, $nb_of_checkouts + 1, 'Delete should have deleted the checkout' ); |
149 |
is( |
|
|
150 |
Koha::Checkouts->search->count, |
| 151 |
$nb_of_checkouts + 1, |
| 152 |
'Delete should have deleted the checkout' |
| 153 |
); |
| 128 |
|
154 |
|
| 129 |
subtest 'issuer' => sub { |
155 |
subtest 'issuer' => sub { |
| 130 |
plan tests => 3; |
156 |
plan tests => 3; |
| 131 |
my $patron = $builder->build_object({class=>'Koha::Patrons', value => {branchcode => $library->{branchcode}}}); |
157 |
my $patron = $builder->build_object( |
| 132 |
my $issuer = $builder->build_object({class=>'Koha::Patrons', value => {branchcode => $library->{branchcode}}}); |
158 |
{ |
| 133 |
|
159 |
class => 'Koha::Patrons', |
| 134 |
my $item = $builder->build_sample_item; |
160 |
value => { branchcode => $library->{branchcode} } |
| 135 |
my $checkout = Koha::Checkout->new({ |
161 |
} |
| 136 |
borrowernumber => $patron->borrowernumber, |
162 |
); |
| 137 |
issuer_id => $issuer->borrowernumber, |
163 |
my $issuer = $builder->build_object( |
| 138 |
itemnumber => $item->itemnumber, |
164 |
{ |
| 139 |
branchcode => $library->{branchcode}, |
165 |
class => 'Koha::Patrons', |
| 140 |
})->store; |
166 |
value => { branchcode => $library->{branchcode} } |
|
|
167 |
} |
| 168 |
); |
| 169 |
|
| 170 |
my $item = $builder->build_sample_item; |
| 171 |
my $checkout = Koha::Checkout->new( |
| 172 |
{ |
| 173 |
borrowernumber => $patron->borrowernumber, |
| 174 |
issuer_id => $issuer->borrowernumber, |
| 175 |
itemnumber => $item->itemnumber, |
| 176 |
branchcode => $library->{branchcode}, |
| 177 |
} |
| 178 |
)->store; |
| 141 |
|
179 |
|
| 142 |
my $i = $checkout->issuer; |
180 |
my $i = $checkout->issuer; |
| 143 |
is( ref($i), 'Koha::Patron', |
181 |
is( ref($i), 'Koha::Patron', |
|
Lines 147-157
subtest 'issuer' => sub {
Link Here
|
| 147 |
|
185 |
|
| 148 |
# Testing Koha::Old::Checkout->patron now |
186 |
# Testing Koha::Old::Checkout->patron now |
| 149 |
my $issue_id = $checkout->issue_id; |
187 |
my $issue_id = $checkout->issue_id; |
| 150 |
C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $checkout->itemnumber ); |
188 |
C4::Circulation::MarkIssueReturned( $patron->borrowernumber, |
|
|
189 |
$checkout->itemnumber ); |
| 151 |
$i->delete; |
190 |
$i->delete; |
| 152 |
my $old_issue = Koha::Old::Checkouts->find($issue_id); |
191 |
my $old_issue = Koha::Old::Checkouts->find($issue_id); |
| 153 |
is( $old_issue->issuer_id, undef, |
192 |
is( $old_issue->issuer_id, undef, |
| 154 |
'Koha::Checkout->issuer_id should return undef if the patron record has been deleted' |
193 |
'Koha::Checkout->issuer_id should return undef if the patron record has been deleted' |
| 155 |
); |
194 |
); |
| 156 |
|
195 |
|
| 157 |
}; |
196 |
}; |
|
Lines 222-224
subtest 'Koha::Old::Checkouts->filter_by_todays_checkins' => sub {
Link Here
|
| 222 |
|
261 |
|
| 223 |
$schema->storage->txn_rollback; |
262 |
$schema->storage->txn_rollback; |
| 224 |
|
263 |
|
| 225 |
- |
264 |
subtest 'automatic_checkin' => sub { |
|
|
265 |
plan tests => 6; |
| 266 |
|
| 267 |
$schema->storage->txn_begin; |
| 268 |
|
| 269 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 270 |
|
| 271 |
my $due_ac_item = |
| 272 |
$builder->build_sample_item( { homebranch => $patron->branchcode } ); |
| 273 |
my $ac_item = |
| 274 |
$builder->build_sample_item( { homebranch => $patron->branchcode } ); |
| 275 |
my $normal_item = |
| 276 |
$builder->build_sample_item( { homebranch => $patron->branchcode } ); |
| 277 |
|
| 278 |
$due_ac_item->itemtype->automatic_checkin(1)->store; |
| 279 |
$ac_item->itemtype->automatic_checkin(1)->store; |
| 280 |
$normal_item->itemtype->automatic_checkin(0)->store; |
| 281 |
|
| 282 |
my $current_date = dt_from_string; |
| 283 |
|
| 284 |
# due checkout for automatic checkin |
| 285 |
my $checkout_due_aci = Koha::Checkout->new( |
| 286 |
{ |
| 287 |
borrowernumber => $patron->borrowernumber, |
| 288 |
itemnumber => $due_ac_item->itemnumber, |
| 289 |
branchcode => $patron->branchcode, |
| 290 |
date_due => $current_date, |
| 291 |
} |
| 292 |
)->store; |
| 293 |
|
| 294 |
# in time checkout for automatic checkin |
| 295 |
my $checkout_aci = Koha::Checkout->new( |
| 296 |
{ |
| 297 |
borrowernumber => $patron->borrowernumber, |
| 298 |
itemnumber => $ac_item->itemnumber, |
| 299 |
branchcode => $patron->branchcode, |
| 300 |
} |
| 301 |
)->store; |
| 302 |
|
| 303 |
# due checkout for nomal itemtype |
| 304 |
my $checkout_ni = Koha::Checkout->new( |
| 305 |
{ |
| 306 |
borrowernumber => $patron->borrowernumber, |
| 307 |
itemnumber => $normal_item->itemnumber, |
| 308 |
branchcode => $patron->branchcode, |
| 309 |
date_due => $current_date, |
| 310 |
} |
| 311 |
)->store; |
| 312 |
|
| 313 |
my $searched = Koha::Checkouts->find( $checkout_ni->issue_id ); |
| 314 |
is( $searched->issue_id, $checkout_ni->issue_id, |
| 315 |
'checkout for normal_item exists' ); |
| 316 |
|
| 317 |
$searched = Koha::Checkouts->find( $checkout_aci->issue_id ); |
| 318 |
is( $searched->issue_id, $checkout_aci->issue_id, |
| 319 |
'checkout for ac_item exists' ); |
| 320 |
|
| 321 |
$searched = Koha::Checkouts->find( $checkout_due_aci->issue_id ); |
| 322 |
is( |
| 323 |
$searched->issue_id, |
| 324 |
$checkout_due_aci->issue_id, |
| 325 |
'checkout for due_ac_item exists' |
| 326 |
); |
| 327 |
|
| 328 |
Koha::Checkouts->automatic_checkin; |
| 329 |
|
| 330 |
$searched = Koha::Checkouts->find( $checkout_ni->issue_id ); |
| 331 |
is( $searched->issue_id, $checkout_ni->issue_id, |
| 332 |
'checkout for normal_item still exists' ); |
| 333 |
|
| 334 |
$searched = Koha::Checkouts->find( $checkout_aci->issue_id ); |
| 335 |
is( $searched->issue_id, $checkout_aci->issue_id, |
| 336 |
'checkout for ac_item still exists' ); |
| 337 |
|
| 338 |
$searched = Koha::Checkouts->find( $checkout_due_aci->issue_id ); |
| 339 |
is( $searched, undef, 'checkout for due_ac_item doesn\'t exist anymore' ); |
| 340 |
|
| 341 |
$schema->storage->txn_rollback; |
| 342 |
} |