4 use Test
::More tests
=> 32;
8 my $schema = Koha
::Database
->new->schema;
9 $schema->storage->txn_begin;
10 my $dbh = C4
::Context
->dbh;
12 use C4
::Serials
::Frequency
;
16 description
=> "One issue per day",
21 my $id = AddSubscriptionFrequency
($frequency);
23 # TEST CASE 1 - 1 variable, from 1 to 4
25 add1
=> 1, add2
=> 0, add3
=> 0,
26 every1
=> 1, every2
=> 0, every3
=> 0,
27 whenmorethan1
=> 4, whenmorethan2
=> 0, whenmorethan3
=> 0,
28 setto1
=> 1, setto2
=> 0, setto3
=> 0,
29 numberingmethod
=> 'X: {X}',
37 firstacquidate
=> '1970-01-01',
38 lastvalue1
=> 1, lastvalue2
=> 1, lastvalue3
=> 1,
39 innerloop1
=> 0, innerloop2
=> 0, innerloop3
=> 0,
41 irregularity
=> '3;5',
42 countissuesperunit
=> 1,
45 my $publisheddate = $subscription->{firstacquidate
};
47 my $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
49 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
50 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
52 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
53 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
55 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
56 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
59 # TEST CASE 2 - 1 variable, use 'dayname' numbering, from 1 to 7
62 firstacquidate
=> '1970-01-01',
63 lastvalue1
=> 1, lastvalue2
=> 1, lastvalue3
=> 1,
64 innerloop1
=> 0, innerloop2
=> 0, innerloop3
=> 0,
66 irregularity
=> '3;4;6',
67 countissuesperunit
=> 1,
71 add1
=> 1, add2
=> 0, add3
=> 0,
72 every1
=> 1, every2
=> 0, every3
=> 0,
73 whenmorethan1
=> 7, whenmorethan2
=> 0, whenmorethan3
=> 0,
74 setto1
=> 1, setto2
=> 0, setto3
=> 0,
75 numberingmethod
=> 'X: {X}',
76 numbering1
=> 'dayname',
81 $publisheddate = $subscription->{firstacquidate
};
83 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
84 is
($seq, 'X: Tuesday');
85 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
86 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
87 is
($seq, 'X: Friday');
88 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
89 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
90 is
($seq, 'X: Sunday');
91 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
92 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
93 is
($seq, 'X: Monday');
94 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
95 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
96 is
($seq, 'X: Tuesday');
98 # TEST CASE 3 - 1 variable, use 'monthname' numbering, from 0 to 11 by step of 2
101 firstacquidate
=> '1970-01-01',
102 lastvalue1
=> 0, lastvalue2
=> 1, lastvalue3
=> 1,
103 innerloop1
=> 0, innerloop2
=> 0, innerloop3
=> 0,
105 irregularity
=> '3;4;6',
106 countissuesperunit
=> 1,
110 add1
=> 2, add2
=> 0, add3
=> 0,
111 every1
=> 1, every2
=> 0, every3
=> 0,
112 whenmorethan1
=> 11, whenmorethan2
=> 0, whenmorethan3
=> 0,
113 setto1
=> 0, setto2
=> 0, setto3
=> 0,
114 numberingmethod
=> 'X: {X}',
115 numbering1
=> 'monthname',
120 $publisheddate = $subscription->{firstacquidate
};
122 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
123 is
($seq, 'X: March');
124 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
125 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
126 is
($seq, 'X: September');
127 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
128 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
129 is
($seq, 'X: January');
130 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
131 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
132 is
($seq, 'X: March');
133 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
134 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
137 # TEST CASE 4 - 1 variable, use 'season' numbering, from 0 to 3
140 firstacquidate
=> '1970-01-01',
141 lastvalue1
=> 0, lastvalue2
=> 1, lastvalue3
=> 1,
142 innerloop1
=> 0, innerloop2
=> 0, innerloop3
=> 0,
144 irregularity
=> '3;4;6',
145 countissuesperunit
=> 1,
149 add1
=> 1, add2
=> 0, add3
=> 0,
150 every1
=> 1, every2
=> 0, every3
=> 0,
151 whenmorethan1
=> 3, whenmorethan2
=> 0, whenmorethan3
=> 0,
152 setto1
=> 0, setto2
=> 0, setto3
=> 0,
153 numberingmethod
=> 'X: {X}',
154 numbering1
=> 'season',
159 $publisheddate = $subscription->{firstacquidate
};
161 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
162 is
($seq, 'X: Summer');
163 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
164 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
165 is
($seq, 'X: Spring');
166 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
167 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
169 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
170 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
171 is
($seq, 'X: Winter');
172 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
173 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
174 is
($seq, 'X: Spring');
176 # TEST CASE 5 - 2 variables, from 1 to 12, and from 1 to 4
179 firstacquidate
=> '1970-01-01',
180 lastvalue1
=> 1, lastvalue2
=> 1, lastvalue3
=> 1,
181 innerloop1
=> 0, innerloop2
=> 0, innerloop3
=> 0,
183 irregularity
=> '3;4;6',
184 countissuesperunit
=> 1,
188 add1
=> 1, add2
=> 1, add3
=> 0,
189 every1
=> 1, every2
=> 4, every3
=> 0,
190 whenmorethan1
=> 4, whenmorethan2
=> 12, whenmorethan3
=> 0,
191 setto1
=> 1, setto2
=> 1, setto3
=> 0,
192 numberingmethod
=> 'Y: {Y}, X: {X}',
198 $publisheddate = $subscription->{firstacquidate
};
200 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
201 is
($seq, 'Y: 1, X: 2');
202 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
203 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
204 is
($seq, 'Y: 2, X: 1');
205 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
206 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
207 is
($seq, 'Y: 2, X: 3');
208 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
209 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
210 is
($seq, 'Y: 2, X: 4');
211 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
212 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
213 is
($seq, 'Y: 3, X: 1');
215 # TEST CASE 6 - 3 variables, from 1 to 12, from 1 to 8, and from 1 to 4
218 firstacquidate
=> '1970-01-01',
219 lastvalue1
=> 1, lastvalue2
=> 1, lastvalue3
=> 1,
220 innerloop1
=> 0, innerloop2
=> 0, innerloop3
=> 0,
222 irregularity
=> '3;4;6;110',
223 countissuesperunit
=> 1,
227 add1
=> 1, add2
=> 1, add3
=> 1,
228 every1
=> 1, every2
=> 4, every3
=> 32,
229 whenmorethan1
=> 4, whenmorethan2
=> 8, whenmorethan3
=> 12,
230 setto1
=> 1, setto2
=> 1, setto3
=> 1,
231 numberingmethod
=> 'Z: {Z}, Y: {Y}, X: {X}',
237 $publisheddate = $subscription->{firstacquidate
};
239 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
240 is
($seq, 'Z: 1, Y: 1, X: 2');
241 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
242 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
243 is
($seq, 'Z: 1, Y: 2, X: 1');
244 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
245 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
246 is
($seq, 'Z: 1, Y: 2, X: 3');
247 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
248 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
249 is
($seq, 'Z: 1, Y: 2, X: 4');
251 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
252 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
254 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
255 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
256 is
($seq, 'Z: 4, Y: 4, X: 1');
258 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
259 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
260 is
($seq, 'Z: 4, Y: 4, X: 3');
261 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
262 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
263 is
($seq, 'Z: 4, Y: 4, X: 4');
264 $publisheddate = GetNextDate
($subscription, $publisheddate, $frequency);
265 $seq = _next_seq
($subscription, $pattern, $frequency, $publisheddate);
266 is
($seq, 'Z: 4, Y: 5, X: 1');
269 my ($subscription, $pattern, $frequency, $publisheddate) = @_;
271 ($seq, $subscription->{lastvalue1
}, $subscription->{lastvalue2
},
272 $subscription->{lastvalue3
}, $subscription->{innerloop1
},
273 $subscription->{innerloop2
}, $subscription->{innerloop3
}) =
274 GetNextSeq
($subscription, $pattern, $frequency, $publisheddate);