From 224463bd1f6dcb826d23349ca28fdb05cea3c746 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Tue, 30 Oct 2018 07:17:12 +0000 Subject: [PATCH] Bug 7046: (follow-up) Tidy up to address test feedback * Removed underscores from start of subroutine * Removed tabs in subscription-renew.tt * Added test for C4/Serials/getsublength() in t/db_dependen/Serials/ReNewSubscription.t * Added missing filters Sponsored-By: Catalyst IT --- C4/Serials.pm | 17 +++++++++-------- .../prog/en/modules/serials/subscription-renew.tt | 8 ++++---- serials/subscription-add.pl | 4 ++-- serials/subscription-renew.pl | 3 ++- t/db_dependent/Serials/ReNewSubscription.t | 17 ++++++++++++++++- 5 files changed, 33 insertions(+), 16 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 9c9a5fbb5a..320b8e78c8 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -74,7 +74,7 @@ BEGIN { &GetNextSeq &GetSeq &NewIssue &GetSerials &GetLatestSerials &ModSerialStatus &GetNextDate &GetSerials2 - &ReNewSubscription &GetLateOrMissingIssues + &getsublength &ReNewSubscription &GetLateOrMissingIssues &GetSerialInformation &AddItem2Serial &PrepareSerialsData &GetNextExpected &ModNextExpected &GetPreviousSerialid @@ -1483,20 +1483,21 @@ sub NewSubscription { return $subscriptionid; } -=head2 _get_sub_length -my ($numberlength, $weeklength, $monthlength) = _get_sub_length( $subtype, $sublength ); +=head2 getsublength -this function calculates the subscription length. +my ($numberlength, $weeklength, $monthlength) = getsublength( $subtype, $sublength ); + +This function calculates the subscription length. =cut -sub _get_sub_length { - my ($type, $subtype, $length) = @_; +sub getsublength { + my ($subtype, $length) = @_; return ( $subtype eq 'issues' ? $length : 0, - $subtype eq 'weeks' ? $length : 0, - $subtype eq 'months' ? $length : 0, + $subtype eq 'weeks' ? $length : 0, + $subtype eq 'months' ? $length : 0, ); } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt index c57c7ac719..d78b6f6ecf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-renew.tt @@ -35,9 +35,9 @@
[% INCLUDE 'date-format.inc' %]
-
  • - Subscription length: - [% FOREACH st IN subtypes %] [% SWITCH st %] [% CASE 'numberlength'%] @@ -61,7 +61,7 @@ [% END %] diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl index 42c90f8e5a..b09e415a56 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -320,7 +320,7 @@ sub redirect_add_subscription { my $subtype = $query->param('subtype'); my $sublength = $query->param('sublength'); my ( $numberlength, $weeklength, $monthlength ) - = C4::Serials->_get_sub_length( $subtype, $sublength ); + = C4::Serials->getsublength( $subtype, $sublength ); my $add1 = $query->param('add1'); my $lastvalue1 = $query->param('lastvalue1'); my $innerloop1 = $query->param('innerloop1'); @@ -433,7 +433,7 @@ sub redirect_mod_subscription { my $subtype = $query->param('subtype'); my $sublength = $query->param('sublength'); - my ($numberlength, $weeklength, $monthlength) = C4::Serials->get_sub_length( $subtype, $sublength ); + my ($numberlength, $weeklength, $monthlength) = C4::Serials->getsublength( $subtype, $sublength ); my $numberpattern = $query->param('numbering_pattern'); my $locale = $query->param('locale'); my $lastvalue1 = $query->param('lastvalue1'); diff --git a/serials/subscription-renew.pl b/serials/subscription-renew.pl index 247aca15b5..b7140b518f 100755 --- a/serials/subscription-renew.pl +++ b/serials/subscription-renew.pl @@ -64,7 +64,7 @@ my @subscriptionids = $query->multi_param('subscriptionid'); my $branchcode = $query->param('branchcode'); my $sublength = $query->param('sublength'); my $subtype = $query->param('subtype'); -my ($numberlength, $weeklength, $monthlength) = C4::Serials->get_sub_length( $subtype, $sublength ); +my ($numberlength, $weeklength, $monthlength) = C4::Serials->getsublength( $subtype, $sublength ); my $done = 0; # for after form has been submitted my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -134,6 +134,7 @@ my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, ); $template->param( op => $op, libraries => $libraries, + subtypes => [ qw( numberlength weeklength monthlength ) ], ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/t/db_dependent/Serials/ReNewSubscription.t b/t/db_dependent/Serials/ReNewSubscription.t index 73affa201c..7e1ca8158d 100644 --- a/t/db_dependent/Serials/ReNewSubscription.t +++ b/t/db_dependent/Serials/ReNewSubscription.t @@ -3,6 +3,7 @@ # This script includes tests for ReNewSubscription # Copyright 2015 BibLibre, Paul Poulain +# Copyright 2018 Catalyst IT, Alex Buckley # # This file is part of Koha. # @@ -21,7 +22,7 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 4; use Test::MockModule; use t::lib::TestBuilder; use t::lib::Mocks; @@ -93,6 +94,20 @@ ReNewSubscription( monthlength => 12 } ); + +# Calculate the subscription length for the renewal for issues, days and months +my ($numberlength, $weeklength, $monthlength) = getsublength('issues', 7); +is ( $numberlength, 7, "Sub length is 7 issues"); + +($numberlength, $weeklength, $monthlength) = getsublength('weeks', 7); +is ( $weeklength, 7, "Sub length is 7 weeks"); + +($numberlength, $weeklength, $monthlength) = getsublength('months', 7); +is ( $monthlength, 7, "Sub length is 7 months"); + +# Renew the subscription and check that enddate has not been set + +ReNewSubscription($subscription->{subscriptionid},'',"2016-01-01",'','',12,''); my $history = Koha::Subscription::Histories->find($subscription->{subscriptionid}); is ( $history->histenddate(), undef, 'subscription history not empty after renewal'); -- 2.11.0