Bug 13019 - Add base classes on which to build Koha objects
[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 $result = Koha::Database->new()->schema()->resultset('Borrower')->new({ surname => 'Test Borrower' });
31 my $object = Koha::Borrower->new_from_dbic( $result );
32
33 is( $object->surname(), 'Test Borrower', "Accessor returns correct value" );
34
35 $object->surname('Test Borrower Surname');
36 is( $object->surname(), 'Test Borrower Surname', "Accessor returns correct value after set" );
37
38 my $object2 = Koha::Borrower->new( { surname => 'Test Borrower 2' } );
39 is( $object2->surname(), 'Test Borrower 2', "Accessor returns correct value" );
40
41 $object2->surname('Test Borrower Surname 2');
42 is( $object2->surname(), 'Test Borrower Surname 2', "Accessor returns correct value after set" );
43
44 my $ret;
45 $ret = $object2->set({ surname => "Test Borrower Surname 3", firstname => "Test Firstname" });
46 is( $ret, 1, "Set returns 1 on success" );
47 is( $object2->surname(), "Test Borrower Surname 3", "Set sets first field correctly" );
48 is( $object2->firstname(), "Test Firstname", "Set sets second field correctly" );
49
50 $ret = $object->set({ surname => "Test Borrower Surname 4", bork => "bork" });
51 is( $object2->surname(), "Test Borrower Surname 3", "Bad Set does not set field" );
52 is( $ret, 0, "Set returns 0 when passed a bad property" );
53
54 ok( ! defined $object->bork(), 'Bad getter returns undef' );
55 ok( ! defined $object->bork('bork'), 'Bad setter returns undef' );
56
57 1;