Bug 26384: Fix executable flags
[koha.git] / t / db_dependent / Patron / HouseboundRoles.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 => 6;
21
22 use Koha::Database;
23 use Koha::Patron::HouseboundRoles;
24 use Koha::Patrons;
25
26 use t::lib::TestBuilder;
27
28 my $schema = Koha::Database->new->schema;
29 $schema->storage->txn_begin;
30
31 my $builder = t::lib::TestBuilder->new;
32
33 # Profile Tests
34
35 my $role = $builder->build({ source => 'HouseboundRole' });
36
37 is(
38     Koha::Patron::HouseboundRoles
39           ->find($role->{borrowernumber_id})->borrowernumber_id,
40     $role->{borrowernumber_id},
41     "Find created role."
42 );
43
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."
51 );
52
53 # patron_choosers and patron_deliverers Tests
54
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;
58
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,
67     },
68 });
69
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,
77     },
78 });
79
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");
83
84 isa_ok(Koha::Patrons->search_housebound_choosers->next, "Koha::Patron");
85 isa_ok(Koha::Patrons->search_housebound_deliverers->next, "Koha::Patron");
86
87
88 $schema->storage->txn_rollback;
89