|
Lines 1209-1254
subtest "reduce() tests" => sub {
Link Here
|
| 1209 |
}; |
1209 |
}; |
| 1210 |
|
1210 |
|
| 1211 |
subtest 'checkout' => sub { |
1211 |
subtest 'checkout' => sub { |
| 1212 |
plan tests => 1; |
1212 |
plan tests => 5; |
| 1213 |
|
1213 |
|
| 1214 |
$schema->storage->txn_begin; |
1214 |
$schema->storage->txn_begin; |
| 1215 |
|
1215 |
|
| 1216 |
my $library = $builder->build( { source => 'Branch' } ); |
1216 |
my $library = $builder->build_object({ class => 'Koha::Libraries' } ); |
| 1217 |
my $biblioitem = $builder->build( { source => 'Biblioitem' } ); |
1217 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' } ); |
| 1218 |
my $patron = $builder->build( { source => 'Borrower' } ); |
1218 |
my $item_1 = $builder->build_sample_item({ library => $library->branchcode }); |
| 1219 |
my $item = Koha::Item->new( |
|
|
| 1220 |
{ |
| 1221 |
biblionumber => $biblioitem->{biblionumber}, |
| 1222 |
biblioitemnumber => $biblioitem->{biblioitemnumber}, |
| 1223 |
homebranch => $library->{branchcode}, |
| 1224 |
holdingbranch => $library->{branchcode}, |
| 1225 |
barcode => 'some_barcode_13', |
| 1226 |
itype => 'BK', |
| 1227 |
} |
| 1228 |
)->store; |
| 1229 |
|
1219 |
|
| 1230 |
my $checkout = Koha::Checkout->new( |
1220 |
my $checkout = Koha::Checkout->new( |
| 1231 |
{ |
1221 |
{ |
| 1232 |
borrowernumber => $patron->{borrowernumber}, |
1222 |
borrowernumber => $patron->borrowernumber, |
| 1233 |
itemnumber => $item->itemnumber, |
1223 |
itemnumber => $item_1->itemnumber, |
| 1234 |
branchcode => $library->{branchcode}, |
1224 |
branchcode => $library->branchcode, |
| 1235 |
} |
1225 |
} |
| 1236 |
)->store; |
1226 |
)->store; |
| 1237 |
|
1227 |
|
| 1238 |
my $line = Koha::Account::Line->new( |
1228 |
my $line = $builder->build_object( |
| 1239 |
{ |
1229 |
{ |
| 1240 |
borrowernumber => $patron->{borrowernumber}, |
1230 |
class => 'Koha::Account::Lines', |
| 1241 |
itemnumber => $item->itemnumber, |
1231 |
value => { |
| 1242 |
issue_id => $checkout->id, |
1232 |
borrowernumber => $patron->borrowernumber, |
| 1243 |
accounttype => "F", |
1233 |
itemnumber => $item_1->itemnumber, |
| 1244 |
amount => 10, |
1234 |
issue_id => $checkout->id, |
| 1245 |
interface => 'commandline', |
1235 |
} |
| 1246 |
} |
1236 |
} |
| 1247 |
)->store; |
1237 |
); |
| 1248 |
|
1238 |
|
|
|
1239 |
is( ref($line->checkout), 'Koha::Checkout', 'Object type is correct' ); |
| 1249 |
is( $line->checkout->id, $checkout->id, |
1240 |
is( $line->checkout->id, $checkout->id, |
| 1250 |
'Koha::Account::Line->checkout should return the correct checkout' ); |
1241 |
'Koha::Account::Line->checkout should return the correct checkout' ); |
| 1251 |
|
1242 |
|
|
|
1243 |
my $item_2 = $builder->build_sample_item({ library => $library->branchcode }); |
| 1244 |
my $old_checkout = $builder->build_object( |
| 1245 |
{ |
| 1246 |
class => 'Koha::Old::Checkouts', |
| 1247 |
value => { |
| 1248 |
borrowernumber => $patron->borrowernumber, |
| 1249 |
itemnumber => $item_2->itemnumber, |
| 1250 |
branchcode => $library->branchcode |
| 1251 |
} |
| 1252 |
} |
| 1253 |
); |
| 1254 |
|
| 1255 |
my $old_checkout_line = $builder->build_object( |
| 1256 |
{ |
| 1257 |
class => 'Koha::Account::Lines', |
| 1258 |
value => { |
| 1259 |
borrowernumber => $patron->borrowernumber, |
| 1260 |
itemnumber => $item_2->itemnumber, |
| 1261 |
issue_id => $old_checkout->id, |
| 1262 |
} |
| 1263 |
} |
| 1264 |
); |
| 1265 |
|
| 1266 |
is( ref($old_checkout_line->checkout), 'Koha::Old::Checkout', 'Object type is correct' ); |
| 1267 |
is( $old_checkout_line->checkout->id, $old_checkout->id, |
| 1268 |
'Koha::Account::Line->checkout should return the correct (old) checkout' ); |
| 1269 |
|
| 1270 |
my $no_checkout_line = $builder->build_object( |
| 1271 |
{ |
| 1272 |
class => 'Koha::Account::Lines', |
| 1273 |
value => { |
| 1274 |
itemnumber => $item_2->itemnumber, |
| 1275 |
issue_id => undef |
| 1276 |
} |
| 1277 |
} |
| 1278 |
); |
| 1279 |
|
| 1280 |
is( $no_checkout_line->checkout, undef, 'No issue_id makes it return undef' ); |
| 1281 |
|
| 1252 |
$schema->storage->txn_rollback; |
1282 |
$schema->storage->txn_rollback; |
| 1253 |
}; |
1283 |
}; |
| 1254 |
|
1284 |
|