Bug 5670: [Followup] Return Koha::Patron objects.
[koha.git] / t / db_dependent / Patron / HouseboundVisits.t
blobe6f8245ee29e35ef158f32fe702edc4701a3dfbd
1 #!/usr/bin/perl
3 # This file is part of Koha.
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.
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.
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>.
18 use Modern::Perl;
20 use Test::More tests => 8;
22 use Koha::Database;
23 use Koha::Patron::HouseboundVisits;
24 use Koha::Patron::HouseboundVisit;
26 use t::lib::TestBuilder;
28 my $schema = Koha::Database->new->schema;
29 $schema->storage->txn_begin;
31 my $builder = t::lib::TestBuilder->new;
33 ########### Test HouseboundVisits
35 my $visit = $builder->build({ source => 'HouseboundVisit' });
37 is(
38 Koha::Patron::HouseboundVisits
39 ->find($visit->{id})->id,
40 $visit->{id},
41 "Find created visit."
44 # Using our Prefetching search
46 # Does it work implicitly?
47 my @visits = Koha::Patron::HouseboundVisits
48 ->special_search({ borrowernumber => $visit->{borrowernumber} });
49 my $found_visit = shift @visits;
50 is(
51 $found_visit->borrowernumber,
52 $visit->{borrowernumber},
53 "Search for created visit."
56 # Does it work Explicitly?
57 @visits = Koha::Patron::HouseboundVisits
58 ->special_search({ 'me.borrowernumber' => $visit->{borrowernumber} });
59 $found_visit = shift @visits;
60 is(
61 $found_visit->borrowernumber,
62 $visit->{borrowernumber},
63 "Search for created visit."
66 # Does it work without prefetcing?
67 @visits = Koha::Patron::HouseboundVisits
68 ->special_search({ borrowernumber => $visit->{borrowernumber} }, { prefetch => [] });
69 $found_visit = shift @visits;
70 is(
71 $found_visit->borrowernumber,
72 $visit->{borrowernumber},
73 "Search for created visit."
76 ########### Test HouseboundVisit
78 my $result = Koha::Patron::HouseboundVisits->find($visit->{id});
80 is( $result->deliverer->borrowernumber, $visit->{deliverer_brwnumber} );
82 is( $result->chooser->borrowernumber, $visit->{chooser_brwnumber} );
84 isa_ok( $result->deliverer, "Koha::Patron");
85 isa_ok( $result->chooser, "Koha::Patron");
87 $schema->storage->txn_rollback;