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>.
20 use Test::More tests => 6;
27 use_ok('Koha::Object');
28 use_ok('Koha::Patron');
31 my $schema = Koha::Database->new->schema;
32 $schema->storage->txn_begin;
34 my $categorycode = $schema->resultset('Category')->first()->categorycode();
35 my $branchcode = $schema->resultset('Branch')->first()->branchcode();
37 subtest 'is_changed' => sub {
39 my $object = Koha::Patron->new();
40 $object->categorycode( $categorycode );
41 $object->branchcode( $branchcode );
42 $object->surname("Test Surname");
44 is( $object->is_changed(), 0, "Object is unchanged" );
45 $object->surname("Test Surname");
46 is( $object->is_changed(), 0, "Object is still unchanged" );
47 $object->surname("Test Surname 2");
48 is( $object->is_changed(), 1, "Object is changed" );
51 is( $object->is_changed(), 0, "Object no longer marked as changed after being stored" );
53 $object->set({ firstname => 'Test Firstname' });
54 is( $object->is_changed(), 1, "Object is changed after Set" );
56 is( $object->is_changed(), 0, "Object no longer marked as changed after being stored" );
59 subtest 'in_storage' => sub {
61 my $object = Koha::Patron->new();
62 is( $object->in_storage, 0, "Object is not in storage" );
63 $object->categorycode( $categorycode );
64 $object->branchcode( $branchcode );
65 $object->surname("Test Surname");
67 is( $object->in_storage, 1, "Object is now stored" );
68 $object->surname("another surname");
69 is( $object->in_storage, 1 );
71 my $borrowernumber = $object->borrowernumber;
72 my $patron = $schema->resultset('Borrower')->find( $borrowernumber );
73 is( $patron->surname(), "Test Surname", "Object found in database" );
76 $patron = $schema->resultset('Borrower')->find( $borrowernumber );
77 ok( ! $patron, "Object no longer found in database" );
78 is( $object->in_storage, 0, "Object is not in storage" );
83 my $patron = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode })->store;
84 is( $patron->id, $patron->borrowernumber );
87 subtest 'get_column' => sub {
89 my $patron = Koha::Patron->new({categorycode => $categorycode, branchcode => $branchcode })->store;
90 is( $patron->get_column('borrowernumber'), $patron->borrowernumber, 'get_column should retrieve the correct value' );