Bug 26384: Fix executable flags
[koha.git] / t / db_dependent / Patron / HouseboundRoles.t
blob7ed46b7dc5a81db48b0f11f313dbff260b9011ec
1 #!/usr/bin/perl
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>.
18 use Modern::Perl;
20 use Test::More tests => 6;
22 use Koha::Database;
23 use Koha::Patron::HouseboundRoles;
24 use Koha::Patrons;
26 use t::lib::TestBuilder;
28 my $schema = Koha::Database->new->schema;
29 $schema->storage->txn_begin;
31 my $builder = t::lib::TestBuilder->new;
33 # Profile Tests
35 my $role = $builder->build({ source => 'HouseboundRole' });
37 is(
38 Koha::Patron::HouseboundRoles
39 ->find($role->{borrowernumber_id})->borrowernumber_id,
40 $role->{borrowernumber_id},
41 "Find created role."
44 my @roles = Koha::Patron::HouseboundRoles
45 ->search({ borrowernumber_id => $role->{borrowernumber_id} });
46 my $found_role = shift @roles;
47 is(
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' });
61 $builder->build({
62 source => 'HouseboundRole',
63 value => {
64 borrowernumber_id => $patron_chooser->{borrowernumber},
65 housebound_chooser => 1,
66 housebound_deliverer => 0,
68 });
70 my $patron_deliverer = $builder->build({ source => 'Borrower' });
71 $builder->build({
72 source => 'HouseboundRole',
73 value => {
74 borrowernumber_id => $patron_deliverer->{borrowernumber},
75 housebound_deliverer => 1,
76 housebound_chooser => 0,
78 });
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;