View | Details | Raw Unified | Return to bug 40665
Collapse All | Expand All

(-)a/t/db_dependent/Circulation.t (-1 / +99 lines)
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(
(-)a/t/db_dependent/Koha/Booking.t (-1 / +85 lines)
Lines 38-44 my $schema = Koha::Database->new->schema; Link Here
38
my $builder = t::lib::TestBuilder->new;
38
my $builder = t::lib::TestBuilder->new;
39
39
40
subtest 'Relation accessor tests' => sub {
40
subtest 'Relation accessor tests' => sub {
41
    plan tests => 4;
41
    plan tests => 6;
42
42
43
    subtest 'biblio relation tests' => sub {
43
    subtest 'biblio relation tests' => sub {
44
        plan tests => 3;
44
        plan tests => 3;
Lines 125-130 subtest 'Relation accessor tests' => sub { Link Here
125
125
126
        $schema->storage->txn_rollback;
126
        $schema->storage->txn_rollback;
127
    };
127
    };
128
129
    subtest 'checkout relation tests' => sub {
130
        plan tests => 4;
131
        $schema->storage->txn_begin;
132
133
        my $patron  = $builder->build_object( { class => "Koha::Patrons" } );
134
        my $item    = $builder->build_sample_item( { bookable => 1 } );
135
        my $booking = $builder->build_object(
136
            {
137
                class => 'Koha::Bookings',
138
                value => {
139
                    patron_id => $patron->borrowernumber,
140
                    item_id   => $item->itemnumber,
141
                    status    => 'completed'
142
                }
143
            }
144
        );
145
146
        my $checkout = $booking->checkout;
147
        is( $checkout, undef, "Koha::Booking->checkout returns undef when no checkout exists" );
148
149
        my $issue = $builder->build_object(
150
            {
151
                class => 'Koha::Checkouts',
152
                value => {
153
                    borrowernumber => $patron->borrowernumber,
154
                    itemnumber     => $item->itemnumber,
155
                    booking_id     => $booking->booking_id
156
                }
157
            }
158
        );
159
160
        $checkout = $booking->checkout;
161
        is( ref($checkout),        'Koha::Checkout',     "Koha::Booking->checkout returns a Koha::Checkout object" );
162
        is( $checkout->issue_id,   $issue->issue_id,     "Koha::Booking->checkout returns the linked checkout" );
163
        is( $checkout->booking_id, $booking->booking_id, "The checkout is properly linked to the booking" );
164
165
        $schema->storage->txn_rollback;
166
    };
167
168
    subtest 'old_checkout relation tests' => sub {
169
        plan tests => 4;
170
        $schema->storage->txn_begin;
171
172
        my $patron  = $builder->build_object( { class => "Koha::Patrons" } );
173
        my $item    = $builder->build_sample_item( { bookable => 1 } );
174
        my $booking = $builder->build_object(
175
            {
176
                class => 'Koha::Bookings',
177
                value => {
178
                    patron_id => $patron->borrowernumber,
179
                    item_id   => $item->itemnumber,
180
                    status    => 'completed'
181
                }
182
            }
183
        );
184
185
        my $old_checkout = $booking->old_checkout;
186
        is( $old_checkout, undef, "Koha::Booking->old_checkout returns undef when no old_checkout exists" );
187
188
        my $old_issue = $builder->build_object(
189
            {
190
                class => 'Koha::Old::Checkouts',
191
                value => {
192
                    borrowernumber => $patron->borrowernumber,
193
                    itemnumber     => $item->itemnumber,
194
                    booking_id     => $booking->booking_id
195
                }
196
            }
197
        );
198
199
        $old_checkout = $booking->old_checkout;
200
        is(
201
            ref($old_checkout), 'Koha::Old::Checkout',
202
            "Koha::Booking->old_checkout returns a Koha::Old::Checkout object"
203
        );
204
        is(
205
            $old_checkout->issue_id, $old_issue->issue_id,
206
            "Koha::Booking->old_checkout returns the linked old_checkout"
207
        );
208
        is( $old_checkout->booking_id, $booking->booking_id, "The old_checkout is properly linked to the booking" );
209
210
        $schema->storage->txn_rollback;
211
    };
128
};
212
};
129
213
130
subtest 'store() tests' => sub {
214
subtest 'store() tests' => sub {
(-)a/t/db_dependent/Koha/Checkout.t (-2 / +31 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::NoWarnings;
22
use Test::NoWarnings;
23
use Test::More tests => 5;
23
use Test::More tests => 6;
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
25
26
use Koha::Database;
26
use Koha::Database;
Lines 187-189 subtest 'public_read_list() tests' => sub { Link Here
187
187
188
    $schema->storage->txn_rollback;
188
    $schema->storage->txn_rollback;
189
};
189
};
190
- 
190
191
subtest 'booking() tests' => sub {
192
    plan tests => 4;
193
194
    $schema->storage->txn_begin;
195
196
    my $booking  = $builder->build_object( { class => 'Koha::Bookings' } );
197
    my $checkout = $builder->build_object(
198
        {
199
            class => 'Koha::Checkouts',
200
            value => { booking_id => $booking->booking_id }
201
        }
202
    );
203
204
    my $linked_booking = $checkout->booking;
205
    is( ref($linked_booking),        'Koha::Booking',      'booking() returns a Koha::Booking object' );
206
    is( $linked_booking->booking_id, $booking->booking_id, 'booking() returns the correct booking' );
207
208
    my $checkout_no_booking = $builder->build_object(
209
        {
210
            class => 'Koha::Checkouts',
211
            value => { booking_id => undef }
212
        }
213
    );
214
215
    my $no_booking = $checkout_no_booking->booking;
216
    is( $no_booking, undef, 'booking() returns undef when no booking_id is set' );
217
218
    $schema->storage->txn_rollback;
219
};

Return to bug 40665