+subtest 'automatic_checkin' => sub {
+ plan tests => 6;
+
+ $schema->storage->txn_begin;
+
+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
+
+ my $due_ac_item =
+ $builder->build_sample_item( { homebranch => $patron->branchcode } );
+ my $ac_item =
+ $builder->build_sample_item( { homebranch => $patron->branchcode } );
+ my $normal_item =
+ $builder->build_sample_item( { homebranch => $patron->branchcode } );
+
+ $due_ac_item->itemtype->automatic_checkin(1)->store;
+ $ac_item->itemtype->automatic_checkin(1)->store;
+ $normal_item->itemtype->automatic_checkin(0)->store;
+
+ my $current_date = dt_from_string;
+
+ # due checkout for automatic checkin
+ my $checkout_due_aci = Koha::Checkout->new(
+ {
+ borrowernumber => $patron->borrowernumber,
+ itemnumber => $due_ac_item->itemnumber,
+ branchcode => $patron->branchcode,
+ date_due => $current_date,
+ }
+ )->store;
+
+ # in time checkout for automatic checkin
+ my $checkout_aci = Koha::Checkout->new(
+ {
+ borrowernumber => $patron->borrowernumber,
+ itemnumber => $ac_item->itemnumber,
+ branchcode => $patron->branchcode,
+ }
+ )->store;
+
+ # due checkout for nomal itemtype
+ my $checkout_ni = Koha::Checkout->new(
+ {
+ borrowernumber => $patron->borrowernumber,
+ itemnumber => $normal_item->itemnumber,
+ branchcode => $patron->branchcode,
+ date_due => $current_date,
+ }
+ )->store;
+
+ my $searched = Koha::Checkouts->find( $checkout_ni->issue_id );
+ is( $searched->issue_id, $checkout_ni->issue_id,
+ 'checkout for normal_item exists' );
+
+ $searched = Koha::Checkouts->find( $checkout_aci->issue_id );
+ is( $searched->issue_id, $checkout_aci->issue_id,
+ 'checkout for ac_item exists' );
+
+ $searched = Koha::Checkouts->find( $checkout_due_aci->issue_id );
+ is(
+ $searched->issue_id,
+ $checkout_due_aci->issue_id,
+ 'checkout for due_ac_item exists'
+ );
+
+ Koha::Checkouts->automatic_checkin;
+
+ $searched = Koha::Checkouts->find( $checkout_ni->issue_id );
+ is( $searched->issue_id, $checkout_ni->issue_id,
+ 'checkout for normal_item still exists' );
+
+ $searched = Koha::Checkouts->find( $checkout_aci->issue_id );
+ is( $searched->issue_id, $checkout_aci->issue_id,
+ 'checkout for ac_item still exists' );
+
+ $searched = Koha::Checkouts->find( $checkout_due_aci->issue_id );
+ is( $searched, undef, 'checkout for due_ac_item doesn\'t exist anymore' );
+
+ $schema->storage->txn_rollback;
+}