1 package KohaTest::Circulation::AddIssue;
2 use base qw(KohaTest::Circulation);
11 basic usage of C4::Circulation::AddIssue
13 Note: This logic is repeated in
14 KohaTest::Circulation::checkout_first_item, but without tests. This
15 includes tests at each step to make it easier to track down what's
16 broken as we go along.
20 sub basic_usage : Test( 13 ) {
23 my $borrowernumber = $self->{'memberid'};
24 ok( $borrowernumber, "we're going to work with borrower: $borrowernumber" );
26 my $borrower = C4::Members::GetMemberDetails( $borrowernumber );
27 ok( $borrower, '...and we were able to look up that borrower' );
28 is( $borrower->{'borrowernumber'}, $borrowernumber, '...and they have the right borrowernumber' );
30 my $itemnumber = $self->{'items'}[0]{'itemnumber'};
31 ok( $itemnumber, "We're going to checkout itemnumber $itemnumber" );
32 my $barcode = $self->get_barcode_from_itemnumber($itemnumber);
33 ok( $barcode, "...which has barcode $barcode" );
35 my $before_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
36 # Note that we can't check for $before_issues as undef because GetItemIssue always returns a populated hashref
37 ok( ! defined $before_issues->{'borrowernumber'}, '...and is not currently checked out' )
38 or diag( Data::Dumper->Dump( [ $before_issues ], [ 'before_issues' ] ) );
40 my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $borrower, $barcode );
41 is( scalar keys %$issuingimpossible, 0, 'the item CanBookBeIssued' )
42 or diag( Data::Dumper->Dump( [ $issuingimpossible, $needsconfirmation ], [ qw( issuingimpossible needsconfirmation ) ] ) );
43 is( scalar keys %$needsconfirmation, 0, '...and the transaction does not needsconfirmation' )
44 or diag( Data::Dumper->Dump( [ $issuingimpossible, $needsconfirmation ], [ qw( issuingimpossible needsconfirmation ) ] ) );
46 # bug 2758 don't ask for confirmation if patron has $0.00 account balance
47 # and IssuingInProcess is on
48 my $orig_issuing_in_process = C4::Context->preference('IssuingInProcess');
49 my $dbh = C4::Context->dbh;
50 $dbh->do("UPDATE systempreferences SET value = 1 WHERE variable = 'IssuingInProcess'");
51 C4::Context->clear_syspref_cache(); # FIXME not needed after a syspref mutator is written
52 ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $borrower, $barcode );
53 is( scalar keys %$issuingimpossible, 0, 'the item CanBookBeIssued with IssuingInProcess ON (bug 2758)' )
54 or diag( Data::Dumper->Dump( [ $issuingimpossible, $needsconfirmation ], [ qw( issuingimpossible needsconfirmation ) ] ) );
55 is( scalar keys %$needsconfirmation, 0,
56 '...and the transaction does not needsconfirmation with IssuingInProcess ON (bug 2758)' )
57 or diag( Data::Dumper->Dump( [ $issuingimpossible, $needsconfirmation ], [ qw( issuingimpossible needsconfirmation ) ] ) );
58 $dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'IssuingInProcess'", {}, $orig_issuing_in_process);
59 C4::Context->clear_syspref_cache(); # FIXME not needed after a syspref mutator is written
61 my $datedue = C4::Circulation::AddIssue( $borrower, $barcode );
62 ok( $datedue, "the item has been issued and it is due: $datedue" );
64 my $after_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
65 is( $after_issues->{'borrowernumber'}, $borrowernumber, '...and now it is checked out to our borrower' )
66 or diag( Data::Dumper->Dump( [ $after_issues ], [ 'after_issues' ] ) );
68 my $loanlength = Date::Calc::Delta_Days( split( /-/, $after_issues->{'issuedate'} ), split( /-/, $after_issues->{'date_due'} ) );
69 ok( $loanlength, "the loanlength is $loanlength days" );
71 # save this here since we refer to it in set_issuedate.
72 $self->{'loanlength'} = $loanlength;
78 Make sure that we can set the issuedate of an issue.
80 Also, since we are specifying an issuedate and not a due date, the due
81 date should be calculated from the issuedate, not today.
85 sub set_issuedate : Test( 7 ) {
88 my $before_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
89 ok( ! defined $before_issues->{'borrowernumber'}, 'At this beginning, this item was not checked out.' )
90 or diag( Data::Dumper->Dump( [ $before_issues ], [ 'before_issues' ] ) );
92 my $issuedate = $self->random_date();
93 ok( $issuedate, "Check out an item on $issuedate" );
94 my $datedue = $self->checkout_first_item( { issuedate => $issuedate } );
95 ok( $datedue, "...and it's due on $datedue" );
97 my $after_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
98 is( $after_issues->{'borrowernumber'}, $self->{'memberid'}, 'We found this item checked out to our member.' )
99 or diag( Data::Dumper->Dump( [ $after_issues ], [ 'issues' ] ) );
100 is( $after_issues->{'issuedate'}, $issuedate, "...and it was issued on $issuedate" )
101 or diag( Data::Dumper->Dump( [ $after_issues ], [ 'after_issues' ] ) );
103 my $loanlength = Date::Calc::Delta_Days( split( /-/, $after_issues->{'issuedate'} ), split( /-/, $after_issues->{'date_due'} ) );
104 ok( $loanlength, "the loanlength is $loanlength days" );
105 is( $loanlength, $self->{'loanlength'} );
108 sub set_lastreneweddate_on_renewal : Test( 6 ) {
111 my $before_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
112 ok( ! defined $before_issues->{'borrowernumber'}, 'At this beginning, this item was not checked out.' )
113 or diag( Data::Dumper->Dump( [ $before_issues ], [ 'before_issues' ] ) );
115 my $datedue = $self->checkout_first_item( { issuedate => $self->yesterday() } );
116 ok( $datedue, "The item is checked out and it's due on $datedue" );
118 my $issuedate = $self->random_date();
119 ok( $issuedate, "Check out an item again on $issuedate" );
120 # This will actually be a renewal
121 $datedue = $self->checkout_first_item( { issuedate => $issuedate } );
122 ok( $datedue, "...and it's due on $datedue" );
124 my $after_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
125 is( $after_issues->{'borrowernumber'}, $self->{'memberid'}, 'We found this item checked out to our member.' )
126 or diag( Data::Dumper->Dump( [ $after_issues ], [ 'issues' ] ) );
127 is( $after_issues->{'lastreneweddate'}, $issuedate, "...and it was renewed on $issuedate" )
128 or diag( Data::Dumper->Dump( [ $after_issues ], [ 'after_issues' ] ) );