Bug 19280: Pass a Koha::Patron to CanBookBeIssued
[koha.git] / t / db_dependent / rollingloans.t
1
2 use Modern::Perl;
3 use C4::Context;
4 use C4::Circulation;
5 use C4::Members;
6 use C4::Items;
7 use Koha::DateUtils;
8 use Koha::Patrons;
9 use t::lib::TestBuilder;
10
11 use Test::More tests => 8;
12
13 my $schema = Koha::Database->new->schema;
14 $schema->storage->txn_begin;
15
16 C4::Context->_new_userenv(1234567);
17 C4::Context->set_userenv(91, 'CLIstaff', '23529001223661', 'CPL',
18                          'CPL', 'CPL', '', 'cc@cscnet.co.uk');
19
20
21 my $test_patron = '23529001223651';
22 my $test_item_fic = '502326000402';
23 my $test_item_24 = '502326000404';
24 my $test_item_48 = '502326000403';
25
26 my $builder = t::lib::TestBuilder->new;
27 my $borrower1 = $builder->build_object({ class => 'Koha::Patrons', value => { cardnumber => $test_patron } });
28 my $item1 = GetItem (undef,$test_item_fic);
29
30 SKIP: {
31     skip 'Missing test borrower or item, skipping tests', 8
32       unless ( defined $borrower1 && defined $item1 );
33
34     for my $item_barcode ( $test_item_fic, $test_item_24, $test_item_48 ) {
35         my $duedate = try_issue( $test_patron, $item_barcode );
36         isa_ok( $duedate, 'DateTime' );
37         if ( $item_barcode eq $test_item_fic ) {
38             is( $duedate->hour(),   23, "daily loan hours = 23" );
39             is( $duedate->minute(), 59, "daily loan mins = 59" );
40         }
41         my $ret_ok = try_return($item_barcode);
42         is( $ret_ok, 1, 'Return succeeded' );
43     }
44 }
45
46 sub try_issue {
47     my ($cardnumber, $item ) = @_;
48     my $issuedate = '2011-05-16';
49     my $patron = Koha::Patrons->find( { cardnumber => $cardnumber } );
50     my ($issuingimpossible,$needsconfirmation) = CanBookBeIssued( $patron, $item );
51     my $issue = AddIssue($patron->unblessed, $item, undef, 0, $issuedate);
52     return dt_from_string( $issue->due_date() );
53 }
54
55 sub try_return {
56     my $barcode = shift;
57     my ($ret, $messages, $iteminformation, $borrower) = AddReturn($barcode);
58     return $ret;
59 }