Bug 7728: QA fixes
[koha.git] / t / db_dependent / Serials / ReNewSubscription.t
1 #!/usr/bin/perl
2
3 # This script includes tests for ReNewSubscription
4
5 # Copyright 2015 BibLibre, Paul Poulain
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21
22 use Modern::Perl;
23
24 use Test::More tests => 1;
25 use Test::MockModule;
26 use t::lib::TestBuilder;
27 use t::lib::Mocks;
28
29 use C4::Serials;
30
31 use Koha::Database;
32 use Koha::Subscription::Histories;
33
34 my $schema = Koha::Database->new->schema;
35 $schema->storage->txn_begin;
36
37 my $builder = t::lib::TestBuilder->new();
38
39 # create fake numberpattern & fake periodicity
40 my $frequency = $builder->build({
41     source => 'SubscriptionFrequency',
42     value => {
43         description   => "daily",
44         unit          => "day",
45         unitsperissue => 1,
46     },
47 });
48
49 my $pattern = $builder->build({
50     source => 'SubscriptionNumberpattern',
51     value => {
52         label           => 'mock',
53         description     =>'mock',
54         numberingmethod => 'Issue {X}',
55         add1            => 1,
56         every1          => 1,
57         setto1          => 100,
58     }
59 });
60
61 # Create fake subscription, daily subscription, duration 12 months, issues startint at #100
62 my $subscription = $builder->build({
63     source => 'Subscription',
64     value  => {
65         biblionumber    => 1,
66         startdate       => '2015-01-01',
67         enddate         => '2015-12-31',
68         aqbooksellerid  => 1,
69         periodicity     => $frequency->{id},
70         numberpattern   => $pattern->{id},
71         monthlength     => 12,
72     },
73 });
74
75 my $subscriptionhistory = $builder->build({
76     source => 'Subscriptionhistory',
77     value  => {
78         subscriptionid => $subscription->{subscriptionid},
79         histenddate    => undef,
80         opacnote       => 'Testing',
81     }
82 });
83
84 # Actual testing starts here!
85
86 # Renew the subscription and check that enddate has not been set
87 ReNewSubscription($subscription->{subscriptionid},'',"2016-01-01",'','',12,'');
88 my @history = Koha::Subscription::Histories->find($subscription->{subscriptionid});
89
90 is ( $history[0]->histenddate(), undef, 'subscription history not empty after renewal');
91
92 # End of tests
93
94 $schema->storage->txn_rollback;
95
96 1;