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>.
20 use Test::More tests => 8;
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' });
38 Koha::Patron::HouseboundVisits
39 ->find($visit->{id})->id,
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;
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;
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;
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} );
85 local $TODO = "We want our results here to be Koha::Patron objects, but they by default return DBIC Schema objects. The currently accepted solution to this (use the _from_dbic method), is defined for Koha::Objects, but not for Koha::Object. We do not resolve this issue here";
86 isa_ok( $result->deliverer, "Koha::Patron");
87 isa_ok( $result->chooser, "Koha::Patron");
90 $schema->storage->txn_rollback;