|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# This file is part of Koha |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WIT HOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
|
| 20 |
use Test::More tests => 15; |
| 21 |
use t::lib::TestBuilder; |
| 22 |
|
| 23 |
use Koha::Database; |
| 24 |
use Koha::Subscriptions; |
| 25 |
|
| 26 |
BEGIN { |
| 27 |
use_ok('Koha::Subscriptions'); |
| 28 |
} |
| 29 |
|
| 30 |
my $schema = Koha::Database->new->schema; |
| 31 |
my $builder = t::lib::TestBuilder->new; |
| 32 |
|
| 33 |
$schema->storage->txn_begin; |
| 34 |
|
| 35 |
|
| 36 |
my $frequency = $builder->build({ |
| 37 |
source => 'SubscriptionFrequency', |
| 38 |
value => { |
| 39 |
unit => 'day', |
| 40 |
unitsperissue => 1, |
| 41 |
issuesperunit => 1 |
| 42 |
} |
| 43 |
}); |
| 44 |
|
| 45 |
my $subscription = $builder->build({ |
| 46 |
source => 'Subscription', |
| 47 |
value => { |
| 48 |
startdate => '2018-01-01', |
| 49 |
weeklength => 0, |
| 50 |
monthlength => 0, |
| 51 |
numberlength => 7, |
| 52 |
periodicity => $frequency->{id}, |
| 53 |
} |
| 54 |
}); |
| 55 |
|
| 56 |
$subscription = Koha::Subscriptions->find($subscription->{subscriptionid}); |
| 57 |
$frequency = $schema->resultset('SubscriptionFrequency')->find($frequency->{id}); |
| 58 |
is($subscription->guess_enddate, '2018-01-08'); |
| 59 |
|
| 60 |
$frequency->update({ |
| 61 |
unit => 'day', |
| 62 |
unitsperissue => 2, |
| 63 |
issuesperunit => 1 |
| 64 |
}); |
| 65 |
is($subscription->guess_enddate, '2018-01-15'); |
| 66 |
|
| 67 |
$frequency->update({ |
| 68 |
unit => 'day', |
| 69 |
unitsperissue => 1, |
| 70 |
issuesperunit => 2 |
| 71 |
}); |
| 72 |
is($subscription->guess_enddate, '2018-01-04'); |
| 73 |
|
| 74 |
$frequency->update({ |
| 75 |
unit => 'week', |
| 76 |
unitsperissue => 1, |
| 77 |
issuesperunit => 1 |
| 78 |
}); |
| 79 |
is($subscription->guess_enddate, '2018-02-19'); |
| 80 |
|
| 81 |
$frequency->update({ |
| 82 |
unit => 'week', |
| 83 |
unitsperissue => 2, |
| 84 |
issuesperunit => 1 |
| 85 |
}); |
| 86 |
is($subscription->guess_enddate, '2018-04-09'); |
| 87 |
|
| 88 |
$frequency->update({ |
| 89 |
unit => 'week', |
| 90 |
unitsperissue => 1, |
| 91 |
issuesperunit => 2 |
| 92 |
}); |
| 93 |
is($subscription->guess_enddate, '2018-01-25'); |
| 94 |
|
| 95 |
$frequency->update({ |
| 96 |
unit => 'month', |
| 97 |
unitsperissue => 1, |
| 98 |
issuesperunit => 1 |
| 99 |
}); |
| 100 |
is($subscription->guess_enddate, '2018-08-01'); |
| 101 |
|
| 102 |
$frequency->update({ |
| 103 |
unit => 'month', |
| 104 |
unitsperissue => 2, |
| 105 |
issuesperunit => 1 |
| 106 |
}); |
| 107 |
is($subscription->guess_enddate, '2019-03-01'); |
| 108 |
|
| 109 |
$frequency->update({ |
| 110 |
unit => 'month', |
| 111 |
unitsperissue => 1, |
| 112 |
issuesperunit => 2 |
| 113 |
}); |
| 114 |
is($subscription->guess_enddate, '2018-04-01'); |
| 115 |
|
| 116 |
$frequency->update({ |
| 117 |
unit => 'year', |
| 118 |
unitsperissue => 1, |
| 119 |
issuesperunit => 1 |
| 120 |
}); |
| 121 |
is($subscription->guess_enddate, '2025-01-01'); |
| 122 |
|
| 123 |
$frequency->update({ |
| 124 |
unit => 'year', |
| 125 |
unitsperissue => 2, |
| 126 |
issuesperunit => 1 |
| 127 |
}); |
| 128 |
is($subscription->guess_enddate, '2032-01-01'); |
| 129 |
|
| 130 |
$frequency->update({ |
| 131 |
unit => 'year', |
| 132 |
unitsperissue => 1, |
| 133 |
issuesperunit => 2 |
| 134 |
}); |
| 135 |
is($subscription->guess_enddate, '2021-01-01'); |
| 136 |
|
| 137 |
|
| 138 |
$subscription->numberlength(0); |
| 139 |
$subscription->weeklength(2); |
| 140 |
$subscription->store; |
| 141 |
is($subscription->guess_enddate, '2018-01-15'); |
| 142 |
|
| 143 |
$subscription->weeklength(0); |
| 144 |
$subscription->monthlength(1); |
| 145 |
$subscription->store; |
| 146 |
is($subscription->guess_enddate, '2018-02-01'); |
| 147 |
|
| 148 |
$schema->storage->txn_rollback; |