Bug 8252: (follow-up) add basic UNIMARC indexing tests
[koha.git] / t / db_dependent / rollingloans.t
1
2 use strict;
3 use warnings;
4 use 5.010;
5 use C4::Context;
6 use C4::Circulation;
7 use C4::Members;
8 use C4::Items;
9
10 use Test::More tests => 8;
11 C4::Context->_new_userenv(1234567);
12 C4::Context->set_userenv(91, 'CLIstaff', '23529001223661', 'CPL',
13                          'CPL', 'CPL', '', 'cc@cscnet.co.uk');
14
15
16 my $test_patron = '23529001223651';
17 my $test_item_fic = '502326000402';
18 my $test_item_24 = '502326000404';
19 my $test_item_48 = '502326000403';
20
21 my $borrower1 =  GetMember(cardnumber => $test_patron);
22 my $item1 = GetItem (undef,$test_item_fic);
23
24 SKIP: {
25     skip 'Missing test borrower or item, skipping tests', 8
26       unless ( defined $borrower1 && defined $item1 );
27
28     for my $item_barcode ( $test_item_fic, $test_item_24, $test_item_48 ) {
29         my $duedate = try_issue( $test_patron, $item_barcode );
30         isa_ok( $duedate, 'DateTime' );
31         if ( $item_barcode eq $test_item_fic ) {
32             is( $duedate->hour(),   23, "daily loan hours = 23" );
33             is( $duedate->minute(), 59, "daily loan mins = 59" );
34         }
35         my $ret_ok = try_return($item_barcode);
36         is( $ret_ok, 1, 'Return succeeded' );
37     }
38 }
39
40 sub try_issue {
41     my ($cardnumber, $item ) = @_;
42     my $issuedate = '2011-05-16';
43     my $borrower = GetMemberDetails(0, $cardnumber);
44     my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued( $borrower, $item );
45         my $due_date = AddIssue($borrower, $item, undef, 0, $issuedate);
46     return $due_date;
47 }
48
49 sub try_return {
50     my $barcode = shift;
51     my ($ret, $messages, $iteminformation, $borrower) = AddReturn($barcode);
52     return $ret;
53 }