Bug 15072: (followup) fix spaces and consistency
[koha.git] / t / db_dependent / Borrowers.t
blob50d9c3201b23d6d98e1a80b329642812be36f1e7
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 => 13;
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 $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
91 $borrowers->reset();
92 foreach my $b ( $borrowers->as_list() ) {
93 is( $b->categorycode(), $categorycode, "Iteration returns a borrower object" );