Bug 5670: Housebound Readers Module
[koha_ffzg] / t / db_dependent / Patron / Housebound.t
1 #!/usr/bin/perl
2 use Modern::Perl;
3
4 use C4::Members;
5 use C4::Circulation;
6 use Koha::Database;
7 use Koha::Patrons;
8
9 use Test::More tests => 6;
10
11 use_ok('Koha::Patron');
12
13 use t::lib::TestBuilder;
14 use t::lib::Mocks;
15
16 my $schema = Koha::Database->new->schema;
17 $schema->storage->txn_begin;
18
19 my $builder = t::lib::TestBuilder->new;
20
21 my $patron = $builder->build({ source => 'Borrower' });
22 my $profile = $builder->build({
23     source => 'HouseboundProfile',
24     value  => {
25         borrowernumber => $patron->{borrowernumber},
26     },
27 });
28
29 # Test housebound_profile
30 is(
31     Koha::Patrons->find($patron->{borrowernumber})
32           ->housebound_profile->frequency,
33     $profile->{frequency},
34     "Fetch housebound_profile."
35 );
36
37 # patron_choosers and patron_deliverers Tests
38
39 # Current Patron Chooser / Deliverer count
40 my $orig_del_count = Koha::Patrons->housebound_deliverers->count;
41 my $orig_cho_count = Koha::Patrons->housebound_choosers->count;
42
43 # We add one, just in case the above is 0, so we're guaranteed one of each.
44 my $patron_chooser = $builder->build({ source => 'Borrower' });
45 $builder->build({
46     source => 'BorrowerAttribute',
47     value  => {
48         borrowernumber => $patron_chooser->{borrowernumber},
49         code           => 'HSBND',
50         attribute      => 'CHO',
51         password       => undef,
52     },
53 });
54
55 my $patron_deliverer = $builder->build({ source => 'Borrower' });
56 $builder->build({
57     source => 'BorrowerAttribute',
58     value  => {
59         borrowernumber => $patron_deliverer->{borrowernumber},
60         code           => 'HSBND',
61         attribute      => 'DEL',
62         password       => undef,
63     },
64 });
65
66 # Test housebound_choosers
67 is(Koha::Patrons->housebound_choosers->count, $orig_cho_count + 1, "Correct count of choosers.");
68 is(Koha::Patrons->housebound_deliverers->count, $orig_del_count + 1, "Correct count of deliverers");
69
70 isa_ok(Koha::Patrons->housebound_choosers->next, "Koha::Patron");
71 isa_ok(Koha::Patrons->housebound_deliverers->next, "Koha::Patron");
72
73 $schema->storage->txn_rollback;
74
75 1;