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( 11 ) {
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 my $datedue = C4::Circulation::AddIssue( $borrower, $barcode );
48 local $TODO = 'AddIssue does not actually return the due date';
49 ok( $datedue, "the item has been issued and it is due: $datedue" );
52 my $after_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
53 is( $after_issues->{'borrowernumber'}, $borrowernumber, '...and now it is checked out to our borrower' )
54 or diag( Data::Dumper->Dump( [ $after_issues ], [ 'after_issues' ] ) );
56 my $loanlength = Date::Calc::Delta_Days( split( /-/, $after_issues->{'issuedate'} ), split( /-/, $after_issues->{'date_due'} ) );
57 ok( $loanlength, "the loanlength is $loanlength days" );
59 # save this here since we refer to it in set_issuedate.
60 $self->{'loanlength'} = $loanlength;
66 Make sure that we can set the issuedate of an issue.
68 Also, since we are specifying an issuedate and not a due date, the due
69 date should be calculated from the issuedate, not today.
73 sub set_issuedate : Test( 7 ) {
76 my $before_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
77 ok( ! defined $before_issues->{'borrowernumber'}, 'At this beginning, this item was not checked out.' )
78 or diag( Data::Dumper->Dump( [ $before_issues ], [ 'before_issues' ] ) );
80 my $issuedate = $self->random_date();
81 ok( $issuedate, "Check out an item on $issuedate" );
82 my $datedue = $self->checkout_first_item( { issuedate => $issuedate } );
83 ok( $datedue, "...and it's due on $datedue" );
85 my $after_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
86 is( $after_issues->{'borrowernumber'}, $self->{'memberid'}, 'We found this item checked out to our member.' )
87 or diag( Data::Dumper->Dump( [ $after_issues ], [ 'issues' ] ) );
88 is( $after_issues->{'issuedate'}, $issuedate, "...and it was issued on $issuedate" )
89 or diag( Data::Dumper->Dump( [ $after_issues ], [ 'after_issues' ] ) );
91 my $loanlength = Date::Calc::Delta_Days( split( /-/, $after_issues->{'issuedate'} ), split( /-/, $after_issues->{'date_due'} ) );
92 ok( $loanlength, "the loanlength is $loanlength days" );
93 is( $loanlength, $self->{'loanlength'} );
96 sub set_issuedate_on_renewal : Test( 6 ) {
99 my $before_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
100 ok( ! defined $before_issues->{'borrowernumber'}, 'At this beginning, this item was not checked out.' )
101 or diag( Data::Dumper->Dump( [ $before_issues ], [ 'before_issues' ] ) );
103 my $datedue = $self->checkout_first_item( { issuedate => $self->yesterday() } );
104 ok( $datedue, "The item is checked out and it's due on $datedue" );
106 my $issuedate = $self->random_date();
107 ok( $issuedate, "Check out an item again on $issuedate" );
108 # This will actually be a renewal
109 $datedue = $self->checkout_first_item( { issuedate => $issuedate } );
110 ok( $datedue, "...and it's due on $datedue" );
112 my $after_issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
113 is( $after_issues->{'borrowernumber'}, $self->{'memberid'}, 'We found this item checked out to our member.' )
114 or diag( Data::Dumper->Dump( [ $after_issues ], [ 'issues' ] ) );
115 is( $after_issues->{'issuedate'}, $issuedate, "...and it was issued on $issuedate" )
116 or diag( Data::Dumper->Dump( [ $after_issues ], [ 'after_issues' ] ) );