Bug 29847: Make Koha::Patron::HouseboundProfile->housebound_visits return a resultset

This patch makes the method consistent with the rest of the codebase, by
making it return a proper resultset.

To test:
1. Run:
   $ kshell
  k$ prove t/db_dependent/Patron/HouseboundProfiles.t
=> SUCCESS: Tests pass!
2. Apply this patch
3. Repeat 1
=> SUCCESS: Tests pass!
4. Check the UI hasn't got broken either.
=> SUCCESS: It hasn't!
5. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Tomas Cohen Arazi 2022-02-02 10:35:54 -03:00 committed by Fridolin Somers
parent db0ebb3ab5
commit 9bf19f628a
3 changed files with 47 additions and 45 deletions

View File

@ -42,17 +42,17 @@ Standard Koha::Objects definitions, and additional methods.
=head3 housebound_visits
my $visits = Koha::Patron::HouseboundProfile->housebound_visits;
my $visits = Koha::Patron::HouseboundProfile->housebound_visits;
Returns an arrayref of all visits associated this houseboundProfile.
Returns a I<Koha::Patron::HouseboundVisits> iterator for all the visits
associated this houseboundProfile.
=cut
sub housebound_visits {
my ( $self ) = @_;
my @visits = Koha::Patron::HouseboundVisits
->special_search({ borrowernumber => $self->borrowernumber })->as_list;
return \@visits;
return Koha::Patron::HouseboundVisits
->special_search({ borrowernumber => $self->borrowernumber });
}
=head3 _type

View File

@ -387,7 +387,7 @@
<div>
<h3>Deliveries</h3>
[% housebound_visits = housebound_profile.housebound_visits %]
[% IF housebound_visits.size > 0 %]
[% IF housebound_visits.count > 0 %]
<table border="0" width="100%" cellpadding="3" cellspacing="0">
<tr>
<th>ID</th><th>Date</th><th>Chooser</th><th>Deliverer</th><th class="noExport">Actions</th>

View File

@ -17,58 +17,60 @@
use Modern::Perl;
use Test::More tests => 3;
use Test::More tests => 1;
use Koha::Database;
use Koha::Patron::HouseboundProfiles;
use t::lib::TestBuilder;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
my $schema = Koha::Database->new->schema;
my $builder = t::lib::TestBuilder->new;
# Profile Tests
subtest 'housebound_visits() tests' => sub {
my $profile = $builder->build({ source => 'HouseboundProfile' });
plan tests => 3;
is(
Koha::Patron::HouseboundProfiles
->find($profile->{borrowernumber})->borrowernumber,
$profile->{borrowernumber},
"Find created profile."
);
$schema->storage->txn_begin;
my @profiles = Koha::Patron::HouseboundProfiles
->search({ day => $profile->{day} })->as_list;
my $found_profile = shift @profiles;
is(
$found_profile->borrowernumber,
$profile->{borrowernumber},
"Search for created profile."
);
my $profile = $builder->build({ source => 'HouseboundProfile' });
# ->housebound_profile Tests
is(
Koha::Patron::HouseboundProfiles
->find($profile->{borrowernumber})->borrowernumber,
$profile->{borrowernumber},
"Find created profile."
);
my $visit1 = $builder->build({
source => 'HouseboundVisit',
value => {
borrowernumber => $profile->{borrowernumber},
},
});
my $visit2 = $builder->build({
source => 'HouseboundVisit',
value => {
borrowernumber => $profile->{borrowernumber},
},
});
my @profiles = Koha::Patron::HouseboundProfiles
->search({ day => $profile->{day} })->as_list;
my $found_profile = shift @profiles;
is(
$found_profile->borrowernumber,
$profile->{borrowernumber},
"Search for created profile."
);
is(
scalar @{$found_profile->housebound_visits},
2,
"Fetch housebound_visits."
);
# ->housebound_profile Tests
$schema->storage->txn_rollback;
my $visit1 = $builder->build({
source => 'HouseboundVisit',
value => {
borrowernumber => $profile->{borrowernumber},
},
});
my $visit2 = $builder->build({
source => 'HouseboundVisit',
value => {
borrowernumber => $profile->{borrowernumber},
},
});
is(
$found_profile->housebound_visits->count,
2,
"Fetch housebound_visits."
);
$schema->storage->txn_rollback;
};