Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
# |
3 |
# This Koha test module is a stub! |
4 |
# Add more tests here!!! |
5 |
|
6 |
use Modern::Perl; |
7 |
|
8 |
use C4::Serials |
9 |
qw( updateClaim NewSubscription GetSubscription GetSubscriptionHistoryFromSubscriptionId SearchSubscriptions ModSubscription GetExpirationDate GetSerials GetSerialInformation NewIssue AddItem2Serial DelSubscription GetFullSubscription PrepareSerialsData GetSubscriptionsFromBiblionumber ModSubscriptionHistory GetSerials2 GetLatestSerials GetNextSeq GetSeq CountSubscriptionFromBiblionumber ModSerialStatus findSerialsByStatus HasSubscriptionStrictlyExpired HasSubscriptionExpired GetLateOrMissingIssues check_routing addroutingmember GetNextDate GetSeasonsTranslations ); |
10 |
use C4::Serials::Frequency; |
11 |
use C4::Serials::Numberpattern; |
12 |
use C4::Biblio qw( AddBiblio GetMarcFromKohaField ); |
13 |
use C4::Budgets qw( AddBudgetPeriod AddBudget ); |
14 |
use C4::Context; |
15 |
use C4::Items qw( AddItemFromMarc ); |
16 |
use Encode qw( encode ); |
17 |
use File::Temp; |
18 |
use Koha::Database; |
19 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
20 |
use Koha::Acquisition::Booksellers; |
21 |
use t::lib::Mocks; |
22 |
use t::lib::TestBuilder; |
23 |
use Test::More tests => 55; |
24 |
|
25 |
BEGIN { |
26 |
use_ok( |
27 |
'C4::Serials', |
28 |
qw( updateClaim NewSubscription GetSubscription GetSubscriptionHistoryFromSubscriptionId SearchSubscriptions ModSubscription GetExpirationDate GetSerials GetSerialInformation NewIssue AddItem2Serial DelSubscription GetFullSubscription PrepareSerialsData GetSubscriptionsFromBiblionumber ModSubscriptionHistory GetSerials2 GetLatestSerials GetNextSeq GetSeq CountSubscriptionFromBiblionumber ModSerialStatus findSerialsByStatus HasSubscriptionStrictlyExpired HasSubscriptionExpired GetLateOrMissingIssues check_routing addroutingmember GetNextDate GetSeasonsTranslations ) |
29 |
); |
30 |
} |
31 |
|
32 |
# Auth required for cataloguing plugins |
33 |
my $mAuth = Test::MockModule->new('C4::Auth'); |
34 |
$mAuth->mock( 'check_cookie_auth', sub { return ('ok') } ); |
35 |
|
36 |
my $schema = Koha::Database->new->schema; |
37 |
$schema->storage->txn_begin; |
38 |
my $dbh = C4::Context->dbh; |
39 |
|
40 |
$dbh->do('DELETE FROM subscription'); |
41 |
|
42 |
my $builder = t::lib::TestBuilder->new(); |
43 |
|
44 |
# This could/should be used for all untested methods |
45 |
my @methods = ('updateClaim'); |
46 |
can_ok( 'C4::Serials', @methods ); |
47 |
|
48 |
$dbh->do( |
49 |
q|UPDATE marc_subfield_structure SET value_builder="callnumber.pl" where kohafield="items.itemcallnumber" and frameworkcode=''| |
50 |
); |
51 |
|
52 |
my $bookseller = Koha::Acquisition::Bookseller->new( |
53 |
{ |
54 |
name => "my vendor", |
55 |
address1 => "bookseller's address", |
56 |
phone => "0123456", |
57 |
active => 1 |
58 |
} |
59 |
); |
60 |
|
61 |
my ( $biblionumber, $biblioitemnumber ) = AddBiblio( MARC::Record->new, '' ); |
62 |
|
63 |
my $bpid = AddBudgetPeriod( |
64 |
{ |
65 |
budget_period_startdate => '2015-01-01', |
66 |
budget_period_enddate => '2015-12-31', |
67 |
budget_period_description => "budget desc" |
68 |
} |
69 |
); |
70 |
|
71 |
my $budget_id = AddBudget( |
72 |
{ |
73 |
budget_code => "ABCD", |
74 |
budget_amount => "123.132", |
75 |
budget_name => "Périodiques", |
76 |
budget_notes => "This is a note", |
77 |
budget_period_id => $bpid |
78 |
} |
79 |
); |
80 |
|
81 |
my $frequency_id = AddSubscriptionFrequency( { description => "Test frequency 1" } ); |
82 |
my $pattern_id = AddSubscriptionNumberpattern( |
83 |
{ |
84 |
label => 'Test numberpattern 1', |
85 |
description => 'Description for numberpattern 1', |
86 |
numberingmethod => '{X}', |
87 |
label1 => q{}, |
88 |
add1 => 1, |
89 |
every1 => 1, |
90 |
every1 => 1, |
91 |
numbering1 => 1, |
92 |
whenmorethan1 => 1, |
93 |
} |
94 |
); |
95 |
|
96 |
my $notes = "a\nnote\non\nseveral\nlines"; |
97 |
my $internalnotes = 'intnotes'; |
98 |
my $ccode = 'FIC'; |
99 |
my $subscriptionid = NewSubscription( |
100 |
undef, |
101 |
"", |
102 |
undef, |
103 |
undef, |
104 |
$budget_id, |
105 |
$biblionumber, |
106 |
'2013-01-01', |
107 |
$frequency_id, |
108 |
undef, |
109 |
undef, |
110 |
undef, |
111 |
undef, |
112 |
undef, |
113 |
undef, |
114 |
undef, |
115 |
undef, |
116 |
undef, |
117 |
1, |
118 |
$notes, |
119 |
undef, |
120 |
'2013-01-01', |
121 |
undef, |
122 |
$pattern_id, |
123 |
undef, |
124 |
undef, |
125 |
0, |
126 |
$internalnotes, |
127 |
0, |
128 |
undef, |
129 |
undef, |
130 |
0, |
131 |
undef, |
132 |
'2013-12-31', 0, |
133 |
undef, |
134 |
undef, |
135 |
undef, |
136 |
$ccode |
137 |
); |
138 |
|
139 |
NewSubscription( |
140 |
undef, |
141 |
"", |
142 |
undef, |
143 |
undef, |
144 |
$budget_id, |
145 |
$biblionumber, |
146 |
'2013-01-02', |
147 |
$frequency_id, |
148 |
undef, |
149 |
undef, |
150 |
undef, |
151 |
undef, |
152 |
undef, |
153 |
undef, |
154 |
undef, |
155 |
undef, |
156 |
undef, |
157 |
1, |
158 |
$notes, |
159 |
undef, |
160 |
'2013-01-02', |
161 |
undef, |
162 |
$pattern_id, |
163 |
undef, |
164 |
undef, |
165 |
0, |
166 |
$internalnotes, |
167 |
0, |
168 |
undef, |
169 |
undef, |
170 |
0, |
171 |
undef, |
172 |
'2013-12-31', |
173 |
0, |
174 |
undef, |
175 |
undef, |
176 |
undef, |
177 |
$ccode |
178 |
); |
179 |
|
180 |
my $subscriptioninformation = GetSubscription($subscriptionid); |
181 |
|
182 |
is( $subscriptioninformation->{notes}, $notes, 'NewSubscription should set notes' ); |
183 |
is( $subscriptioninformation->{internalnotes}, $internalnotes, 'NewSubscription should set internalnotes' ); |
184 |
is( $subscriptioninformation->{ccode}, $ccode, 'NewSubscription should set ccode' ); |
185 |
|
186 |
my $subscription_history = C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid); |
187 |
is( $subscription_history->{opacnote}, undef, 'NewSubscription should not set subscriptionhistory opacnotes' ); |
188 |
is( |
189 |
$subscription_history->{librariannote}, undef, |
190 |
'NewSubscription should not set subscriptionhistory librariannotes' |
191 |
); |
192 |
|
193 |
my @subscriptions = SearchSubscriptions( { string => $subscriptioninformation->{bibliotitle}, orderby => 'title' } ); |
194 |
isa_ok( \@subscriptions, 'ARRAY' ); |
195 |
|
196 |
@subscriptions = SearchSubscriptions( { issn => $subscriptioninformation->{issn}, orderby => 'title' } ); |
197 |
isa_ok( \@subscriptions, 'ARRAY' ); |
198 |
|
199 |
@subscriptions = SearchSubscriptions( { ean => $subscriptioninformation->{ean}, orderby => 'title' } ); |
200 |
isa_ok( \@subscriptions, 'ARRAY' ); |
201 |
|
202 |
@subscriptions = SearchSubscriptions( { biblionumber => $subscriptioninformation->{bibnum}, orderby => 'title' } ); |
203 |
isa_ok( \@subscriptions, 'ARRAY' ); |
204 |
|
205 |
@subscriptions = SearchSubscriptions( {} ); |
206 |
is( |
207 |
@subscriptions, |
208 |
2, |
209 |
'SearchSubscriptions returned the expected number of subscriptions when results_limit is not set' |
210 |
); |
211 |
|
212 |
@subscriptions = SearchSubscriptions( {}, { results_limit => 1 } ); |
213 |
is( |
214 |
@subscriptions, |
215 |
1, |
216 |
'SearchSubscriptions returned only one subscription when results_limit is set to "1"' |
217 |
); |
218 |
|
219 |
my $frequency = GetSubscriptionFrequency( $subscriptioninformation->{periodicity} ); |
220 |
my $old_frequency; |
221 |
if ( not $frequency->{unit} ) { |
222 |
$old_frequency = $frequency->{id}; |
223 |
$frequency->{unit} = "month"; |
224 |
$frequency->{unitsperissue} = 1; |
225 |
$frequency->{issuesperunit} = 1; |
226 |
$frequency->{description} = "Frequency created by t/db_dependant/Serials.t"; |
227 |
$subscriptioninformation->{periodicity} = AddSubscriptionFrequency($frequency); |
228 |
$subscriptioninformation->{serialsadditems} = 1; |
229 |
$subscriptioninformation->{ccode} = 'NFIC'; |
230 |
|
231 |
ModSubscription( |
232 |
@$subscriptioninformation{ |
233 |
qw( |
234 |
librarian branchcode aqbooksellerid cost aqbudgetid startdate |
235 |
periodicity firstacquidate irregularity numberpattern locale |
236 |
numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2 |
237 |
innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes |
238 |
letter manualhistory internalnotes serialsadditems staffdisplaycount |
239 |
opacdisplaycount graceperiod location enddate subscriptionid |
240 |
skip_serialseq itemtype previousitemtype mana_id ccode |
241 |
) |
242 |
} |
243 |
); |
244 |
} |
245 |
my $expirationdate = GetExpirationDate($subscriptionid); |
246 |
ok( $expirationdate, "expiration date is not NULL" ); |
247 |
|
248 |
# Check ModSubscription has updated the ccode |
249 |
my $subscriptioninformation2 = GetSubscription($subscriptionid); |
250 |
is( $subscriptioninformation2->{ccode}, 'NFIC', 'ModSubscription should update ccode' ); |
251 |
|
252 |
ok( C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid), 'test getting history from sub-scription' ); |
253 |
|
254 |
my ( $serials_count, @serials ) = GetSerials($subscriptionid); |
255 |
ok( $serials_count > 0, 'Subscription has at least one serial' ); |
256 |
my $serial = $serials[0]; |
257 |
|
258 |
isa_ok( C4::Serials::GetSerialInformation( $serial->{serialid} ), 'HASH', 'test getting Serial Information' ); |
259 |
|
260 |
subtest 'Values should not be erased on editing' => sub { |
261 |
|
262 |
plan tests => 1; |
263 |
|
264 |
my $biblio = $builder->build_sample_biblio(); |
265 |
my $biblionumber = $biblio->biblionumber; |
266 |
my ( $icn_tag, $icn_sf ) = GetMarcFromKohaField('items.itemcallnumber'); |
267 |
my ( $it_tag, $it_sf ) = GetMarcFromKohaField('items.itype'); |
268 |
|
269 |
my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype}; |
270 |
my $itemcallnumber = 'XXXmy itemcallnumberXXX'; |
271 |
|
272 |
my $item_record = MARC::Record->new; |
273 |
|
274 |
$item_record->append_fields( |
275 |
MARC::Field->new( '080', '', '', "a" => "default" ), |
276 |
MARC::Field->new( |
277 |
$icn_tag, '', '', |
278 |
$icn_sf => $itemcallnumber, |
279 |
$it_sf => $itemtype |
280 |
) |
281 |
); |
282 |
my ( undef, undef, $itemnumber ) = C4::Items::AddItemFromMarc( $item_record, $biblionumber ); |
283 |
my $serialid = C4::Serials::NewIssue( |
284 |
"serialseq", $subscriptionid, $biblionumber, |
285 |
1, undef, undef, "publisheddatetext", "notes", "routingnotes" |
286 |
); |
287 |
C4::Serials::AddItem2Serial( $serialid, $itemnumber ); |
288 |
my $serial_info = C4::Serials::GetSerialInformation($serialid); |
289 |
my ($itemcallnumber_info) = |
290 |
grep { $_->{kohafield} eq 'items.itemcallnumber' } @{ $serial_info->{items}[0]->{iteminformation} }; |
291 |
like( $itemcallnumber_info->{marc_value}, qr|value="$itemcallnumber"| ); |
292 |
}; |
293 |
|
294 |
# Delete created frequency |
295 |
if ($old_frequency) { |
296 |
my $freq_to_delete = $subscriptioninformation->{periodicity}; |
297 |
$subscriptioninformation->{periodicity} = $old_frequency; |
298 |
|
299 |
ModSubscription( |
300 |
@$subscriptioninformation{ |
301 |
qw( |
302 |
librarian branchcode aqbooksellerid cost aqbudgetid startdate |
303 |
periodicity firstacquidate irregularity numberpattern locale |
304 |
numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2 |
305 |
innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes |
306 |
letter manualhistory internalnotes serialsadditems staffdisplaycount |
307 |
opacdisplaycount graceperiod location enddate subscriptionid |
308 |
skip_serialseq |
309 |
) |
310 |
} |
311 |
); |
312 |
|
313 |
DelSubscriptionFrequency($freq_to_delete); |
314 |
} |
315 |
|
316 |
# Test calling subs without parameters |
317 |
is( C4::Serials::AddItem2Serial(), undef, 'test adding item to serial' ); |
318 |
is( C4::Serials::GetFullSubscription(), undef, 'test getting full subscription' ); |
319 |
is( C4::Serials::PrepareSerialsData(), undef, 'test preparing serial data' ); |
320 |
|
321 |
subtest 'GetSubscriptionsFromBiblionumber' => sub { |
322 |
plan tests => 4; |
323 |
|
324 |
is( |
325 |
C4::Serials::GetSubscriptionsFromBiblionumber(), |
326 |
undef, 'test getting subscriptions form biblio number' |
327 |
); |
328 |
|
329 |
my $subscriptions = C4::Serials::GetSubscriptionsFromBiblionumber($biblionumber); |
330 |
ModSubscriptionHistory( |
331 |
$subscriptions->[0]->{subscriptionid}, |
332 |
undef, undef, $notes, $notes, $notes |
333 |
); |
334 |
|
335 |
$subscriptions = C4::Serials::GetSubscriptionsFromBiblionumber($biblionumber); |
336 |
is( |
337 |
$subscriptions->[0]->{opacnote}, $notes, |
338 |
'GetSubscriptionsFromBiblionumber should have returned the opacnote as it is in DB, ie. without br tags' |
339 |
); |
340 |
is( |
341 |
$subscriptions->[0]->{recievedlist}, $notes, |
342 |
'GetSubscriptionsFromBiblionumber should have returned recievedlist as it is in DB, ie. without br tags' |
343 |
); |
344 |
is( |
345 |
$subscriptions->[0]->{missinglist}, $notes, |
346 |
'GetSubscriptionsFromBiblionumber should have returned missinglist as it is in DB, ie. without br tags' |
347 |
); |
348 |
}; |
349 |
|
350 |
is( C4::Serials::GetSerials(), undef, 'test getting serials when you enter nothing' ); |
351 |
is( C4::Serials::GetSerials2(), undef, 'test getting serials when you enter nothing' ); |
352 |
|
353 |
is( C4::Serials::GetLatestSerials(), undef, 'test getting lastest serials' ); |
354 |
|
355 |
is( C4::Serials::GetNextSeq(), undef, 'test getting next seq when you enter nothing' ); |
356 |
|
357 |
is( C4::Serials::GetSeq(), undef, 'test getting seq when you enter nothing' ); |
358 |
|
359 |
is( C4::Serials::CountSubscriptionFromBiblionumber(), undef, 'test counting subscription when nothing is entered' ); |
360 |
|
361 |
is( C4::Serials::ModSubscriptionHistory(), undef, 'test modding subscription history' ); |
362 |
|
363 |
is( C4::Serials::ModSerialStatus(), undef, 'test modding serials' ); |
364 |
|
365 |
is( C4::Serials::findSerialsByStatus(), 0, 'test finding serial by status with no parameters' ); |
366 |
|
367 |
is( C4::Serials::NewIssue(), undef, 'test getting 0 when nothing is entered' ); |
368 |
|
369 |
is( C4::Serials::HasSubscriptionStrictlyExpired(), undef, 'test if the subscriptions has expired' ); |
370 |
is( C4::Serials::HasSubscriptionExpired(), undef, 'test if the subscriptions has expired' ); |
371 |
|
372 |
is( C4::Serials::GetLateOrMissingIssues(), undef, 'test getting last or missing issues' ); |
373 |
|
374 |
subtest 'test_updateClaim' => sub { |
375 |
plan tests => 11; |
376 |
|
377 |
my $today = output_pref( { dt => dt_from_string, dateonly => 1 } ); |
378 |
|
379 |
# Given ... nothing much |
380 |
# When ... Then ... |
381 |
my $result_0 = C4::Serials::updateClaim(undef); |
382 |
is( $result_0, undef, 'Got the expected undef from update claim with nothin' ); |
383 |
|
384 |
# Given ... 3 serial. 2 of them updated. |
385 |
my $claimdate_1 = dt_from_string('2001-01-13'); # arbitrary date some time in the past. |
386 |
my $claim_count_1 = 5; |
387 |
my $biblio = $builder->build_sample_biblio; |
388 |
my $serial1 = $builder->build_object( |
389 |
{ |
390 |
class => 'Koha::Serials', |
391 |
value => { |
392 |
serialseq => 'serialseq', |
393 |
subscriptionid => $subscriptionid, |
394 |
status => 3, |
395 |
biblionumber => $biblio->biblionumber, |
396 |
claimdate => $claimdate_1, |
397 |
claims_count => $claim_count_1, |
398 |
} |
399 |
} |
400 |
); |
401 |
my $serial2 = $builder->build_object( |
402 |
{ |
403 |
class => 'Koha::Serials', |
404 |
value => { |
405 |
serialseq => 'serialseq', |
406 |
subscriptionid => $subscriptionid, |
407 |
status => 3, |
408 |
biblionumber => $biblio->biblionumber, |
409 |
claimdate => $claimdate_1, |
410 |
claims_count => $claim_count_1, |
411 |
} |
412 |
} |
413 |
); |
414 |
my $serial3 = $builder->build_object( |
415 |
{ |
416 |
class => 'Koha::Serials', |
417 |
value => { |
418 |
serialseq => 'serialseq', |
419 |
subscriptionid => $subscriptionid, |
420 |
status => 3, |
421 |
biblionumber => $biblio->biblionumber, |
422 |
claimdate => $claimdate_1, |
423 |
claims_count => $claim_count_1, |
424 |
} |
425 |
} |
426 |
); |
427 |
|
428 |
# When ... |
429 |
my $result_1 = C4::Serials::updateClaim( [ $serial1->serialid, $serial2->serialid ] ); |
430 |
|
431 |
# Then ... |
432 |
is( $result_1, 2, 'Got the expected 2 from update claim with 2 serial ids' ); |
433 |
|
434 |
my @late_or_missing_issues_1_0 = C4::Serials::GetLateOrMissingIssues( undef, $serial1->serialid ); |
435 |
is( |
436 |
output_pref( { str => $late_or_missing_issues_1_0[0]->{claimdate}, dateonly => 1 } ), $today, |
437 |
'Got the expected first different claim date from update claim' |
438 |
); |
439 |
is( |
440 |
$late_or_missing_issues_1_0[0]->{claims_count}, $claim_count_1 + 1, |
441 |
'Got the expected first claim count from update claim' |
442 |
); |
443 |
is( $late_or_missing_issues_1_0[0]->{status}, 7, 'Got the expected first claim status from update claim' ); |
444 |
|
445 |
my @late_or_missing_issues_1_1 = C4::Serials::GetLateOrMissingIssues( undef, $serial2->serialid ); |
446 |
is( |
447 |
output_pref( { str => $late_or_missing_issues_1_1[0]->{claimdate}, dateonly => 1 } ), $today, |
448 |
'Got the expected second different claim date from update claim' |
449 |
); |
450 |
is( |
451 |
$late_or_missing_issues_1_1[0]->{claims_count}, $claim_count_1 + 1, |
452 |
'Got the expected second claim count from update claim' |
453 |
); |
454 |
is( $late_or_missing_issues_1_1[0]->{status}, 7, 'Got the expected second claim status from update claim' ); |
455 |
|
456 |
my @late_or_missing_issues_1_2 = C4::Serials::GetLateOrMissingIssues( undef, $serial3->serialid ); |
457 |
is( |
458 |
output_pref( { str => $late_or_missing_issues_1_2[0]->{claimdate}, dateonly => 1 } ), |
459 |
output_pref( { dt => $claimdate_1, dateonly => 1 } ), |
460 |
'Got the expected unchanged claim date from update claim' |
461 |
); |
462 |
is( |
463 |
$late_or_missing_issues_1_2[0]->{claims_count}, $claim_count_1, |
464 |
'Got the expected unchanged claim count from update claim' |
465 |
); |
466 |
is( $late_or_missing_issues_1_2[0]->{status}, 3, 'Got the expected unchanged claim status from update claim' ); |
467 |
}; |
468 |
|
469 |
is( C4::Serials::check_routing(), undef, 'test checking route' ); |
470 |
is( C4::Serials::check_routing($subscriptionid), 0, 'There should not have any routing list for the subscription' ); |
471 |
|
472 |
# TODO really test this check_routing subroutine |
473 |
|
474 |
is( C4::Serials::addroutingmember(), undef, 'test adding route member' ); |
475 |
|
476 |
# Unit tests for statuses management (Bug 11689) |
477 |
$subscriptionid = NewSubscription( |
478 |
undef, "", undef, undef, $budget_id, $biblionumber, |
479 |
'2013-01-01', $frequency_id, undef, undef, undef, |
480 |
undef, undef, undef, undef, undef, undef, |
481 |
1, $notes, undef, '2013-01-01', undef, $pattern_id, |
482 |
undef, undef, 0, $internalnotes, 0, |
483 |
undef, undef, 0, undef, '2013-12-31', 0 |
484 |
); |
485 |
my $total_issues; |
486 |
( $total_issues, @serials ) = C4::Serials::GetSerials($subscriptionid); |
487 |
is( $total_issues, 1, "NewSubscription created a first serial" ); |
488 |
is( @serials, 1, "GetSerials returns the serial" ); |
489 |
my $subscription = C4::Serials::GetSubscription($subscriptionid); |
490 |
my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern( $subscription->{numberpattern} ); |
491 |
( $total_issues, @serials ) = C4::Serials::GetSerials($subscriptionid); |
492 |
my $publisheddate = output_pref( { dt => dt_from_string, dateformat => 'iso', dateonly => 1 } ); |
493 |
( $total_issues, @serials ) = C4::Serials::GetSerials($subscriptionid); |
494 |
$frequency = C4::Serials::Frequency::GetSubscriptionFrequency( $subscription->{periodicity} ); |
495 |
my $nextpublisheddate = C4::Serials::GetNextDate( $subscription, $publisheddate, $frequency, 1 ); |
496 |
my @statuses = qw( 2 2 3 3 3 3 3 4 4 41 42 43 44 5 ); |
497 |
|
498 |
# Add 14 serials |
499 |
my $counter = 0; |
500 |
for my $status (@statuses) { |
501 |
my $serialseq = "No." . $counter; |
502 |
my ($expected_serial) = GetSerials2( $subscriptionid, [1] ); |
503 |
C4::Serials::ModSerialStatus( |
504 |
$expected_serial->{serialid}, $serialseq, $publisheddate, $publisheddate, |
505 |
$publisheddate, $statuses[$counter], 'an useless note' |
506 |
); |
507 |
$counter++; |
508 |
} |
509 |
|
510 |
# Here we have 15 serials with statuses : 2*2 + 5*3 + 2*4 + 1*41 + 1*42 + 1*43 + 1*44 + 1*5 + 1*1 |
511 |
my @serialsByStatus = C4::Serials::findSerialsByStatus( 2, $subscriptionid ); |
512 |
is( @serialsByStatus, 2, "findSerialsByStatus returns all serials with chosen status" ); |
513 |
( $total_issues, @serials ) = C4::Serials::GetSerials($subscriptionid); |
514 |
is( $total_issues, @statuses + 1, "GetSerials returns total_issues" ); |
515 |
my @arrived_missing = map { |
516 |
my $status = $_->{status}; |
517 |
( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? $_ : () |
518 |
} @serials; |
519 |
my @others = map { |
520 |
my $status = $_->{status}; |
521 |
( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? () : $_ |
522 |
} @serials; |
523 |
is( @arrived_missing, 5, "GetSerials returns 5 arrived/missing by default" ); |
524 |
is( @others, 6, "GetSerials returns all serials not arrived and not missing" ); |
525 |
|
526 |
( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid, 10 ); |
527 |
is( $total_issues, @statuses + 1, "GetSerials returns total_issues" ); |
528 |
@arrived_missing = map { |
529 |
my $status = $_->{status}; |
530 |
( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? $_ : () |
531 |
} @serials; |
532 |
@others = map { |
533 |
my $status = $_->{status}; |
534 |
( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? () : $_ |
535 |
} @serials; |
536 |
is( @arrived_missing, 9, "GetSerials returns all arrived/missing if count given" ); |
537 |
is( @others, 6, "GetSerials returns all serials not arrived and not missing if count given" ); |
538 |
|
539 |
$subscription = C4::Serials::GetSubscription($subscriptionid); # Retrieve the updated subscription |
540 |
|
541 |
my @serialseqs; |
542 |
for my $am (@arrived_missing) { |
543 |
if ( grep { /^$am->{status}$/ } qw( 4 41 42 43 44 ) ) { |
544 |
push @serialseqs, $am->{serialseq}; |
545 |
} elsif ( grep { /^$am->{status}$/ } qw( 5 ) ) { |
546 |
push @serialseqs, 'not issued ' . $am->{serialseq}; |
547 |
} |
548 |
} |
549 |
is( |
550 |
$subscription->{missinglist}, join( '; ', @serialseqs ), |
551 |
"subscription missinglist is updated after ModSerialStatus" |
552 |
); |
553 |
|
554 |
subtest "Do not generate an expected if one already exists" => sub { |
555 |
plan tests => 2; |
556 |
my ($expected_serial) = GetSerials2( $subscriptionid, [1] ); |
557 |
|
558 |
#Find serialid for serial with status Expected |
559 |
my $serialexpected = ( C4::Serials::findSerialsByStatus( 1, $subscriptionid ) )[0]; |
560 |
|
561 |
#delete serial with status Expected |
562 |
C4::Serials::ModSerialStatus( |
563 |
$serialexpected->{serialid}, $serialexpected->{serialseq}, $publisheddate, |
564 |
$publisheddate, $publisheddate, '1', 'an useless note' |
565 |
); |
566 |
@serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid ); |
567 |
is( @serialsByStatus, 1, "ModSerialStatus delete corectly serial expected and create another if not exist" ); |
568 |
|
569 |
# add 1 serial with status=Expected 1 |
570 |
C4::Serials::ModSerialStatus( |
571 |
$expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate, |
572 |
$publisheddate, '1', 'an useless note' |
573 |
); |
574 |
|
575 |
#Now we have two serials it have status expected |
576 |
#put status delete for last serial |
577 |
C4::Serials::ModSerialStatus( |
578 |
$serialexpected->{serialid}, $serialexpected->{serialseq}, $publisheddate, |
579 |
$publisheddate, $publisheddate, '1', 'an useless note' |
580 |
); |
581 |
|
582 |
#try if create or not another serial with status is expected |
583 |
@serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid ); |
584 |
is( @serialsByStatus, 1, "ModSerialStatus delete corectly serial expected and not create another if exists" ); |
585 |
}; |
586 |
|
587 |
subtest "PreserveSerialNotes preference" => sub { |
588 |
plan tests => 2; |
589 |
my ($expected_serial) = GetSerials2( $subscriptionid, [1] ); |
590 |
|
591 |
t::lib::Mocks::mock_preference( 'PreserveSerialNotes', 1 ); |
592 |
|
593 |
C4::Serials::ModSerialStatus( |
594 |
$expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate, |
595 |
$publisheddate, '1', 'an useless note' |
596 |
); |
597 |
@serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid ); |
598 |
is( $serialsByStatus[0]->{note}, $expected_serial->{note}, "note passed through if supposed to" ); |
599 |
|
600 |
t::lib::Mocks::mock_preference( 'PreserveSerialNotes', 0 ); |
601 |
$expected_serial = $serialsByStatus[0]; |
602 |
C4::Serials::ModSerialStatus( |
603 |
$expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate, |
604 |
$publisheddate, '1', 'an useless note' |
605 |
); |
606 |
is( $serialsByStatus[0]->{note}, $expected_serial->{note}, "note not passed through if not supposed to" ); |
607 |
|
608 |
}; |
609 |
|
610 |
subtest "NewSubscription|ModSubscription" => sub { |
611 |
plan tests => 4; |
612 |
my $subscriptionid = NewSubscription( |
613 |
"", "", "", "", $budget_id, $biblionumber, |
614 |
'2013-01-01', $frequency_id, "", "", "", |
615 |
"", "", "", "", "", "", |
616 |
1, $notes, "", '2013-01-01', "", $pattern_id, |
617 |
"", "", 0, $internalnotes, 0, |
618 |
"", "", 0, "", '2013-12-31', 0 |
619 |
); |
620 |
ok( $subscriptionid, "Sending empty string instead of undef to reflect use of the interface" ); |
621 |
|
622 |
my $subscription = Koha::Subscriptions->find($subscriptionid); |
623 |
my $serials = Koha::Serials->search( { subscriptionid => $subscriptionid } ); |
624 |
is( $serials->count, 1, "NewSubscription created a first serial" ); |
625 |
|
626 |
my $biblio_2 = $builder->build_sample_biblio; |
627 |
my $subscription_info = $subscription->unblessed; |
628 |
$subscription_info->{biblionumber} = $biblio_2->biblionumber; |
629 |
ModSubscription( |
630 |
@$subscription_info{ |
631 |
qw( |
632 |
librarian branchcode aqbooksellerid cost aqbudgetid startdate |
633 |
periodicity firstacquidate irregularity numberpattern locale |
634 |
numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2 |
635 |
innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes |
636 |
letter manualhistory internalnotes serialsadditems staffdisplaycount |
637 |
opacdisplaycount graceperiod location enddate subscriptionid |
638 |
skip_serialseq |
639 |
) |
640 |
} |
641 |
); |
642 |
|
643 |
$serials = Koha::Serials->search( { subscriptionid => $subscriptionid } ); |
644 |
is( $serials->count, 1, "Still only one serial" ); |
645 |
is( |
646 |
$serials->next->biblionumber, $biblio_2->biblionumber, |
647 |
'ModSubscription should have updated serial.biblionumber' |
648 |
); |
649 |
}; |
650 |
|
651 |
subtest "_numeration" => sub { |
652 |
|
653 |
plan tests => 8; |
654 |
|
655 |
my $s = C4::Serials::_numeration( 0, 'monthname', 'cat' ); |
656 |
is( $s, "gener" ); |
657 |
$s = C4::Serials::_numeration( 0, 'monthname', 'es' ); |
658 |
is( $s, "enero" ); |
659 |
$s = C4::Serials::_numeration( 0, 'monthname', 'fr' ); |
660 |
is( $s, "janvier" ); |
661 |
|
662 |
$s = C4::Serials::_numeration( 0, 'monthabrv', 'cat' ); |
663 |
is( $s, "de gen." ); |
664 |
$s = C4::Serials::_numeration( 0, 'monthabrv', 'es' ); |
665 |
like( $s, qr{^ene\.?} ); |
666 |
$s = C4::Serials::_numeration( 0, 'monthabrv', 'fr' ); |
667 |
is( $s, "janv." ); |
668 |
|
669 |
my $translations = { |
670 |
seasons => [ 'Spring', 'Summer', 'Fall', 'Winter' ], |
671 |
seasonsabrv => [ 'Spr', 'Sum', 'Fal', 'Win' ], |
672 |
}; |
673 |
|
674 |
$s = C4::Serials::_numeration( 0, 'season', 'en', $translations ); |
675 |
is( $s, "Spring" ); |
676 |
$s = C4::Serials::_numeration( 0, 'seasonabrv', 'en', $translations ); |
677 |
is( $s, "Spr" ); |
678 |
}; |
679 |
|
680 |
subtest "GetSeasonsTranslations" => sub { |
681 |
|
682 |
plan tests => 8; |
683 |
|
684 |
my @seasons = qw( Printemps Été Automne Hiver ); |
685 |
my @seasonsabrv = qw( Pri Été Aut Hiv ); |
686 |
|
687 |
my $dir = C4::Context->config('intranetdir') . '/misc/translator/po/'; |
688 |
my $fh = File::Temp->new( DIR => $dir, SUFFIX => '-staff-prog.po' ); |
689 |
my $filename = $fh->filename; |
690 |
|
691 |
my $txt = ' |
692 |
#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530 |
693 |
#, c-format |
694 |
msgid "Spring" |
695 |
msgstr "Printemps" |
696 |
|
697 |
#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530 |
698 |
#, c-format |
699 |
msgid "Summer" |
700 |
msgstr "Été" |
701 |
|
702 |
#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530 |
703 |
#, c-format |
704 |
msgid "Fall" |
705 |
msgstr "Automne" |
706 |
|
707 |
#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt:530 |
708 |
#, c-format |
709 |
msgid "Winter" |
710 |
msgstr "Hiver" |
711 |
|
712 |
#: koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt:208 |
713 |
#: koha-tmpl/intranet-tmpl/prog/en/modules/admin/searchengine/elasticsearch/mappings.tt:210 |
714 |
#, c-format |
715 |
msgid "Sum" |
716 |
msgstr "Total" |
717 |
|
718 |
#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-collection.tt:248 |
719 |
#: koha-tmpl/intranet-tmpl/prog/en/modules/serials/showpredictionpattern.tt:43 |
720 |
#, c-format |
721 |
msgid "" |
722 |
"%s %sSpring%s %s %sSummer%s %s %sFall%s %s %sWinter%s %s %sSpr%s %s %sSum%s " |
723 |
"%s %sFal%s %s %sWin%s %s %s %s " |
724 |
msgstr "" |
725 |
"%s %sPrintemps%s %s %sÉté%s %s %sAutomne%s %s %sHiver%s %s %sPri%s %s %sÉté" |
726 |
"%s %s %sAut%s %s %sHiv%s %s %s %s " |
727 |
'; |
728 |
|
729 |
print $fh encode( 'utf-8', $txt ); |
730 |
close($fh); |
731 |
|
732 |
my $translations = GetSeasonsTranslations( 1, 1, $filename =~ s/($dir|-staff-prog.po)//gr ); |
733 |
|
734 |
for my $idx ( 0 .. $#{ $translations->{seasons} } ) { |
735 |
is( $translations->{seasons}->[$idx], $seasons[$idx] ); |
736 |
is( $translations->{seasonsabrv}->[$idx], $seasonsabrv[$idx] ); |
737 |
} |
738 |
}; |