|
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 => 2; |
| 21 |
use t::lib::TestBuilder; |
| 22 |
|
| 23 |
use C4::Serials; |
| 24 |
|
| 25 |
use Koha::Database; |
| 26 |
use Koha::Subscriptions; |
| 27 |
|
| 28 |
BEGIN { |
| 29 |
use_ok('Koha::Subscriptions'); |
| 30 |
} |
| 31 |
|
| 32 |
my $schema = Koha::Database->new->schema; |
| 33 |
my $builder = t::lib::TestBuilder->new; |
| 34 |
|
| 35 |
$schema->storage->txn_begin; |
| 36 |
|
| 37 |
my $biblio = $builder->build({ |
| 38 |
source => 'Biblio', |
| 39 |
}); |
| 40 |
|
| 41 |
my $frequency = $builder->build({ |
| 42 |
source => 'SubscriptionFrequency', |
| 43 |
value => { |
| 44 |
unit => 'day', |
| 45 |
unitsperissue => 1, |
| 46 |
issuesperunit => 1 |
| 47 |
} |
| 48 |
}); |
| 49 |
|
| 50 |
my $number_pattern = $builder->build({ |
| 51 |
source => 'SubscriptionNumberpattern', |
| 52 |
value => { |
| 53 |
numberingmethod => 'No.{X}', |
| 54 |
add1 => 1, |
| 55 |
every1 => 1, |
| 56 |
whenmorethan1 => 99999, |
| 57 |
setto1 => 1 |
| 58 |
} |
| 59 |
}); |
| 60 |
|
| 61 |
my $subscription = $builder->build({ |
| 62 |
source => 'Subscription', |
| 63 |
value => { |
| 64 |
biblionumber => $biblio->{biblionumber}, |
| 65 |
startdate => '2018-05-07', |
| 66 |
weeklength => 0, |
| 67 |
monthlength => 0, |
| 68 |
numberlength => 7, |
| 69 |
periodicity => $frequency->{id}, |
| 70 |
countissuesperunit => 1, |
| 71 |
status => 1, |
| 72 |
lastvalue1 => 5, |
| 73 |
lastvalue2 => 0, |
| 74 |
innerloop1 => 0, |
| 75 |
innerloop2 => 0, |
| 76 |
innerloop3 => 0, |
| 77 |
lastvalue3 => 0, |
| 78 |
firstacquidate => '2018-05-07', |
| 79 |
irregularity => '3;4', |
| 80 |
permanent_irregularity => '3;4', |
| 81 |
numberpattern => 7, |
| 82 |
enddate => '2018-05-13', |
| 83 |
closed => 0 |
| 84 |
} |
| 85 |
}); |
| 86 |
|
| 87 |
$builder->build({ |
| 88 |
source => 'Serial', |
| 89 |
value => { |
| 90 |
biblionumber => $biblio->{biblionumber}, |
| 91 |
subscriptionid => $subscription->{subscriptionid}, |
| 92 |
serialseq => 'No.1', |
| 93 |
serialseq_x => 1, |
| 94 |
status => 2, |
| 95 |
planneddate => '2018-05-07', |
| 96 |
publisheddate => '2018-05-07', |
| 97 |
} |
| 98 |
}); |
| 99 |
|
| 100 |
$builder->build({ |
| 101 |
source => 'Serial', |
| 102 |
value => { |
| 103 |
biblionumber => $biblio->{biblionumber}, |
| 104 |
subscriptionid => $subscription->{subscriptionid}, |
| 105 |
serialseq => 'No.2', |
| 106 |
serialseq_x => 2, |
| 107 |
status => 2, |
| 108 |
planneddate => '2018-05-08', |
| 109 |
publisheddate => '2018-05-08', |
| 110 |
} |
| 111 |
}); |
| 112 |
|
| 113 |
$builder->build({ |
| 114 |
source => 'Serial', |
| 115 |
value => { |
| 116 |
biblionumber => $biblio->{biblionumber}, |
| 117 |
subscriptionid => $subscription->{subscriptionid}, |
| 118 |
serialseq => 'No.3', |
| 119 |
serialseq_x => 3, |
| 120 |
status => 2, |
| 121 |
planneddate => '2018-05-11', |
| 122 |
publisheddate => '2018-05-11', |
| 123 |
} |
| 124 |
}); |
| 125 |
|
| 126 |
$builder->build({ |
| 127 |
source => 'Serial', |
| 128 |
value => { |
| 129 |
biblionumber => $biblio->{biblionumber}, |
| 130 |
subscriptionid => $subscription->{subscriptionid}, |
| 131 |
serialseq => 'No.4', |
| 132 |
serialseq_x => 4, |
| 133 |
status => 2, |
| 134 |
planneddate => '2018-05-12', |
| 135 |
publisheddate => '2018-05-12', |
| 136 |
} |
| 137 |
}); |
| 138 |
|
| 139 |
$builder->build({ |
| 140 |
source => 'Serial', |
| 141 |
value => { |
| 142 |
biblionumber => $biblio->{biblionumber}, |
| 143 |
subscriptionid => $subscription->{subscriptionid}, |
| 144 |
serialseq => 'No.5', |
| 145 |
serialseq_x => 5, |
| 146 |
status => 2, |
| 147 |
planneddate => '2018-05-13', |
| 148 |
publisheddate => '2018-05-13', |
| 149 |
} |
| 150 |
}); |
| 151 |
|
| 152 |
$builder->build({ |
| 153 |
source => 'Serial', |
| 154 |
value => { |
| 155 |
biblionumber => $biblio->{biblionumber}, |
| 156 |
subscriptionid => $subscription->{subscriptionid}, |
| 157 |
serialseq => 'No.6', |
| 158 |
serialseq_x => 6, |
| 159 |
status => 1, |
| 160 |
planneddate => '2018-05-14', |
| 161 |
publisheddate => '2018-05-14', |
| 162 |
} |
| 163 |
}); |
| 164 |
|
| 165 |
ReNewSubscription( |
| 166 |
$subscription->{subscriptionid}, undef, |
| 167 |
$subscription->{enddate}, $subscription->{numberlength}, |
| 168 |
$subscription->{weeklength}, $subscription->{monthlength}, |
| 169 |
); |
| 170 |
|
| 171 |
my $s = Koha::Subscriptions->find($subscription->{subscriptionid}); |
| 172 |
my $irregularities = join(';', $s->guess_irregularities); |
| 173 |
is($irregularities, '10;11', 'Irregularities have been updated'); |
| 174 |
|
| 175 |
$schema->storage->txn_rollback; |