|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 8; |
22 |
use Test::More tests => 9; |
| 23 |
|
23 |
|
| 24 |
use C4::Circulation; |
24 |
use C4::Circulation; |
| 25 |
use Koha::Checkouts; |
25 |
use Koha::Checkouts; |
|
Lines 31-60
use t::lib::TestBuilder;
Link Here
|
| 31 |
my $schema = Koha::Database->new->schema; |
31 |
my $schema = Koha::Database->new->schema; |
| 32 |
$schema->storage->txn_begin; |
32 |
$schema->storage->txn_begin; |
| 33 |
|
33 |
|
| 34 |
my $builder = t::lib::TestBuilder->new; |
34 |
my $builder = t::lib::TestBuilder->new; |
| 35 |
my $library = $builder->build( { source => 'Branch' } ); |
35 |
my $library = $builder->build( { source => 'Branch' } ); |
| 36 |
my $patron = $builder->build( { source => 'Borrower', value => { branchcode => $library->{branchcode} } } ); |
36 |
my $patron = $builder->build( |
|
|
37 |
{ source => 'Borrower', value => { branchcode => $library->{branchcode} } } |
| 38 |
); |
| 37 |
my $item_1 = $builder->build_sample_item; |
39 |
my $item_1 = $builder->build_sample_item; |
| 38 |
my $item_2 = $builder->build_sample_item; |
40 |
my $item_2 = $builder->build_sample_item; |
| 39 |
my $nb_of_checkouts = Koha::Checkouts->search->count; |
41 |
my $nb_of_checkouts = Koha::Checkouts->search->count; |
| 40 |
my $new_checkout_1 = Koha::Checkout->new( |
42 |
my $new_checkout_1 = Koha::Checkout->new( |
| 41 |
{ borrowernumber => $patron->{borrowernumber}, |
43 |
{ |
|
|
44 |
borrowernumber => $patron->{borrowernumber}, |
| 42 |
itemnumber => $item_1->itemnumber, |
45 |
itemnumber => $item_1->itemnumber, |
| 43 |
branchcode => $library->{branchcode}, |
46 |
branchcode => $library->{branchcode}, |
| 44 |
} |
47 |
} |
| 45 |
)->store; |
48 |
)->store; |
| 46 |
my $new_checkout_2 = Koha::Checkout->new( |
49 |
my $new_checkout_2 = Koha::Checkout->new( |
| 47 |
{ borrowernumber => $patron->{borrowernumber}, |
50 |
{ |
|
|
51 |
borrowernumber => $patron->{borrowernumber}, |
| 48 |
itemnumber => $item_2->itemnumber, |
52 |
itemnumber => $item_2->itemnumber, |
| 49 |
branchcode => $library->{branchcode}, |
53 |
branchcode => $library->{branchcode}, |
| 50 |
} |
54 |
} |
| 51 |
)->store; |
55 |
)->store; |
| 52 |
|
56 |
|
| 53 |
like( $new_checkout_1->issue_id, qr|^\d+$|, 'Adding a new checkout should have set the issue_id' ); |
57 |
like( $new_checkout_1->issue_id, qr|^\d+$|, |
| 54 |
is( Koha::Checkouts->search->count, $nb_of_checkouts + 2, 'The 2 checkouts should have been added' ); |
58 |
'Adding a new checkout should have set the issue_id' ); |
|
|
59 |
is( |
| 60 |
Koha::Checkouts->search->count, |
| 61 |
$nb_of_checkouts + 2, |
| 62 |
'The 2 checkouts should have been added' |
| 63 |
); |
| 55 |
|
64 |
|
| 56 |
my $retrieved_checkout_1 = Koha::Checkouts->find( $new_checkout_1->issue_id ); |
65 |
my $retrieved_checkout_1 = Koha::Checkouts->find( $new_checkout_1->issue_id ); |
| 57 |
is( $retrieved_checkout_1->itemnumber, $new_checkout_1->itemnumber, 'Find a checkout by id should return the correct checkout' ); |
66 |
is( |
|
|
67 |
$retrieved_checkout_1->itemnumber, |
| 68 |
$new_checkout_1->itemnumber, |
| 69 |
'Find a checkout by id should return the correct checkout' |
| 70 |
); |
| 58 |
|
71 |
|
| 59 |
subtest 'is_overdue' => sub { |
72 |
subtest 'is_overdue' => sub { |
| 60 |
plan tests => 6; |
73 |
plan tests => 6; |
|
Lines 90-106
subtest 'is_overdue' => sub {
Link Here
|
| 90 |
subtest 'item' => sub { |
103 |
subtest 'item' => sub { |
| 91 |
plan tests => 2; |
104 |
plan tests => 2; |
| 92 |
my $item = $retrieved_checkout_1->item; |
105 |
my $item = $retrieved_checkout_1->item; |
| 93 |
is( ref( $item ), 'Koha::Item', 'Koha::Checkout->item should return a Koha::Item' ); |
106 |
is( ref($item), 'Koha::Item', |
| 94 |
is( $item->itemnumber, $item_1->itemnumber, 'Koha::Checkout->item should return the correct item' ); |
107 |
'Koha::Checkout->item should return a Koha::Item' ); |
|
|
108 |
is( $item->itemnumber, $item_1->itemnumber, |
| 109 |
'Koha::Checkout->item should return the correct item' ); |
| 95 |
}; |
110 |
}; |
| 96 |
|
111 |
|
| 97 |
subtest 'patron' => sub { |
112 |
subtest 'patron' => sub { |
| 98 |
plan tests => 3; |
113 |
plan tests => 3; |
| 99 |
my $patron = $builder->build_object({class=>'Koha::Patrons', value => {branchcode => $library->{branchcode}}}); |
114 |
my $patron = $builder->build_object( |
|
|
115 |
{ |
| 116 |
class => 'Koha::Patrons', |
| 117 |
value => { branchcode => $library->{branchcode} } |
| 118 |
} |
| 119 |
); |
| 100 |
|
120 |
|
| 101 |
my $item = $builder->build_sample_item; |
121 |
my $item = $builder->build_sample_item; |
| 102 |
my $checkout = Koha::Checkout->new( |
122 |
my $checkout = Koha::Checkout->new( |
| 103 |
{ borrowernumber => $patron->borrowernumber, |
123 |
{ |
|
|
124 |
borrowernumber => $patron->borrowernumber, |
| 104 |
itemnumber => $item->itemnumber, |
125 |
itemnumber => $item->itemnumber, |
| 105 |
branchcode => $library->{branchcode}, |
126 |
branchcode => $library->{branchcode}, |
| 106 |
} |
127 |
} |
|
Lines 114-142
subtest 'patron' => sub {
Link Here
|
| 114 |
|
135 |
|
| 115 |
# Testing Koha::Old::Checkout->patron now |
136 |
# Testing Koha::Old::Checkout->patron now |
| 116 |
my $issue_id = $checkout->issue_id; |
137 |
my $issue_id = $checkout->issue_id; |
| 117 |
C4::Circulation::MarkIssueReturned( $p->borrowernumber, $checkout->itemnumber ); |
138 |
C4::Circulation::MarkIssueReturned( $p->borrowernumber, |
|
|
139 |
$checkout->itemnumber ); |
| 118 |
$p->delete; |
140 |
$p->delete; |
| 119 |
my $old_issue = Koha::Old::Checkouts->find($issue_id); |
141 |
my $old_issue = Koha::Old::Checkouts->find($issue_id); |
| 120 |
is( $old_issue->patron, undef, |
142 |
is( $old_issue->patron, undef, |
| 121 |
'Koha::Checkout->patron should return undef if the patron record has been deleted' |
143 |
'Koha::Checkout->patron should return undef if the patron record has been deleted' |
| 122 |
); |
144 |
); |
| 123 |
}; |
145 |
}; |
| 124 |
|
146 |
|
| 125 |
$retrieved_checkout_1->delete; |
147 |
$retrieved_checkout_1->delete; |
| 126 |
is( Koha::Checkouts->search->count, $nb_of_checkouts + 1, 'Delete should have deleted the checkout' ); |
148 |
is( |
|
|
149 |
Koha::Checkouts->search->count, |
| 150 |
$nb_of_checkouts + 1, |
| 151 |
'Delete should have deleted the checkout' |
| 152 |
); |
| 127 |
|
153 |
|
| 128 |
subtest 'issuer' => sub { |
154 |
subtest 'issuer' => sub { |
| 129 |
plan tests => 3; |
155 |
plan tests => 3; |
| 130 |
my $patron = $builder->build_object({class=>'Koha::Patrons', value => {branchcode => $library->{branchcode}}}); |
156 |
my $patron = $builder->build_object( |
| 131 |
my $issuer = $builder->build_object({class=>'Koha::Patrons', value => {branchcode => $library->{branchcode}}}); |
157 |
{ |
| 132 |
|
158 |
class => 'Koha::Patrons', |
| 133 |
my $item = $builder->build_sample_item; |
159 |
value => { branchcode => $library->{branchcode} } |
| 134 |
my $checkout = Koha::Checkout->new({ |
160 |
} |
| 135 |
borrowernumber => $patron->borrowernumber, |
161 |
); |
| 136 |
issuer_id => $issuer->borrowernumber, |
162 |
my $issuer = $builder->build_object( |
| 137 |
itemnumber => $item->itemnumber, |
163 |
{ |
| 138 |
branchcode => $library->{branchcode}, |
164 |
class => 'Koha::Patrons', |
| 139 |
})->store; |
165 |
value => { branchcode => $library->{branchcode} } |
|
|
166 |
} |
| 167 |
); |
| 168 |
|
| 169 |
my $item = $builder->build_sample_item; |
| 170 |
my $checkout = Koha::Checkout->new( |
| 171 |
{ |
| 172 |
borrowernumber => $patron->borrowernumber, |
| 173 |
issuer_id => $issuer->borrowernumber, |
| 174 |
itemnumber => $item->itemnumber, |
| 175 |
branchcode => $library->{branchcode}, |
| 176 |
} |
| 177 |
)->store; |
| 140 |
|
178 |
|
| 141 |
my $i = $checkout->issuer; |
179 |
my $i = $checkout->issuer; |
| 142 |
is( ref($i), 'Koha::Patron', |
180 |
is( ref($i), 'Koha::Patron', |
|
Lines 146-159
subtest 'issuer' => sub {
Link Here
|
| 146 |
|
184 |
|
| 147 |
# Testing Koha::Old::Checkout->patron now |
185 |
# Testing Koha::Old::Checkout->patron now |
| 148 |
my $issue_id = $checkout->issue_id; |
186 |
my $issue_id = $checkout->issue_id; |
| 149 |
C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $checkout->itemnumber ); |
187 |
C4::Circulation::MarkIssueReturned( $patron->borrowernumber, |
|
|
188 |
$checkout->itemnumber ); |
| 150 |
$i->delete; |
189 |
$i->delete; |
| 151 |
my $old_issue = Koha::Old::Checkouts->find($issue_id); |
190 |
my $old_issue = Koha::Old::Checkouts->find($issue_id); |
| 152 |
is( $old_issue->issuer_id, undef, |
191 |
is( $old_issue->issuer_id, undef, |
| 153 |
'Koha::Checkout->issuer_id should return undef if the patron record has been deleted' |
192 |
'Koha::Checkout->issuer_id should return undef if the patron record has been deleted' |
| 154 |
); |
193 |
); |
| 155 |
|
194 |
|
| 156 |
}; |
195 |
}; |
| 157 |
|
196 |
|
| 158 |
$schema->storage->txn_rollback; |
197 |
$schema->storage->txn_rollback; |
| 159 |
|
198 |
|
| 160 |
- |
199 |
subtest 'automatic_checkin' => sub { |
|
|
200 |
plan tests => 6; |
| 201 |
|
| 202 |
$schema->storage->txn_begin; |
| 203 |
|
| 204 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 205 |
|
| 206 |
my $due_ac_item = |
| 207 |
$builder->build_sample_item( { homebranch => $patron->branchcode } ); |
| 208 |
my $ac_item = |
| 209 |
$builder->build_sample_item( { homebranch => $patron->branchcode } ); |
| 210 |
my $normal_item = |
| 211 |
$builder->build_sample_item( { homebranch => $patron->branchcode } ); |
| 212 |
|
| 213 |
$due_ac_item->itemtype->automatic_checkin(1)->store; |
| 214 |
$ac_item->itemtype->automatic_checkin(1)->store; |
| 215 |
$normal_item->itemtype->automatic_checkin(0)->store; |
| 216 |
|
| 217 |
my $current_date = dt_from_string; |
| 218 |
|
| 219 |
# due checkout for automatic checkin |
| 220 |
my $checkout_due_aci = Koha::Checkout->new( |
| 221 |
{ |
| 222 |
borrowernumber => $patron->borrowernumber, |
| 223 |
itemnumber => $due_ac_item->itemnumber, |
| 224 |
branchcode => $patron->branchcode, |
| 225 |
date_due => $current_date, |
| 226 |
} |
| 227 |
)->store; |
| 228 |
|
| 229 |
# in time checkout for automatic checkin |
| 230 |
my $checkout_aci = Koha::Checkout->new( |
| 231 |
{ |
| 232 |
borrowernumber => $patron->borrowernumber, |
| 233 |
itemnumber => $ac_item->itemnumber, |
| 234 |
branchcode => $patron->branchcode, |
| 235 |
} |
| 236 |
)->store; |
| 237 |
|
| 238 |
# due checkout for nomal itemtype |
| 239 |
my $checkout_ni = Koha::Checkout->new( |
| 240 |
{ |
| 241 |
borrowernumber => $patron->borrowernumber, |
| 242 |
itemnumber => $normal_item->itemnumber, |
| 243 |
branchcode => $patron->branchcode, |
| 244 |
date_due => $current_date, |
| 245 |
} |
| 246 |
)->store; |
| 247 |
|
| 248 |
my $searched = Koha::Checkouts->find( $checkout_ni->issue_id ); |
| 249 |
is( $searched->issue_id, $checkout_ni->issue_id, |
| 250 |
'checkout for normal_item exists' ); |
| 251 |
|
| 252 |
$searched = Koha::Checkouts->find( $checkout_aci->issue_id ); |
| 253 |
is( $searched->issue_id, $checkout_aci->issue_id, |
| 254 |
'checkout for ac_item exists' ); |
| 255 |
|
| 256 |
$searched = Koha::Checkouts->find( $checkout_due_aci->issue_id ); |
| 257 |
is( |
| 258 |
$searched->issue_id, |
| 259 |
$checkout_due_aci->issue_id, |
| 260 |
'checkout for due_ac_item exists' |
| 261 |
); |
| 262 |
|
| 263 |
Koha::Checkouts->automatic_checkin; |
| 264 |
|
| 265 |
$searched = Koha::Checkouts->find( $checkout_ni->issue_id ); |
| 266 |
is( $searched->issue_id, $checkout_ni->issue_id, |
| 267 |
'checkout for normal_item still exists' ); |
| 268 |
|
| 269 |
$searched = Koha::Checkouts->find( $checkout_aci->issue_id ); |
| 270 |
is( $searched->issue_id, $checkout_aci->issue_id, |
| 271 |
'checkout for ac_item still exists' ); |
| 272 |
|
| 273 |
$searched = Koha::Checkouts->find( $checkout_due_aci->issue_id ); |
| 274 |
is( $searched, undef, 'checkout for due_ac_item doesn\'t exist anymore' ); |
| 275 |
|
| 276 |
$schema->storage->txn_rollback; |
| 277 |
} |