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
53 can_ok( $self->testing_class, @methods );
56 =head3 setup_add_biblios
58 everything in the C4::Circulation really requires items, so let's do this in the setup phase.
62 sub setup_add_biblios : Tests( setup => 8 ) {
65 # we want to use a fresh batch of items, so clear these lists:
66 delete $self->{'items'};
67 delete $self->{'biblios'};
69 $self->add_biblios( add_items => 1 );
73 =head3 checkout_first_item
76 borrower => borrower hashref, computed from $self->{'memberid'} if not given
77 barcode => item barcode, barcode of $self->{'items'}[0] if not given
78 issuedate => YYYY-MM-DD of date to mark issue checked out. defaults to today.
82 sub checkout_first_item {
86 # get passed in borrower, or default to the one in $self.
87 my $borrower = $params->{'borrower'};
88 if ( ! defined $borrower ) {
89 my $borrowernumber = $self->{'memberid'};
90 $borrower = C4::Members::GetMemberDetails( $borrowernumber );
93 # get the barcode passed in, or default to the first one in the items list
94 my $barcode = $params->{'barcode'};
95 if ( ! defined $barcode ) {
96 return unless $self->{'items'}[0]{'itemnumber'};
97 $barcode = $self->get_barcode_from_itemnumber( $self->{'items'}[0]{'itemnumber'} );
100 # get issuedate from parameters. Default to undef, which will be interpreted as today
101 my $issuedate = $params->{'issuedate'};
103 my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $borrower, $barcode );
105 my $datedue = C4::Circulation::AddIssue(
106 $borrower, # borrower
109 undef, # cancelreserve
110 $issuedate # issuedate
113 my $issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
115 return $issues->{'date_due'};
118 =head3 get_barcode_from_itemnumber
120 pass in an itemnumber, returns a barcode.
122 Should this get moved up to KohaTest.pm? Or, is there a better alternative in C4?
126 sub get_barcode_from_itemnumber {
128 my $itemnumber = shift;
135 my $dbh = C4::Context->dbh() or return;
136 my $sth = $dbh->prepare($sql) or return;
137 $sth->execute($itemnumber) or return;
138 my ($barcode) = $sth->fetchrow_array;