48e21c94d629a325ab40597bf476c4a5d7d38b1e
[koha.git] / t / db_dependent / Patron / HouseboundProfiles.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 => 1;
21
22 use Koha::Database;
23 use Koha::Patron::HouseboundProfiles;
24
25 use t::lib::TestBuilder;
26
27 my $schema  = Koha::Database->new->schema;
28 my $builder = t::lib::TestBuilder->new;
29
30 subtest 'housebound_visits() tests' => sub {
31
32     plan tests => 3;
33
34     $schema->storage->txn_begin;
35
36     my $profile = $builder->build({ source => 'HouseboundProfile' });
37
38     is(
39         Koha::Patron::HouseboundProfiles
40             ->find($profile->{borrowernumber})->borrowernumber,
41         $profile->{borrowernumber},
42         "Find created profile."
43     );
44
45     my @profiles = Koha::Patron::HouseboundProfiles
46         ->search({ day => $profile->{day} })->as_list;
47     my $found_profile = shift @profiles;
48     is(
49         $found_profile->borrowernumber,
50         $profile->{borrowernumber},
51         "Search for created profile."
52     );
53
54     # ->housebound_profile Tests
55
56     my $visit1 = $builder->build({
57         source => 'HouseboundVisit',
58         value  => {
59             borrowernumber => $profile->{borrowernumber},
60         },
61     });
62     my $visit2 = $builder->build({
63         source => 'HouseboundVisit',
64         value  => {
65             borrowernumber => $profile->{borrowernumber},
66         },
67     });
68
69     is(
70         $found_profile->housebound_visits->count,
71         2,
72         "Fetch housebound_visits."
73     );
74
75     $schema->storage->txn_rollback;
76 };