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

(-)a/t/db_dependent/Koha/Biblio.t (-2 / +107 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 31;
20
use Test::More tests => 32;
21
use Test::Exception;
21
use Test::Exception;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 25-30 use C4::Biblio qw( AddBiblio ModBiblio ModBiblioMarc ); Link Here
25
use C4::Circulation qw( AddIssue AddReturn );
25
use C4::Circulation qw( AddIssue AddReturn );
26
26
27
use Koha::Database;
27
use Koha::Database;
28
use Koha::DateUtils qw( dt_from_string );
28
use Koha::Cache::Memory::Lite;
29
use Koha::Cache::Memory::Lite;
29
use Koha::Caches;
30
use Koha::Caches;
30
use Koha::Acquisition::Orders;
31
use Koha::Acquisition::Orders;
Lines 1299-1301 sub host_record { Link Here
1299
    );
1300
    );
1300
    return $marc;
1301
    return $marc;
1301
}
1302
}
1302
- 
1303
1304
subtest 'check_booking tests' => sub {
1305
    plan tests => 4;
1306
1307
    $schema->storage->txn_begin;
1308
1309
    my $biblio = $builder->build_sample_biblio();
1310
    my @items;
1311
    for ( 0 .. 2 ) {
1312
        my $item = $builder->build_sample_item( { biblionumber => $biblio->biblionumber, bookable => 1 } );
1313
        push @items, $item;
1314
    }
1315
1316
    my $can_book = $biblio->check_booking(
1317
        {
1318
            start_date => dt_from_string(),
1319
            end_date   => dt_from_string()->add( days => 7 )
1320
        }
1321
    );
1322
1323
    is(
1324
        $can_book, 1,
1325
        "True returned from Koha::Biblio->check_booking if there are no bookings"
1326
    );
1327
1328
    my $start_1 = dt_from_string()->subtract( days => 7 );
1329
    my $end_1   = dt_from_string()->subtract( days => 1 );
1330
    my $start_2 = dt_from_string();
1331
    my $end_2   = dt_from_string()->add( days => 7 );
1332
1333
    # Past bookings
1334
    my @bookings;
1335
    for my $item (@items) {
1336
1337
        my $booking = $builder->build_object(
1338
            {
1339
                class => 'Koha::Bookings',
1340
                value => {
1341
                    biblio_id  => $biblio->biblionumber,
1342
                    item_id    => $item->itemnumber,
1343
                    start_date => $start_1,
1344
                    end_date   => $end_1
1345
                }
1346
            }
1347
        );
1348
        push @bookings, $booking;
1349
    }
1350
1351
    $can_book = $biblio->check_booking(
1352
        {
1353
            start_date => dt_from_string(),
1354
            end_date   => dt_from_string()->add( days => 7 ),
1355
        }
1356
    );
1357
1358
    is(
1359
        $can_book,
1360
        1,
1361
        "Koha::Biblio->check_booking returns true when we all existing bookings are in the past"
1362
    );
1363
1364
    # Current bookings
1365
    my @current_bookings;
1366
    for my $item (@items) {
1367
        my $booking = $builder->build_object(
1368
            {
1369
                class => 'Koha::Bookings',
1370
                value => {
1371
                    biblio_id  => $biblio->biblionumber,
1372
                    item_id    => $item->itemnumber,
1373
                    start_date => $start_2,
1374
                    end_date   => $end_2
1375
                }
1376
            }
1377
        );
1378
        push @current_bookings, $booking;
1379
    }
1380
1381
    $can_book = $biblio->check_booking(
1382
        {
1383
            start_date => dt_from_string(),
1384
            end_date   => dt_from_string()->add( days => 7 ),
1385
        }
1386
    );
1387
    is(
1388
        $can_book,
1389
        0,
1390
        "Koha::Biblio->check_booking returns false if the booking would conflict with existing bookings"
1391
    );
1392
1393
    $can_book = $biblio->check_booking(
1394
        {
1395
            start_date => dt_from_string(),
1396
            end_date   => dt_from_string()->add( days => 7 ),
1397
            booking_id => $current_bookings[0]->booking_id
1398
        }
1399
    );
1400
    is(
1401
        $can_book,
1402
        1,
1403
        "Koha::Biblio->check_booking returns true if we pass the booking_id of one of the bookings that we would conflict with"
1404
    );
1405
1406
    $schema->storage->txn_rollback;
1407
};

Return to bug 35248