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

(-)a/t/db_dependent/Koha/Booking.t (-4 / +46 lines)
Lines 314-326 subtest 'store() tests' => sub { Link Here
314
    ok( $booking->item_id,    'An item was assigned to the booking' );
314
    ok( $booking->item_id,    'An item was assigned to the booking' );
315
315
316
    subtest '_assign_item_for_booking() tests' => sub {
316
    subtest '_assign_item_for_booking() tests' => sub {
317
        plan tests => 1;
317
        plan tests => 5;
318
        is( $booking->item_id, $item_1->itemnumber, "Item 1 was assigned to the booking" );
319
318
320
        # Bookings
319
        # Bookings
321
        # ✓ Item 1    |----|
320
        # ✓ Item 1    |----|
322
        # ✓ Item 2     |--|
321
        # ✓ Item 2     |--|
323
        # ✓ Any (1)         |--|
322
        # ✓ Any (X)         |--|
323
        my $valid_items   = [ $item_1->itemnumber, $item_2->itemnumber ];
324
        my $assigned_item = $booking->item_id;
325
        is(
326
            ( scalar grep { $_ == $assigned_item } @$valid_items ), 1,
327
            'The item assigned was one of the valid, bookable items'
328
        );
329
330
        my $second_booking = Koha::Booking->new(
331
            {
332
                patron_id         => $patron->borrowernumber,
333
                biblio_id         => $biblio->biblionumber,
334
                pickup_library_id => $item_2->homebranch,
335
                start_date        => $start_1,
336
                end_date          => $end_1
337
            }
338
        )->store();
339
        isnt( $second_booking->item_id, $assigned_item, "The subsequent booking picks the only other available item" );
340
341
        # Cancel both bookings so we can check that cancelled bookings are allowed in the auto-assign
342
        $booking->status('cancelled')->store();
343
        $second_booking->status('cancelled')->store();
344
        is($booking->status, 'cancelled', "Booking is cancelled");
345
        is($second_booking->status, 'cancelled', "Second booking is cancelled");
346
347
        # Test randomness of selection
348
        my %seen_items;
349
        foreach my $i ( 1 .. 10 ) {
350
            my $new_booking = Koha::Booking->new(
351
                {
352
                    patron_id         => $patron->borrowernumber,
353
                    biblio_id         => $biblio->biblionumber,
354
                    pickup_library_id => $item_1->homebranch,
355
                    start_date        => $start_1,
356
                    end_date          => $end_1
357
                }
358
            );
359
            $new_booking->store();
360
            $seen_items{ $new_booking->item_id }++;
361
            $new_booking->delete();
362
        }
363
        ok(
364
            scalar( keys %seen_items ) > 1,
365
            'Multiple different items were selected randomly across bookings, and a cancelled booking is allowed in the selection'
366
        );
324
    };
367
    };
325
368
326
    subtest 'confirmation notice trigger' => sub {
369
    subtest 'confirmation notice trigger' => sub {
327
- 

Return to bug 38175