Bug 26384: Fix executable flags
[koha.git] / t / db_dependent / Serials / ReNewSubscription.t
blobc8e4a60bb49f0042296f22409fda127cb6ac478c
1 #!/usr/bin/perl
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>.
23 use Modern::Perl;
25 use Test::More tests => 7;
26 use Test::MockModule;
27 use t::lib::TestBuilder;
28 use t::lib::Mocks;
30 use C4::Serials;
32 use Koha::Database;
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',
43 value => {
44 description => "daily",
45 unit => "day",
46 unitsperissue => 1,
48 });
50 my $pattern = $builder->build({
51 source => 'SubscriptionNumberpattern',
52 value => {
53 label => 'mock',
54 description =>'mock',
55 numberingmethod => 'Issue {X}',
56 add1 => 1,
57 every1 => 1,
58 setto1 => 100,
60 });
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',
67 value => {
68 biblionumber => $biblio->biblionumber,
69 startdate => '2015-01-01',
70 enddate => '2015-12-31',
71 aqbooksellerid => 1,
72 periodicity => $frequency->{id},
73 numberpattern => $pattern->{id},
74 monthlength => 12,
76 });
78 my $subscriptionhistory = $builder->build({
79 source => 'Subscriptionhistory',
80 value => {
81 biblionumber => $biblio->biblionumber,
82 subscriptionid => $subscription->{subscriptionid},
83 histenddate => undef,
84 opacnote => 'Testing',
86 });
88 # Actual testing starts here!
89 # Renew the subscription and check that enddate has not been set
90 ReNewSubscription(
92 subscriptionid => $subscription->{subscriptionid},
93 startdate => "2016-01-01",
94 monthlength => 12
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');
126 # End of tests
128 $schema->storage->txn_rollback;