Line 0
Link Here
|
0 |
- |
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 |
}, |
67 |
}); |
68 |
|
69 |
my $patron_deliverer = $builder->build({ source => 'Borrower' }); |
70 |
$builder->build({ |
71 |
source => 'HouseboundRole', |
72 |
value => { |
73 |
borrowernumber_id => $patron_deliverer->{borrowernumber}, |
74 |
housebound_deliverer => 1, |
75 |
}, |
76 |
}); |
77 |
|
78 |
# Test search_housebound_choosers |
79 |
is(Koha::Patrons->search_housebound_choosers->count, $orig_cho_count + 1, "Correct count of choosers."); |
80 |
is(Koha::Patrons->search_housebound_deliverers->count, $orig_del_count + 1, "Correct count of deliverers"); |
81 |
|
82 |
isa_ok(Koha::Patrons->search_housebound_choosers->next, "Koha::Patron"); |
83 |
isa_ok(Koha::Patrons->search_housebound_deliverers->next, "Koha::Patron"); |
84 |
|
85 |
|
86 |
$schema->storage->txn_rollback; |
87 |
|
88 |
1; |