From 217da9cf3dd6c10e92397274c61570ef33b50587 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 17 Oct 2022 15:43:22 -0300 Subject: [PATCH] Bug 14783: (QA follow-up) Rename method and move tests Signed-off-by: Tomas Cohen Arazi --- Koha/Hold.pm | 8 +-- .../bootstrap/en/includes/holds-table.inc | 2 +- opac/opac-modrequest.pl | 2 +- t/db_dependent/Hold.t | 52 +------------------ t/db_dependent/Koha/Hold.t | 50 +++++++++++++++++- 5 files changed, 56 insertions(+), 58 deletions(-) diff --git a/Koha/Hold.pm b/Koha/Hold.pm index 232012976a7..378b902638b 100644 --- a/Koha/Hold.pm +++ b/Koha/Hold.pm @@ -906,15 +906,15 @@ sub to_api_mapping { }; } -=head3 can_change_branch_opac +=head3 can_update_pickup_location_opac -returns if a hold can change pickup location from opac + my $can_update_pickup_location_opac = $hold->can_update_pickup_location_opac; -my $can_change_branch_opac = $hold->can_change_branch_opac; +Returns if a hold can change pickup location from opac =cut -sub can_change_branch_opac { +sub can_update_pickup_location_opac { my ($self) = @_; my @statuses = split /,/, C4::Context->preference("OPACAllowUserToChangeBranch"); diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/includes/holds-table.inc b/koha-tmpl/opac-tmpl/bootstrap/en/includes/holds-table.inc index ef08112215f..ab345ca3b2f 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/holds-table.inc +++ b/koha-tmpl/opac-tmpl/bootstrap/en/includes/holds-table.inc @@ -83,7 +83,7 @@ Pickup location: [% HOLD.branch.branchname | html %] - [% IF ( HOLD.can_change_branch_opac ) %] + [% IF ( HOLD.can_update_pickup_location_opac ) %] diff --git a/opac/opac-modrequest.pl b/opac/opac-modrequest.pl index d296591001f..1518a3b72e1 100755 --- a/opac/opac-modrequest.pl +++ b/opac/opac-modrequest.pl @@ -60,7 +60,7 @@ if ( $reserve_id && $borrowernumber ) { } elsif ( $new_pickup_location ) { - if ($hold->can_change_branch_opac){ + if ($hold->can_update_pickup_location_opac) { $hold->set_pickup_location({ library_id => $new_pickup_location }); } else { diff --git a/t/db_dependent/Hold.t b/t/db_dependent/Hold.t index 1cfd5bdeca2..73007c18a08 100755 --- a/t/db_dependent/Hold.t +++ b/t/db_dependent/Hold.t @@ -29,7 +29,7 @@ use Koha::Item; use Koha::DateUtils qw( dt_from_string ); use t::lib::TestBuilder; -use Test::More tests => 36; +use Test::More tests => 35; use Test::Exception; use Test::Warn; @@ -386,53 +386,3 @@ subtest 'suspend() tests' => sub { $schema->storage->txn_rollback; }; - -subtest 'can_change_branch_opac() tests' => sub { - - plan tests => 8; - - $schema->storage->txn_begin; - - my $hold = $builder->build_object( - { class => 'Koha::Holds', - value => { found => undef, suspend => 0, suspend_until => undef, waitingdate => undef } - } - ); - - t::lib::Mocks::mock_preference( 'OPACAllowUserToChangeBranch', '' ); - $hold->found(undef); - is( $hold->can_change_branch_opac, 0, "Pending hold pickup can't be changed (No change allowed)" ); - - $hold->found('T'); - is( $hold->can_change_branch_opac, 0, "In transit hold pickup can't be changed (No change allowed)" ); - - $hold->found('W'); - is( $hold->can_change_branch_opac, 0, "Waiting hold pickup can't be changed (No change allowed)" ); - - $hold->found(undef); - $dt = dt_from_string(); - - $hold->suspend_hold( $dt ); - is( $hold->can_change_branch_opac, 0, "Suspended hold pickup can't be changed (No change allowed)" ); - $hold->resume(); - - t::lib::Mocks::mock_preference( 'OPACAllowUserToChangeBranch', 'pending,intransit,suspended' ); - $hold->found(undef); - is( $hold->can_change_branch_opac, 1, "Pending hold pickup can be changed (pending,intransit,suspended allowed)" ); - - $hold->found('T'); - is( $hold->can_change_branch_opac, 1, "In transit hold pickup can be changed (pending,intransit,suspended allowed)" ); - - $hold->found('W'); - is( $hold->can_change_branch_opac, 0, "Waiting hold pickup can't be changed (pending,intransit,suspended allowed)" ); - - $hold->found(undef); - $dt = dt_from_string(); - $hold->suspend_hold( $dt ); - is( $hold->can_change_branch_opac, 1, "Suspended hold pickup can be changed (pending,intransit,suspended allowed)" ); - $hold->resume(); - - - $schema->storage->txn_rollback; - -}; diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t index 5aeebd073ae..fe59013719e 100755 --- a/t/db_dependent/Koha/Hold.t +++ b/t/db_dependent/Koha/Hold.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 9; +use Test::More tests => 10; use Test::Exception; use Test::MockModule; @@ -29,6 +29,7 @@ use t::lib::TestBuilder; use t::lib::Mocks; use Koha::ActionLogs; +use Koha::DateUtils qw(dt_from_string); use Koha::Holds; use Koha::Libraries; use Koha::Old::Holds; @@ -863,3 +864,50 @@ subtest 'cancellation_requestable_from_opac() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'can_update_pickup_location_opac() tests' => sub { + + plan tests => 8; + + $schema->storage->txn_begin; + + my $hold = $builder->build_object( + { class => 'Koha::Holds', + value => { found => undef, suspend => 0, suspend_until => undef, waitingdate => undef } + } + ); + + t::lib::Mocks::mock_preference( 'OPACAllowUserToChangeBranch', '' ); + $hold->found(undef); + is( $hold->can_update_pickup_location_opac, 0, "Pending hold pickup can't be changed (No change allowed)" ); + + $hold->found('T'); + is( $hold->can_update_pickup_location_opac, 0, "In transit hold pickup can't be changed (No change allowed)" ); + + $hold->found('W'); + is( $hold->can_update_pickup_location_opac, 0, "Waiting hold pickup can't be changed (No change allowed)" ); + + $hold->found(undef); + my $dt = dt_from_string(); + + $hold->suspend_hold( $dt ); + is( $hold->can_update_pickup_location_opac, 0, "Suspended hold pickup can't be changed (No change allowed)" ); + $hold->resume(); + + t::lib::Mocks::mock_preference( 'OPACAllowUserToChangeBranch', 'pending,intransit,suspended' ); + $hold->found(undef); + is( $hold->can_update_pickup_location_opac, 1, "Pending hold pickup can be changed (pending,intransit,suspended allowed)" ); + + $hold->found('T'); + is( $hold->can_update_pickup_location_opac, 1, "In transit hold pickup can be changed (pending,intransit,suspended allowed)" ); + + $hold->found('W'); + is( $hold->can_update_pickup_location_opac, 0, "Waiting hold pickup can't be changed (pending,intransit,suspended allowed)" ); + + $hold->found(undef); + $dt = dt_from_string(); + $hold->suspend_hold( $dt ); + is( $hold->can_update_pickup_location_opac, 1, "Suspended hold pickup can be changed (pending,intransit,suspended allowed)" ); + + $schema->storage->txn_rollback; +}; -- 2.34.1