Bug 13069 - (follow-up) Enable sort by title to ignore articles
[koha.git] / t / db_dependent / 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 C4::Context;
24 use Koha::Database;
25
26 BEGIN {
27     use_ok('Koha::Object');
28     use_ok('Koha::Borrower');
29 }
30
31 # Start transaction
32 my $dbh = C4::Context->dbh;
33 $dbh->{AutoCommit} = 0;
34 $dbh->{RaiseError} = 1;
35
36 my $categorycode = Koha::Database->new()->schema()->resultset('Category')->first()->categorycode();
37 my $branchcode = Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode();
38
39 my $object = Koha::Borrower->new();
40
41 is( $object->in_storage, 0, "Object is not in storage" );
42
43 $object->categorycode( $categorycode );
44 $object->branchcode( $branchcode );
45 $object->surname("Test Surname");
46 $object->store();
47
48 is( $object->in_storage, 1, "Object is now stored" );
49
50 my $borrowernumber = $object->borrowernumber;
51
52 my $borrower = Koha::Database->new()->schema()->resultset('Borrower')->find( $borrowernumber );
53 is( $borrower->surname(), "Test Surname", "Object found in database" );
54
55 is( $object->is_changed(), 0, "Object is unchanged" );
56 $object->surname("Test Surname");
57 is( $object->is_changed(), 0, "Object is still unchanged" );
58 $object->surname("Test Surname 2");
59 is( $object->is_changed(), 1, "Object is changed" );
60
61 $object->store();
62 is( $object->is_changed(), 0, "Object no longer marked as changed after being stored" );
63
64 $object->set({ firstname => 'Test Firstname' });
65 is( $object->is_changed(), 1, "Object is changed after Set" );
66 $object->store();
67 is( $object->is_changed(), 0, "Object no longer marked as changed after being stored" );
68
69 $object->delete();
70 $borrower = Koha::Database->new()->schema()->resultset('Borrower')->find( $borrowernumber );
71 ok( ! $borrower, "Object no longer found in database" );
72 is( $object->in_storage, 0, "Object is not in storage" );
73
74 1;