Bug 29744: (QA follow-up) Only consider PLACK_ENV for underscore
[koha.git] / t / db_dependent / Patron / HouseboundVisits.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 => 8;
21
22 use Koha::Database;
23 use Koha::Patron::HouseboundVisits;
24 use Koha::Patron::HouseboundVisit;
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 ########### Test HouseboundVisits
34
35 my $visit = $builder->build({ source => 'HouseboundVisit' });
36
37 is(
38     Koha::Patron::HouseboundVisits
39           ->find($visit->{id})->id,
40     $visit->{id},
41     "Find created visit."
42 );
43
44 # Using our Prefetching search
45
46 # Does it work implicitly?
47 my @visits = Koha::Patron::HouseboundVisits
48     ->special_search({ borrowernumber => $visit->{borrowernumber} })->as_list;
49 my $found_visit = shift @visits;
50 is(
51     $found_visit->borrowernumber,
52     $visit->{borrowernumber},
53     "Search for created visit."
54 );
55
56 # Does it work Explicitly?
57 @visits = Koha::Patron::HouseboundVisits
58     ->special_search({ 'me.borrowernumber' => $visit->{borrowernumber} })->as_list;
59 $found_visit = shift @visits;
60 is(
61     $found_visit->borrowernumber,
62     $visit->{borrowernumber},
63     "Search for created visit."
64 );
65
66 # Does it work without prefetcing?
67 @visits = Koha::Patron::HouseboundVisits
68     ->special_search({ borrowernumber => $visit->{borrowernumber} }, { prefetch => [] })->as_list;
69 $found_visit = shift @visits;
70 is(
71     $found_visit->borrowernumber,
72     $visit->{borrowernumber},
73     "Search for created visit."
74 );
75
76 ########### Test HouseboundVisit
77
78 my $result = Koha::Patron::HouseboundVisits->find($visit->{id});
79
80 is( $result->deliverer->borrowernumber, $visit->{deliverer_brwnumber} );
81
82 is( $result->chooser->borrowernumber, $visit->{chooser_brwnumber} );
83
84 isa_ok( $result->deliverer, "Koha::Patron");
85 isa_ok( $result->chooser, "Koha::Patron");
86
87 $schema->storage->txn_rollback;
88