Bug 14285: Bengali locale needs to be re-defined
[koha.git] / t / db_dependent / Borrowers.t
blobbd75551dfcd5c7e48901fd7733ba6a53ba22499d
1 #!/usr/bin/perl
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>.
18 use Modern::Perl;
20 use Test::More tests => 12;
21 use Test::Warn;
23 use C4::Context;
24 use Koha::Database;
26 BEGIN {
27 use_ok('Koha::Objects');
28 use_ok('Koha::Borrowers');
31 # Start transaction
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");
38 my $categorycode =
39 Koha::Database->new()->schema()->resultset('Category')->first()
40 ->categorycode();
41 my $branchcode =
42 Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode();
44 my $b1 = Koha::Borrower->new(
46 surname => 'Test 1',
47 branchcode => $branchcode,
48 categorycode => $categorycode
51 $b1->store();
52 my $b2 = Koha::Borrower->new(
54 surname => 'Test 2',
55 branchcode => $branchcode,
56 categorycode => $categorycode
59 $b2->store();
60 my $b3 = Koha::Borrower->new(
62 surname => 'Test 3',
63 branchcode => $branchcode,
64 categorycode => $categorycode
67 $b3->store();
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 $borrowers = Koha::Borrowers->search( { branchcode => $branchcode } );
76 is( $borrowers->count( { branchcode => $branchcode } ), 3, "Counted 3 borrowers with Count" );
78 my $b = $borrowers->next();
79 is( $b->surname(), 'Test 1', "Next returns first borrower" );
80 $b = $borrowers->next();
81 is( $b->surname(), 'Test 2', "Next returns second borrower" );
82 $b = $borrowers->next();
83 is( $b->surname(), 'Test 3', "Next returns third borrower" );
84 $b = $borrowers->next();
85 is( $b, undef, "Next returns undef" );
87 # Test Reset and iteration in concert
88 $borrowers->reset();
89 foreach my $b ( $borrowers->as_list() ) {
90 is( $b->categorycode(), $categorycode, "Iteration returns a borrower object" );