Bug 11934 - Replace given by if-else statements
authorNicolas Legrand <nicolas.legrand@bulac.fr>
Thu, 13 Mar 2014 09:40:27 +0000 (10:40 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Fri, 13 Jun 2014 12:43:16 +0000 (08:43 -0400)
To test:

[1] Verify that prove -v t/db_dependent/Circulation_issuingrules.t
    passes.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
replaces given-when with if-elsif-else constructs.
Tests still pass and code looks good.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 12df62ca33047df0c5cd372bf5574cf131f773e0)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit e4c1de744b6fa0765aa3f308dba7234f71da71e9)

t/db_dependent/Circulation_issuingrules.t

index 1b9f3fd..6c4444b 100644 (file)
@@ -61,13 +61,17 @@ is_deeply($loanlength, $default, 'none matches');
 
 #Set syspref ReturnBeforeExpiry = 1 and useDaysMode = 'Days'
 $contextmodule->mock('preference', sub {
-    my ($self, $syspref) = @_;
-    given ( $syspref ) {
-        when ("ReturnBeforeExpiry"){ return 1; }
-        when ("useDaysMode"){ return 'Days'; }
-        default{ return; }
-    }
-});
+                        my ($self, $syspref) = @_;
+                        if ( $syspref eq "ReturnBeforeExpiry") {
+                            return 1;
+                        }
+                        elsif ( $syspref eq "useDaysMode") {
+                            return 'Days';
+                        }
+                        else {
+                            return;
+                        }
+                    });
 
 my $dateexpiry = '2013-01-01';
 
@@ -76,20 +80,23 @@ my $start_date = DateTime->new({year => 2013, month => 2, day => 9});
 $dbh->{mock_add_resultset} = $mock_loan_length;
 my $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
 is($date, $dateexpiry . 'T23:59:00', 'date expiry');
-
 $dbh->{mock_add_resultset} = $mock_loan_length;
 $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
 
 
 #Set syspref ReturnBeforeExpiry = 1 and useDaysMode != 'Days'
 $contextmodule->mock('preference', sub {
-    my ($self, $syspref) = @_;
-    given ( $syspref ) {
-        when ("ReturnBeforeExpiry"){ return 1; }
-        when ("useDaysMode"){ return 'noDays'; }
-        default{ return; }
-    }
-});
+                        my ($self, $syspref) = @_;
+                        if ( $syspref eq "ReturnBeforeExpiry") {
+                            return 1;
+                        }
+                        elsif ($syspref eq "useDaysMode") {
+                            return 'noDays';
+                        }
+                        else {
+                            return;
+                        }
+                    });
 
 $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
 $start_date = DateTime->new({year => 2013, month => 2, day => 9});
@@ -103,13 +110,17 @@ $date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borr
 
 #Set syspref ReturnBeforeExpiry = 0 and useDaysMode = 'Days'
 $contextmodule->mock('preference', sub {
-    my ($self, $syspref) = @_;
-    given ( $syspref ) {
-        when ("ReturnBeforeExpiry"){ return 0; }
-        when ("useDaysMode"){ return 'Days'; }
-        default{ return; }
-    }
-});
+                        my ($self, $syspref) = @_;
+                        if ( $syspref eq "ReturnBeforeExpiry") {
+                            return 0;
+                        }
+                        elsif ( $syspref eq "useDaysMode") {
+                            return 'Days';
+                        }
+                        else {
+                            return;
+                        }
+                    });
 
 $borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
 $start_date = DateTime->new({year => 2013, month => 2, day => 9});