From 9bf19f628ac444fe29f7817b807c872af894331b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 2 Feb 2022 10:35:54 -0300 Subject: [PATCH] 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 Signed-off-by: Martin Renvoize Signed-off-by: Fridolin Somers --- Koha/Patron/HouseboundProfile.pm | 10 +- .../prog/en/modules/members/housebound.tt | 2 +- t/db_dependent/Patron/HouseboundProfiles.t | 96 ++++++++++--------- 3 files changed, 55 insertions(+), 53 deletions(-) diff --git a/Koha/Patron/HouseboundProfile.pm b/Koha/Patron/HouseboundProfile.pm index 612cb9afce..27427bf535 100644 --- a/Koha/Patron/HouseboundProfile.pm +++ b/Koha/Patron/HouseboundProfile.pm @@ -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 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 diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/housebound.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/housebound.tt index c08564005b..330a55c2b2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/housebound.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/housebound.tt @@ -387,7 +387,7 @@

Deliveries

[% housebound_visits = housebound_profile.housebound_visits %] - [% IF housebound_visits.size > 0 %] + [% IF housebound_visits.count > 0 %] diff --git a/t/db_dependent/Patron/HouseboundProfiles.t b/t/db_dependent/Patron/HouseboundProfiles.t index 88a766fcc2..48e21c94d6 100755 --- a/t/db_dependent/Patron/HouseboundProfiles.t +++ b/t/db_dependent/Patron/HouseboundProfiles.t @@ -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 - -my $profile = $builder->build({ source => 'HouseboundProfile' }); - -is( - Koha::Patron::HouseboundProfiles - ->find($profile->{borrowernumber})->borrowernumber, - $profile->{borrowernumber}, - "Find created profile." -); - -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." -); - -# ->housebound_profile Tests - -my $visit1 = $builder->build({ - source => 'HouseboundVisit', - value => { - borrowernumber => $profile->{borrowernumber}, - }, -}); -my $visit2 = $builder->build({ - source => 'HouseboundVisit', - value => { - borrowernumber => $profile->{borrowernumber}, - }, -}); - -is( - scalar @{$found_profile->housebound_visits}, - 2, - "Fetch housebound_visits." -); - -$schema->storage->txn_rollback; - +subtest 'housebound_visits() tests' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + my $profile = $builder->build({ source => 'HouseboundProfile' }); + + is( + Koha::Patron::HouseboundProfiles + ->find($profile->{borrowernumber})->borrowernumber, + $profile->{borrowernumber}, + "Find created profile." + ); + + 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." + ); + + # ->housebound_profile Tests + + 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; +}; -- 2.39.5
IDDateChooserDelivererActions