Bug 13019: [QA Follow-up] Rename new_from_dbic and few typos
[koha.git] / t / Borrower.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
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.
9 #
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.
14 #
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>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 13;
21 use Test::Warn;
22
23 use Koha::Database;
24
25 BEGIN {
26     use_ok('Koha::Object');
27     use_ok('Koha::Borrower');
28 }
29
30 my $object = Koha::Borrower->new( { surname => 'Test Borrower' } );
31
32 is( $object->surname(), 'Test Borrower', "Accessor returns correct value" );
33
34 $object->surname('Test Borrower Surname');
35 is( $object->surname(), 'Test Borrower Surname', "Accessor returns correct value after set" );
36
37 my $object2 = Koha::Borrower->new( { surname => 'Test Borrower 2' } );
38 is( $object2->surname(), 'Test Borrower 2', "Accessor returns correct value" );
39
40 $object2->surname('Test Borrower Surname 2');
41 is( $object2->surname(), 'Test Borrower Surname 2', "Accessor returns correct value after set" );
42
43 my $ret;
44 $ret = $object2->set({ surname => "Test Borrower Surname 3", firstname => "Test Firstname" });
45 is( $ret, 1, "Set returns 1 on success" );
46 is( $object2->surname(), "Test Borrower Surname 3", "Set sets first field correctly" );
47 is( $object2->firstname(), "Test Firstname", "Set sets second field correctly" );
48
49 $ret = $object->set({ surname => "Test Borrower Surname 4", bork => "bork" });
50 is( $object2->surname(), "Test Borrower Surname 3", "Bad Set does not set field" );
51 is( $ret, 0, "Set returns 0 when passed a bad property" );
52
53 ok( ! defined $object->bork(), 'Bad getter returns undef' );
54 ok( ! defined $object->bork('bork'), 'Bad setter returns undef' );
55
56 1;