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
52 can_ok( $self->testing_class, @methods );
55 =head3 setup_add_biblios
57 everything in the C4::Circulation really requires items, so let's do this in the setup phase.
61 sub setup_add_biblios : Tests( setup => 8 ) {
64 # we want to use a fresh batch of items, so clear these lists:
65 delete $self->{'items'};
66 delete $self->{'biblios'};
68 $self->add_biblios( add_items => 1 );
72 =head3 checkout_first_item
75 borrower => borrower hashref, computed from $self->{'memberid'} if not given
76 barcode => item barcode, barcode of $self->{'items'}[0] if not given
77 issuedate => YYYY-MM-DD of date to mark issue checked out. defaults to today.
81 sub checkout_first_item {
85 # get passed in borrower, or default to the one in $self.
86 my $borrower = $params->{'borrower'};
87 if ( ! defined $borrower ) {
88 my $borrowernumber = $self->{'memberid'};
89 $borrower = C4::Members::GetMemberDetails( $borrowernumber );
92 # get the barcode passed in, or default to the first one in the items list
93 my $barcode = $params->{'barcode'};
94 if ( ! defined $barcode ) {
95 return unless $self->{'items'}[0]{'itemnumber'};
96 $barcode = $self->get_barcode_from_itemnumber( $self->{'items'}[0]{'itemnumber'} );
99 # get issuedate from parameters. Default to undef, which will be interpreted as today
100 my $issuedate = $params->{'issuedate'};
102 my ( $issuingimpossible, $needsconfirmation ) = C4::Circulation::CanBookBeIssued( $borrower, $barcode );
104 my $datedue = C4::Circulation::AddIssue(
105 $borrower, # borrower
108 undef, # cancelreserve
109 $issuedate # issuedate
112 my $issues = C4::Circulation::GetItemIssue( $self->{'items'}[0]{'itemnumber'} );
114 return $issues->{'date_due'};
117 =head3 get_barcode_from_itemnumber
119 pass in an itemnumber, returns a barcode.
121 Should this get moved up to KohaTest.pm? Or, is there a better alternative in C4?
125 sub get_barcode_from_itemnumber {
127 my $itemnumber = shift;
134 my $dbh = C4::Context->dbh() or return;
135 my $sth = $dbh->prepare($sql) or return;
136 $sth->execute($itemnumber) or return;
137 my ($barcode) = $sth->fetchrow_array;