1 package KohaTest::Circulation;
2 use base qw( KohaTest );
10 sub testing_class { 'C4::Circulation' };
13 sub methods : Test( 1 ) {
15 my @methods = qw( barcodedecode
24 GetBranchBorrowerCircRule
28 _FixAccountForLostAndReturned
46 CheckRepeatableHolidays
48 CheckRepeatableSpecialHolidays
54 can_ok( $self->testing_class, @methods );
57 =head3 setup_add_biblios
59 everything in the C4::Circulation really requires items, so let's do this in the setup phase.
63 sub setup_add_biblios : Tests( setup => 8 ) {
66 # we want to use a fresh batch of items, so clear these lists:
67 delete $self->{'items'};
68 delete $self->{'biblios'};
70 $self->add_biblios( add_items => 1 );
74 =head3 checkout_first_item
77 borrower => borrower hashref, computed from $self->{'memberid'} if not given
78 barcode => item barcode, barcode of $self->{'items'}[0] if not given
79 issuedate => YYYY-MM-DD of date to mark issue checked out. defaults to today.
83 sub checkout_first_item {
87 # get passed in borrower, or default to the one in $self.
88 my $borrower = $params->{'borrower'};
89 if ( ! defined $borrower ) {
90 my $borrowernumber = $self->{'memberid'};
91 $borrower = C4::Members::GetMemberDetails( $borrowernumber );
94 # get the barcode passed in, or default to the first one in the items list
95 my $barcode = $params->{'barcode'};
96 if ( ! defined $barcode ) {
97 return unless $self->{'items'}[0]{'itemnumber'};
98 $barcode = $self->get_barcode_from_itemnumber( $self->{'items'}[0]{'itemnumber'} );
101 # get issuedate from parameters. Default to undef, which will be interpreted as today
102 my $issuedate = $params->{'issuedate'};
104 my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $borrower, $barcode );
106 my $datedue = C4::Circulation::AddIssue(
107 $borrower, # borrower
110 undef, # cancelreserve
111 $issuedate # issuedate
114 my $issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
116 return $issues->{'date_due'};
119 =head3 get_barcode_from_itemnumber
121 pass in an itemnumber, returns a barcode.
123 Should this get moved up to KohaTest.pm? Or, is there a better alternative in C4?
127 sub get_barcode_from_itemnumber {
129 my $itemnumber = shift;
136 my $dbh = C4::Context->dbh() or return;
137 my $sth = $dbh->prepare($sql) or return;
138 $sth->execute($itemnumber) or return;
139 my ($barcode) = $sth->fetchrow_array;