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;
23 use Koha
::Patron
::HouseboundRoles
;
26 use t
::lib
::TestBuilder
;
28 my $schema = Koha
::Database
->new->schema;
29 $schema->storage->txn_begin;
31 my $builder = t
::lib
::TestBuilder
->new;
35 my $role = $builder->build({ source
=> 'HouseboundRole' });
38 Koha
::Patron
::HouseboundRoles
39 ->find($role->{borrowernumber_id
})->borrowernumber_id,
40 $role->{borrowernumber_id
},
44 my @roles = Koha
::Patron
::HouseboundRoles
45 ->search({ borrowernumber_id
=> $role->{borrowernumber_id
} });
46 my $found_role = shift @roles;
48 $found_role->borrowernumber_id,
49 $role->{borrowernumber_id
},
50 "Search for created role."
53 # patron_choosers and patron_deliverers Tests
55 # Current Patron Chooser / Deliverer count
56 my $orig_del_count = Koha
::Patrons
->search_housebound_deliverers->count;
57 my $orig_cho_count = Koha
::Patrons
->search_housebound_choosers->count;
59 # We add one, just in case the above is 0, so we're guaranteed one of each.
60 my $patron_chooser = $builder->build({ source
=> 'Borrower' });
62 source
=> 'HouseboundRole',
64 borrowernumber_id
=> $patron_chooser->{borrowernumber
},
65 housebound_chooser
=> 1,
66 housebound_deliverer
=> 0,
70 my $patron_deliverer = $builder->build({ source
=> 'Borrower' });
72 source
=> 'HouseboundRole',
74 borrowernumber_id
=> $patron_deliverer->{borrowernumber
},
75 housebound_deliverer
=> 1,
76 housebound_chooser
=> 0,
80 # Test search_housebound_choosers
81 is
(Koha
::Patrons
->search_housebound_choosers->count, $orig_cho_count + 1, "Correct count of choosers.");
82 is
(Koha
::Patrons
->search_housebound_deliverers->count, $orig_del_count + 1, "Correct count of deliverers");
84 isa_ok
(Koha
::Patrons
->search_housebound_choosers->next, "Koha::Patron");
85 isa_ok
(Koha
::Patrons
->search_housebound_deliverers->next, "Koha::Patron");
88 $schema->storage->txn_rollback;