3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test
::More tests
=> 13;
27 use_ok
('Koha::Objects');
28 use_ok
('Koha::Borrowers');
32 my $dbh = C4
::Context
->dbh;
33 $dbh->{AutoCommit
} = 0;
34 $dbh->{RaiseError
} = 1;
35 $dbh->do("DELETE FROM issues");
36 $dbh->do("DELETE FROM borrowers");
39 Koha
::Database
->new()->schema()->resultset('Category')->first()
42 Koha
::Database
->new()->schema()->resultset('Branch')->first()->branchcode();
44 my $b1 = Koha
::Borrower
->new(
47 branchcode
=> $branchcode,
48 categorycode
=> $categorycode
52 my $b2 = Koha
::Borrower
->new(
55 branchcode
=> $branchcode,
56 categorycode
=> $categorycode
60 my $b3 = Koha
::Borrower
->new(
63 branchcode
=> $branchcode,
64 categorycode
=> $categorycode
69 my $b1_new = Koha
::Borrowers
->find( $b1->borrowernumber() );
70 is
( $b1->surname(), $b1_new->surname(), "Found matching borrower" );
72 my @borrowers = Koha
::Borrowers
->search( { branchcode
=> $branchcode } );
73 is
( @borrowers, 3, "Found 3 borrowers with Search" );
75 my $unexistent = Koha
::Borrowers
->find( '1234567890' );
76 is
( $unexistent, undef, 'Koha::Objects->Find should return undef if the record does not exist' );
78 my $borrowers = Koha
::Borrowers
->search( { branchcode
=> $branchcode } );
79 is
( $borrowers->count( { branchcode
=> $branchcode } ), 3, "Counted 3 borrowers with Count" );
81 my $b = $borrowers->next();
82 is
( $b->surname(), 'Test 1', "Next returns first borrower" );
83 $b = $borrowers->next();
84 is
( $b->surname(), 'Test 2', "Next returns second borrower" );
85 $b = $borrowers->next();
86 is
( $b->surname(), 'Test 3', "Next returns third borrower" );
87 $b = $borrowers->next();
88 is
( $b, undef, "Next returns undef" );
90 # Test Reset and iteration in concert
92 foreach my $b ( $borrowers->as_list() ) {
93 is
( $b->categorycode(), $categorycode, "Iteration returns a borrower object" );