Bug 14783: (QA follow-up) Rename method and move tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 17 Oct 2022 18:43:22 +0000 (15:43 -0300)
committerTomas Cohen Arazi <tomascohen@theke.io>
Mon, 17 Oct 2022 18:43:22 +0000 (15:43 -0300)
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/Hold.pm
koha-tmpl/opac-tmpl/bootstrap/en/includes/holds-table.inc
opac/opac-modrequest.pl
t/db_dependent/Hold.t
t/db_dependent/Koha/Hold.t

index 2320129..378b902 100644 (file)
@@ -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");
index ef08112..ab345ca 100644 (file)
@@ -83,7 +83,7 @@
                             <td class="branch">
                                 <span class="tdlabel">Pickup location:</span>
                                 [% HOLD.branch.branchname | html %]
-                                [% IF ( HOLD.can_change_branch_opac ) %]
+                                [% IF ( HOLD.can_update_pickup_location_opac ) %]
                                     <button type="button" class="btn btn-sm btn-link" data-toggle="modal" data-target="#changePickup[% HOLD.reserve_id | html %]">
                                         <i class="fa fa-pencil" aria-hidden="true"></i> Change
                                     </button>
index d296591..1518a3b 100755 (executable)
@@ -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 {
index 1cfd5bd..73007c1 100755 (executable)
@@ -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;
-
-};
index 5aeebd0..fe59013 100755 (executable)
@@ -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;
+};