3 # This script includes tests for ReNewSubscription
5 # Copyright 2015 BibLibre, Paul Poulain
6 # Copyright 2018 Catalyst IT, Alex Buckley
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
25 use Test
::More tests
=> 7;
27 use t
::lib
::TestBuilder
;
33 use Koha
::Subscription
::Histories
;
35 my $schema = Koha
::Database
->new->schema;
36 $schema->storage->txn_begin;
38 my $builder = t
::lib
::TestBuilder
->new();
40 # create fake numberpattern & fake periodicity
41 my $frequency = $builder->build({
42 source
=> 'SubscriptionFrequency',
44 description
=> "daily",
50 my $pattern = $builder->build({
51 source
=> 'SubscriptionNumberpattern',
55 numberingmethod
=> 'Issue {X}',
62 my $biblio = $builder->build_sample_biblio();
64 # Create fake subscription, daily subscription, duration 12 months, issues startint at #100
65 my $subscription = $builder->build({
66 source
=> 'Subscription',
68 biblionumber
=> $biblio->biblionumber,
69 startdate
=> '2015-01-01',
70 enddate
=> '2015-12-31',
72 periodicity
=> $frequency->{id
},
73 numberpattern
=> $pattern->{id
},
78 my $subscriptionhistory = $builder->build({
79 source
=> 'Subscriptionhistory',
81 biblionumber
=> $biblio->biblionumber,
82 subscriptionid
=> $subscription->{subscriptionid
},
84 opacnote
=> 'Testing',
88 # Actual testing starts here!
89 # Renew the subscription and check that enddate has not been set
92 subscriptionid
=> $subscription->{subscriptionid
},
93 startdate
=> "2016-01-01",
98 # Calculate the subscription length for the renewal for issues, days and months
99 my ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength
('issues', 7);
100 is
( $numberlength, 7, "Subscription length is 7 issues");
102 ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength
('weeks', 7);
103 is
( $weeklength, 7, "Subscription length is 7 weeks");
105 ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength
('months', 7);
106 is
( $monthlength, 7, "Subscription length is 7 months");
108 # Check subscription length when no value is inputted into the numeric sublength field
109 ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength
('months', '');
110 is
($monthlength, undef, "Subscription length is undef months, invalid month data was not stored");
112 # Check subscription length when a letter is inputted into the numeric sublength field
113 ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength
('issues', 'w');
114 is
($monthlength, undef, "Subscription length is undef issues, invalid issue data was not stored");
116 # Check subscription length when a special character is inputted into numberic sublength field
117 ($numberlength, $weeklength, $monthlength) = GetSubscriptionLength
('weeks', '!');
118 is
($weeklength, undef, "Subscription length is undef weeks, invalid weeks data was not stored");
120 # Renew the subscription and check that enddate has not been set
122 my $history = Koha
::Subscription
::Histories
->find($subscription->{subscriptionid
});
124 is
( $history->histenddate(), undef, 'subscription history not empty after renewal');
128 $schema->storage->txn_rollback;