Bug 8064: Change the way target record is built.
[koha.git] / t / Serials / GetNextSeq.t
blob2f3a1c35551fbc78c739da233ef7ebba70ae8db9
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use Test::More tests => 43;
5 use C4::Serials;
7 # TEST CASE 1 - 1 variable, from 1 to 4
8 my $subscription = {
9 lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1,
10 innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
11 skip_serialseq => 0,
12 irregularity => '',
13 locale => 'en',
15 my $pattern = {
16 add1 => 1, add2 => 0, add3 => 0,
17 every1 => 1, every2 => 0, every3 => 0,
18 whenmorethan1 => 4, whenmorethan2 => 0, whenmorethan3 => 0,
19 setto1 => 1, setto2 => 0, setto3 => 0,
20 numberingmethod => 'X: {X}',
21 numbering1 => '',
22 numbering2 => '',
23 numbering3 => '',
26 my $seq = _next_seq($subscription, $pattern);
27 is($seq, 'X: 2');
28 $seq = _next_seq($subscription, $pattern);
29 is($seq, 'X: 3');
30 $seq = _next_seq($subscription, $pattern);
31 is($seq, 'X: 4');
32 $seq = _next_seq($subscription, $pattern);
33 is($seq, 'X: 1');
34 $seq = _next_seq($subscription, $pattern);
35 is($seq, 'X: 2');
37 # TEST CASE 2 - 1 variable, use 'dayname' numbering, from 1 to 7
38 $subscription = {
39 lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1,
40 innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
41 skip_serialseq => 0,
42 irregularity => '',
43 locale => 'C',
45 $pattern = {
46 add1 => 1, add2 => 0, add3 => 0,
47 every1 => 1, every2 => 0, every3 => 0,
48 whenmorethan1 => 7, whenmorethan2 => 0, whenmorethan3 => 0,
49 setto1 => 1, setto2 => 0, setto3 => 0,
50 numberingmethod => 'X: {X}',
51 numbering1 => 'dayname',
52 numbering2 => '',
53 numbering3 => '',
56 $seq = _next_seq($subscription, $pattern);
57 is($seq, 'X: Tuesday');
58 $seq = _next_seq($subscription, $pattern);
59 is($seq, 'X: Wednesday');
60 $seq = _next_seq($subscription, $pattern);
61 is($seq, 'X: Thursday');
62 $seq = _next_seq($subscription, $pattern);
63 is($seq, 'X: Friday');
64 $seq = _next_seq($subscription, $pattern);
65 is($seq, 'X: Saturday');
66 $seq = _next_seq($subscription, $pattern);
67 is($seq, 'X: Sunday');
68 $seq = _next_seq($subscription, $pattern);
69 is($seq, 'X: Monday');
71 # TEST CASE 3 - 1 variable, use 'monthname' numbering, from 0 to 11 by step of 2
72 $subscription = {
73 lastvalue1 => 0, lastvalue2 => 1, lastvalue3 => 1,
74 innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
75 skip_serialseq => 0,
76 irregularity => '',
77 locale => 'C', # locale set to 'C' to ensure we'll have english strings
79 $pattern = {
80 add1 => 2, add2 => 0, add3 => 0,
81 every1 => 1, every2 => 0, every3 => 0,
82 whenmorethan1 => 11, whenmorethan2 => 0, whenmorethan3 => 0,
83 setto1 => 0, setto2 => 0, setto3 => 0,
84 numberingmethod => 'X: {X}',
85 numbering1 => 'monthname',
86 numbering2 => '',
87 numbering3 => '',
90 $seq = _next_seq($subscription, $pattern);
91 is($seq, 'X: March');
92 $seq = _next_seq($subscription, $pattern);
93 is($seq, 'X: May');
94 $seq = _next_seq($subscription, $pattern);
95 is($seq, 'X: July');
96 $seq = _next_seq($subscription, $pattern);
97 is($seq, 'X: September');
98 $seq = _next_seq($subscription, $pattern);
99 is($seq, 'X: November');
100 $seq = _next_seq($subscription, $pattern);
101 is($seq, 'X: January');
102 $seq = _next_seq($subscription, $pattern);
103 is($seq, 'X: March');
105 # TEST CASE 4 - 1 variable, use 'season' numbering, from 0 to 3
106 # Months starts at 0, this implies subscription's lastvalue1 should be 0,
107 # together with setto1 and whenmorethan1 should be 11
108 $subscription = {
109 lastvalue1 => 0, lastvalue2 => 1, lastvalue3 => 1,
110 innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
111 skip_serialseq => 0,
112 irregularity => '',
113 locale => 'C', # locale set to 'C' to ensure we'll have english strings
115 $pattern = {
116 add1 => 1, add2 => 0, add3 => 0,
117 every1 => 1, every2 => 0, every3 => 0,
118 whenmorethan1 => 3, whenmorethan2 => 0, whenmorethan3 => 0,
119 setto1 => 0, setto2 => 0, setto3 => 0,
120 numberingmethod => 'X: {X}',
121 numbering1 => 'season',
122 numbering2 => '',
123 numbering3 => '',
126 $seq = _next_seq($subscription, $pattern);
127 is($seq, 'X: Summer');
128 $seq = _next_seq($subscription, $pattern);
129 is($seq, 'X: Fall');
130 $seq = _next_seq($subscription, $pattern);
131 is($seq, 'X: Winter');
132 $seq = _next_seq($subscription, $pattern);
133 is($seq, 'X: Spring');
134 $seq = _next_seq($subscription, $pattern);
135 is($seq, 'X: Summer');
137 # TEST CASE 5 - 2 variables, from 1 to 12, and from 1 to 4
138 $subscription = {
139 lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1,
140 innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
141 skip_serialseq => 0,
142 irregularity => '',
143 locale => 'C', # locale set to 'C' to ensure we'll have english strings
145 $pattern = {
146 add1 => 1, add2 => 1, add3 => 0,
147 every1 => 1, every2 => 4, every3 => 0,
148 whenmorethan1 => 4, whenmorethan2 => 12, whenmorethan3 => 0,
149 setto1 => 1, setto2 => 1, setto3 => 0,
150 numberingmethod => 'Y: {Y}, X: {X}',
151 numbering1 => '',
152 numbering2 => '',
153 numbering3 => '',
156 $seq = _next_seq($subscription, $pattern);
157 is($seq, 'Y: 1, X: 2');
158 $seq = _next_seq($subscription, $pattern);
159 is($seq, 'Y: 1, X: 3');
160 $seq = _next_seq($subscription, $pattern);
161 is($seq, 'Y: 1, X: 4');
162 $seq = _next_seq($subscription, $pattern);
163 is($seq, 'Y: 2, X: 1');
164 $seq = _next_seq($subscription, $pattern);
165 is($seq, 'Y: 2, X: 2');
166 # Back to the future
167 for (1..39) {
168 $seq = _next_seq($subscription, $pattern);
170 $seq = _next_seq($subscription, $pattern);
171 is($seq, 'Y: 12, X: 2');
172 $seq = _next_seq($subscription, $pattern);
173 is($seq, 'Y: 12, X: 3');
174 $seq = _next_seq($subscription, $pattern);
175 is($seq, 'Y: 12, X: 4');
176 $seq = _next_seq($subscription, $pattern);
177 is($seq, 'Y: 1, X: 1');
179 # TEST CASE 6 - 3 variables, from 1 to 12, from 1 to 8, and from 1 to 4
180 $subscription = {
181 lastvalue1 => 1, lastvalue2 => 1, lastvalue3 => 1,
182 innerloop1 => 0, innerloop2 => 0, innerloop3 => 0,
183 skip_serialseq => 0,
184 irregularity => '',
185 locale => 'C', # locale set to 'C' to ensure we'll have english strings
187 $pattern = {
188 add1 => 1, add2 => 1, add3 => 1,
189 every1 => 1, every2 => 4, every3 => 32,
190 whenmorethan1 => 4, whenmorethan2 => 8, whenmorethan3 => 12,
191 setto1 => 1, setto2 => 1, setto3 => 1,
192 numberingmethod => 'Z: {Z}, Y: {Y}, X: {X}',
193 numbering1 => '',
194 numbering2 => '',
195 numbering3 => '',
198 $seq = _next_seq($subscription, $pattern);
199 is($seq, 'Z: 1, Y: 1, X: 2');
200 $seq = _next_seq($subscription, $pattern);
201 is($seq, 'Z: 1, Y: 1, X: 3');
202 $seq = _next_seq($subscription, $pattern);
203 is($seq, 'Z: 1, Y: 1, X: 4');
204 $seq = _next_seq($subscription, $pattern);
205 is($seq, 'Z: 1, Y: 2, X: 1');
206 for (1..24) {
207 $seq = _next_seq($subscription, $pattern);
209 $seq = _next_seq($subscription, $pattern);
210 is($seq, 'Z: 1, Y: 8, X: 2');
211 $seq = _next_seq($subscription, $pattern);
212 is($seq, 'Z: 1, Y: 8, X: 3');
213 $seq = _next_seq($subscription, $pattern);
214 is($seq, 'Z: 1, Y: 8, X: 4');
215 $seq = _next_seq($subscription, $pattern);
216 is($seq, 'Z: 2, Y: 1, X: 1');
217 for (1..350) {
218 $seq = _next_seq($subscription, $pattern);
220 $seq = _next_seq($subscription, $pattern);
221 is($seq, 'Z: 12, Y: 8, X: 4');
222 $seq = _next_seq($subscription, $pattern);
223 is($seq, 'Z: 1, Y: 1, X: 1');
226 sub _next_seq {
227 my ($subscription, $pattern) = @_;
228 my $seq;
229 ($seq, $subscription->{lastvalue1}, $subscription->{lastvalue2},
230 $subscription->{lastvalue3}, $subscription->{innerloop1},
231 $subscription->{innerloop2}, $subscription->{innerloop3}) =
232 GetNextSeq($subscription, $pattern);
233 return $seq;