Bug 7047: (QA follow-up) Fix tests
[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 my $biblio = $builder->build_sample_biblio();
62
63 # Create fake subscription, daily subscription, duration 12 months, issues startint at #100
64 my $subscription = $builder->build({
65     source => 'Subscription',
66     value  => {
67         biblionumber    => $biblio->biblionumber,
68         startdate       => '2015-01-01',
69         enddate         => '2015-12-31',
70         aqbooksellerid  => 1,
71         periodicity     => $frequency->{id},
72         numberpattern   => $pattern->{id},
73         monthlength     => 12,
74     },
75 });
76
77 my $subscriptionhistory = $builder->build({
78     source => 'Subscriptionhistory',
79     value  => {
80         biblionumber   => $biblio->biblionumber,
81         subscriptionid => $subscription->{subscriptionid},
82         histenddate    => undef,
83         opacnote       => 'Testing',
84     }
85 });
86
87 # Actual testing starts here!
88 # Renew the subscription and check that enddate has not been set
89 ReNewSubscription(
90     {
91         subscriptionid => $subscription->{subscriptionid},
92         startdate      => "2016-01-01",
93         monthlength    => 12
94     }
95 );
96 my $history = Koha::Subscription::Histories->find($subscription->{subscriptionid});
97
98 is ( $history->histenddate(), undef, 'subscription history not empty after renewal');
99
100 # End of tests
101
102 $schema->storage->txn_rollback;
103