Lines 19-25
use Modern::Perl;
Link Here
|
19 |
use utf8; |
19 |
use utf8; |
20 |
|
20 |
|
21 |
use Test::NoWarnings; |
21 |
use Test::NoWarnings; |
22 |
use Test::More tests => 78; |
22 |
use Test::More tests => 80; |
23 |
use Test::Exception; |
23 |
use Test::Exception; |
24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
25 |
use Test::Deep qw( cmp_deeply ); |
25 |
use Test::Deep qw( cmp_deeply ); |
Lines 7120-7125
subtest "SendCirculationAlert" => sub {
Link Here
|
7120 |
|
7120 |
|
7121 |
}; |
7121 |
}; |
7122 |
|
7122 |
|
|
|
7123 |
subtest 'AddIssue | booking_id field linkage' => sub { |
7124 |
plan tests => 6; |
7125 |
|
7126 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
7127 |
my $patron1 = $builder->build_object( { class => 'Koha::Patrons' } ); |
7128 |
my $patron2 = $builder->build_object( { class => 'Koha::Patrons' } ); |
7129 |
my $item = $builder->build_sample_item( { bookable => 1 } ); |
7130 |
|
7131 |
# Patron checks out item with their own booking - booking_id should be set |
7132 |
my $booking1 = Koha::Booking->new( |
7133 |
{ |
7134 |
patron_id => $patron1->borrowernumber, |
7135 |
pickup_library_id => $library->branchcode, |
7136 |
item_id => $item->itemnumber, |
7137 |
biblio_id => $item->biblio->biblionumber, |
7138 |
start_date => dt_from_string(), |
7139 |
end_date => dt_from_string()->add( days => 5 ), |
7140 |
} |
7141 |
)->store(); |
7142 |
|
7143 |
my $issue1 = AddIssue( $patron1, $item->barcode, dt_from_string()->add( days => 7 ) ); |
7144 |
is( $issue1->booking_id, $booking1->booking_id, "Checkout linked to patron's own booking via booking_id" ); |
7145 |
|
7146 |
# Verify the relationship accessor works |
7147 |
my $linked_booking = $issue1->booking; |
7148 |
is( $linked_booking->booking_id, $booking1->booking_id, "Booking relationship accessor returns correct booking" ); |
7149 |
|
7150 |
# Verify booking_id is preserved when moved to old_issues on return |
7151 |
my ( $returned, undef, undef, undef ) = AddReturn( $item->barcode, $library->branchcode ); |
7152 |
is( $returned, 1, "Item returned successfully" ); |
7153 |
|
7154 |
my $old_checkout = Koha::Old::Checkouts->find( { issue_id => $issue1->issue_id } ); |
7155 |
is( $old_checkout->booking_id, $booking1->booking_id, "booking_id preserved in old_issues after return" ); |
7156 |
|
7157 |
# Verify old_checkout booking relationship works |
7158 |
my $old_linked_booking = $old_checkout->booking; |
7159 |
is( $old_linked_booking->booking_id, $booking1->booking_id, "Old checkout booking relationship accessor works" ); |
7160 |
|
7161 |
# Another patron checks out - no booking_id should be set |
7162 |
$booking1->delete(); |
7163 |
my $issue2 = AddIssue( $patron2, $item->barcode, dt_from_string()->add( days => 7 ) ); |
7164 |
is( $issue2->booking_id, undef, "No booking_id set when checkout is not from a patron's own booking" ); |
7165 |
}; |
7166 |
|
7167 |
subtest 'AddRenewal | booking_id preservation' => sub { |
7168 |
plan tests => 3; |
7169 |
|
7170 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
7171 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
7172 |
my $item = $builder->build_sample_item( { library => $library->branchcode } ); |
7173 |
|
7174 |
# Set up renewal rules |
7175 |
Koha::CirculationRules->set_rules( |
7176 |
{ |
7177 |
branchcode => $library->branchcode, |
7178 |
categorycode => $patron->categorycode, |
7179 |
itemtype => $item->effective_itemtype, |
7180 |
rules => { |
7181 |
renewalsallowed => 10, |
7182 |
renewalperiod => 7, |
7183 |
issuelength => 7, |
7184 |
} |
7185 |
} |
7186 |
); |
7187 |
|
7188 |
# Create a simple booking using the builder |
7189 |
my $booking = $builder->build_object( |
7190 |
{ |
7191 |
class => 'Koha::Bookings', |
7192 |
value => { |
7193 |
patron_id => $patron->borrowernumber, |
7194 |
item_id => $item->itemnumber, |
7195 |
pickup_library_id => $library->branchcode, |
7196 |
status => 'completed' |
7197 |
} |
7198 |
} |
7199 |
); |
7200 |
|
7201 |
# Create a checkout and manually set booking_id to simulate a booking-linked checkout |
7202 |
my $issue = AddIssue( $patron, $item->barcode ); |
7203 |
$issue->booking_id( $booking->booking_id )->store; |
7204 |
|
7205 |
# Renew the checkout |
7206 |
AddRenewal( |
7207 |
{ |
7208 |
borrowernumber => $patron->borrowernumber, |
7209 |
itemnumber => $item->itemnumber, |
7210 |
branch => $library->branchcode, |
7211 |
} |
7212 |
); |
7213 |
|
7214 |
# Refresh the issue object and test that booking_id is preserved |
7215 |
$issue = $issue->get_from_storage; |
7216 |
is( $issue->booking_id, $booking->booking_id, "booking_id preserved after renewal" ); |
7217 |
is( $issue->renewals_count, 1, "Renewal count incremented" ); |
7218 |
ok( defined $issue->booking_id, "booking_id field is not null after renewal" ); |
7219 |
}; |
7220 |
|
7123 |
subtest "GetSoonestRenewDate tests" => sub { |
7221 |
subtest "GetSoonestRenewDate tests" => sub { |
7124 |
plan tests => 6; |
7222 |
plan tests => 6; |
7125 |
Koha::CirculationRules->set_rule( |
7223 |
Koha::CirculationRules->set_rule( |