|
Line 0
Link Here
|
| 0 |
- |
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::Context; |
| 30 |
use Koha::Database; |
| 31 |
use C4::Serials; |
| 32 |
|
| 33 |
my $schema = Koha::Database->new->schema; |
| 34 |
$schema->storage->txn_begin; |
| 35 |
|
| 36 |
my $builder = t::lib::TestBuilder->new(); |
| 37 |
#my $library = $builder->build({ |
| 38 |
# source => 'Subscription', |
| 39 |
#}); |
| 40 |
|
| 41 |
#my $mContext = new Test::MockModule('C4::Context'); |
| 42 |
#$mContext->mock( 'userenv', sub { |
| 43 |
# return { branch => $library->{branchcode} }; |
| 44 |
#}); |
| 45 |
|
| 46 |
|
| 47 |
#my $dbh = C4::Context->dbh; # after start transaction of testbuilder |
| 48 |
|
| 49 |
# create fake numberpattern & fake periodicity |
| 50 |
my $frequency = $builder->build({ |
| 51 |
source => 'SubscriptionFrequency', |
| 52 |
value => { |
| 53 |
description => "daily", |
| 54 |
unit => "day", |
| 55 |
unitsperissue => 1, |
| 56 |
}, |
| 57 |
}); |
| 58 |
|
| 59 |
my $pattern = $builder->build({ |
| 60 |
source => 'SubscriptionNumberpattern', |
| 61 |
value => { |
| 62 |
label => 'mock', |
| 63 |
description =>'mock', |
| 64 |
numberingmethod => 'Issue {X}', |
| 65 |
add1 => 1, |
| 66 |
every1 => 1, |
| 67 |
setto1 => 100, |
| 68 |
} |
| 69 |
}); |
| 70 |
|
| 71 |
# Create fake subscription, daily subscription, duration 12 months, issues startint at #100 |
| 72 |
my $subscription = $builder->build({ |
| 73 |
source => 'Subscription', |
| 74 |
value => { |
| 75 |
biblionumber => 1, |
| 76 |
startdate => '2015-01-01', |
| 77 |
enddate => '2015-12-31', |
| 78 |
aqbooksellerid => 1, |
| 79 |
periodicity => $frequency->{id}, |
| 80 |
numberpattern => $pattern->{id}, |
| 81 |
monthlength => 12, |
| 82 |
}, |
| 83 |
}); |
| 84 |
|
| 85 |
my $subscriptionhistory = $builder->build({ |
| 86 |
source => 'Subscriptionhistory', |
| 87 |
value => { |
| 88 |
subscriptionid => $subscription->{subscriptionid}, |
| 89 |
histenddate => undef, |
| 90 |
opacnote => 'Testing', |
| 91 |
} |
| 92 |
}); |
| 93 |
|
| 94 |
# Actual testing starts here! |
| 95 |
|
| 96 |
# Renew the subscription and check that enddate has not been set |
| 97 |
ReNewSubscription($subscription->{subscriptionid},'',"2016-01-01",'','',12,''); |
| 98 |
my @history = Koha::Subscription::Histories->search( {subscriptionid => $subscription->{subscriptionid} } ); |
| 99 |
|
| 100 |
is ( $history[0]->histenddate(), undef, 'subscription history not empty after renewal'); |
| 101 |
|
| 102 |
# End of tests |
| 103 |
|
| 104 |
$schema->storage->txn_rollback; |
| 105 |
|
| 106 |
1; |