Bug 35086: Add chunk_size option to elasticsearch configuration
[koha.git] / t / db_dependent / Serials.t
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 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 );
9 use C4::Serials::Frequency;
10 use C4::Serials::Numberpattern;
11 use C4::Biblio qw( AddBiblio GetMarcFromKohaField );
12 use C4::Budgets qw( AddBudgetPeriod AddBudget );
13 use C4::Items qw( AddItemFromMarc );
14 use Koha::Database;
15 use Koha::DateUtils qw( dt_from_string output_pref );
16 use Koha::Acquisition::Booksellers;
17 use t::lib::Mocks;
18 use t::lib::TestBuilder;
19 use Test::More tests => 54;
20
21 BEGIN {
22     use_ok('C4::Serials', 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 ));
23 }
24
25 my $schema = Koha::Database->new->schema;
26 $schema->storage->txn_begin;
27 my $dbh = C4::Context->dbh;
28
29 $dbh->do('DELETE FROM subscription');
30
31 my $builder = t::lib::TestBuilder->new();
32
33 # This could/should be used for all untested methods
34 my @methods = ('updateClaim');
35 can_ok('C4::Serials', @methods);
36
37 $dbh->do(q|UPDATE marc_subfield_structure SET value_builder="callnumber.pl" where kohafield="items.itemcallnumber" and frameworkcode=''|);
38
39 my $bookseller = Koha::Acquisition::Bookseller->new(
40     {
41         name => "my vendor",
42         address1 => "bookseller's address",
43         phone => "0123456",
44         active => 1
45     }
46 );
47
48 my ($biblionumber, $biblioitemnumber) = AddBiblio(MARC::Record->new, '');
49
50 my $bpid = AddBudgetPeriod({
51     budget_period_startdate   => '2015-01-01',
52     budget_period_enddate     => '2015-12-31',
53     budget_period_description => "budget desc"
54 });
55
56 my $budget_id = AddBudget({
57     budget_code        => "ABCD",
58     budget_amount      => "123.132",
59     budget_name        => "Périodiques",
60     budget_notes       => "This is a note",
61     budget_period_id   => $bpid
62 });
63
64 my $frequency_id = AddSubscriptionFrequency({ description => "Test frequency 1" });
65 my $pattern_id = AddSubscriptionNumberpattern({
66     label => 'Test numberpattern 1',
67     description => 'Description for numberpattern 1',
68     numberingmethod => '{X}',
69     label1 => q{},
70     add1 => 1,
71     every1 => 1,
72     every1 => 1,
73     numbering1 => 1,
74     whenmorethan1 => 1,
75 });
76
77 my $notes = "a\nnote\non\nseveral\nlines";
78 my $internalnotes = 'intnotes';
79 my $ccode = 'FIC';
80 my $subscriptionid = NewSubscription(
81     undef,
82     "",
83     undef,
84     undef,
85     $budget_id,
86     $biblionumber,
87     '2013-01-01',
88     $frequency_id,
89     undef,
90     undef,
91     undef,
92     undef,
93     undef,
94     undef,
95     undef,
96     undef,
97     undef,
98     1,
99     $notes,
100     undef,
101     '2013-01-01',
102     undef,
103     $pattern_id,
104     undef,
105     undef,
106     0,
107     $internalnotes,
108     0,
109     undef,
110     undef,
111     0,
112     undef,
113     '2013-12-31', 0,
114     undef,
115     undef,
116     undef,
117     $ccode
118 );
119
120 NewSubscription(
121     undef,
122     "",
123     undef,
124     undef,
125     $budget_id,
126     $biblionumber,
127     '2013-01-02',
128     $frequency_id,
129     undef,
130     undef,
131     undef,
132     undef,
133     undef,
134     undef,
135     undef,
136     undef,
137     undef,
138     1,
139     $notes,
140     undef,
141     '2013-01-02',
142     undef,
143     $pattern_id,
144     undef,
145     undef,
146     0,
147     $internalnotes,
148     0,
149     undef,
150     undef,
151     0,
152     undef,
153     '2013-12-31',
154     0,
155     undef,
156     undef,
157     undef,
158     $ccode
159 );
160
161 my $subscriptioninformation = GetSubscription( $subscriptionid );
162
163 is( $subscriptioninformation->{notes}, $notes, 'NewSubscription should set notes' );
164 is( $subscriptioninformation->{internalnotes}, $internalnotes, 'NewSubscription should set internalnotes' );
165 is( $subscriptioninformation->{ccode}, $ccode, 'NewSubscription should set ccode' );
166
167 my $subscription_history = C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid);
168 is( $subscription_history->{opacnote}, undef, 'NewSubscription should not set subscriptionhistory opacnotes' );
169 is( $subscription_history->{librariannote}, undef, 'NewSubscription should not set subscriptionhistory librariannotes' );
170
171 my @subscriptions = SearchSubscriptions({string => $subscriptioninformation->{bibliotitle}, orderby => 'title' });
172 isa_ok( \@subscriptions, 'ARRAY' );
173
174 @subscriptions = SearchSubscriptions({ issn => $subscriptioninformation->{issn}, orderby => 'title' });
175 isa_ok( \@subscriptions, 'ARRAY' );
176
177 @subscriptions = SearchSubscriptions({ ean => $subscriptioninformation->{ean}, orderby => 'title' });
178 isa_ok( \@subscriptions, 'ARRAY' );
179
180 @subscriptions = SearchSubscriptions({ biblionumber => $subscriptioninformation->{bibnum}, orderby => 'title' });
181 isa_ok( \@subscriptions, 'ARRAY' );
182
183 @subscriptions = SearchSubscriptions({});
184 is(
185     @subscriptions,
186     2,
187     'SearchSubscriptions returned the expected number of subscriptions when results_limit is not set'
188 );
189
190 @subscriptions = SearchSubscriptions({}, { results_limit => 1 });
191 is(
192     @subscriptions,
193     1,
194     'SearchSubscriptions returned only one subscription when results_limit is set to "1"'
195 );
196
197 my $frequency = GetSubscriptionFrequency($subscriptioninformation->{periodicity});
198 my $old_frequency;
199 if (not $frequency->{unit}) {
200     $old_frequency = $frequency->{id};
201     $frequency->{unit} = "month";
202     $frequency->{unitsperissue} = 1;
203     $frequency->{issuesperunit} = 1;
204     $frequency->{description} = "Frequency created by t/db_dependant/Serials.t";
205     $subscriptioninformation->{periodicity} = AddSubscriptionFrequency($frequency);
206     $subscriptioninformation->{serialsadditems} = 1;
207     $subscriptioninformation->{ccode} = 'NFIC';
208
209     ModSubscription( @$subscriptioninformation{qw(
210         librarian branchcode aqbooksellerid cost aqbudgetid startdate
211         periodicity firstacquidate irregularity numberpattern locale
212         numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2
213         innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes
214         letter manualhistory internalnotes serialsadditems staffdisplaycount
215         opacdisplaycount graceperiod location enddate subscriptionid
216         skip_serialseq itemtype previousitemtype mana_id ccode
217     )} );
218 }
219 my $expirationdate = GetExpirationDate($subscriptionid) ;
220 ok( $expirationdate, "expiration date is not NULL" );
221
222 # Check ModSubscription has updated the ccode
223 my $subscriptioninformation2 = GetSubscription($subscriptionid);
224 is( $subscriptioninformation2->{ccode}, 'NFIC', 'ModSubscription should update ccode' );
225
226 ok(C4::Serials::GetSubscriptionHistoryFromSubscriptionId($subscriptionid), 'test getting history from sub-scription');
227
228 my ($serials_count, @serials) = GetSerials($subscriptionid);
229 ok($serials_count > 0, 'Subscription has at least one serial');
230 my $serial = $serials[0];
231
232 isa_ok(C4::Serials::GetSerialInformation($serial->{serialid}), 'HASH', 'test getting Serial Information');
233
234 subtest 'Values should not be erased on editing' => sub {
235
236     plan tests => 1;
237
238     my $biblio = $builder->build_sample_biblio();
239     my $biblionumber = $biblio->biblionumber;
240     my ( $icn_tag, $icn_sf ) = GetMarcFromKohaField( 'items.itemcallnumber' );
241     my ( $it_tag, $it_sf )   = GetMarcFromKohaField( 'items.itype' );
242
243     my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype};
244     my $itemcallnumber = 'XXXmy itemcallnumberXXX';
245
246     my $item_record    = MARC::Record->new;
247
248     $item_record->append_fields(
249         MARC::Field->new( '080', '', '', "a" => "default" ),
250         MARC::Field->new(
251             $icn_tag, '', '',
252             $icn_sf => $itemcallnumber,
253             $it_sf  => $itemtype
254         )
255     );
256     my ( undef, undef, $itemnumber ) = C4::Items::AddItemFromMarc( $item_record, $biblionumber );
257     my $serialid = C4::Serials::NewIssue( "serialseq", $subscriptionid, $biblionumber,
258                                           1, undef, undef, "publisheddatetext", "notes", "routingnotes" );
259     C4::Serials::AddItem2Serial( $serialid, $itemnumber );
260     my $serial_info = C4::Serials::GetSerialInformation($serialid);
261     my ($itemcallnumber_info) = grep { $_->{kohafield} eq 'items.itemcallnumber' }
262                                      @{ $serial_info->{items}[0]->{iteminformation} };
263     like( $itemcallnumber_info->{marc_value}, qr|value="$itemcallnumber"| );
264 };
265
266 # Delete created frequency
267 if ($old_frequency) {
268     my $freq_to_delete = $subscriptioninformation->{periodicity};
269     $subscriptioninformation->{periodicity} = $old_frequency;
270
271     ModSubscription( @$subscriptioninformation{qw(
272         librarian branchcode aqbooksellerid cost aqbudgetid startdate
273         periodicity firstacquidate irregularity numberpattern locale
274         numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2
275         innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes
276         letter manualhistory internalnotes serialsadditems staffdisplaycount
277         opacdisplaycount graceperiod location enddate subscriptionid
278         skip_serialseq
279     )} );
280
281     DelSubscriptionFrequency($freq_to_delete);
282 }
283
284 # Test calling subs without parameters
285 is(C4::Serials::AddItem2Serial(), undef, 'test adding item to serial');
286 is(C4::Serials::GetFullSubscription(), undef, 'test getting full subscription');
287 is(C4::Serials::PrepareSerialsData(), undef, 'test preparing serial data');
288
289 subtest 'GetSubscriptionsFromBiblionumber' => sub {
290     plan tests => 4;
291
292     is( C4::Serials::GetSubscriptionsFromBiblionumber(),
293         undef, 'test getting subscriptions form biblio number' );
294
295     my $subscriptions = C4::Serials::GetSubscriptionsFromBiblionumber($biblionumber);
296     ModSubscriptionHistory( $subscriptions->[0]->{subscriptionid},
297         undef, undef, $notes, $notes, $notes );
298
299     $subscriptions = C4::Serials::GetSubscriptionsFromBiblionumber($biblionumber);
300     is( $subscriptions->[0]->{opacnote}, $notes,
301         'GetSubscriptionsFromBiblionumber should have returned the opacnote as it is in DB, ie. without br tags'
302     );
303     is( $subscriptions->[0]->{recievedlist}, $notes,
304         'GetSubscriptionsFromBiblionumber should have returned recievedlist as it is in DB, ie. without br tags'
305     );
306     is( $subscriptions->[0]->{missinglist}, $notes,
307         'GetSubscriptionsFromBiblionumber should have returned missinglist as it is in DB, ie. without br tags'
308     );
309 };
310
311 is(C4::Serials::GetSerials(), undef, 'test getting serials when you enter nothing');
312 is(C4::Serials::GetSerials2(), undef, 'test getting serials when you enter nothing');
313
314 is(C4::Serials::GetLatestSerials(), undef, 'test getting lastest serials');
315
316 is(C4::Serials::GetNextSeq(), undef, 'test getting next seq when you enter nothing');
317
318 is(C4::Serials::GetSeq(), undef, 'test getting seq when you enter nothing');
319
320 is(C4::Serials::CountSubscriptionFromBiblionumber(), undef, 'test counting subscription when nothing is entered');
321
322 is(C4::Serials::ModSubscriptionHistory(), undef, 'test modding subscription history');
323
324 is(C4::Serials::ModSerialStatus(),undef, 'test modding serials');
325
326 is(C4::Serials::findSerialsByStatus(), 0, 'test finding serial by status with no parameters');
327
328 is(C4::Serials::NewIssue(), undef, 'test getting 0 when nothing is entered');
329
330 is(C4::Serials::HasSubscriptionStrictlyExpired(), undef, 'test if the subscriptions has expired');
331 is(C4::Serials::HasSubscriptionExpired(), undef, 'test if the subscriptions has expired');
332
333 is(C4::Serials::GetLateOrMissingIssues(), undef, 'test getting last or missing issues');
334
335 subtest 'test_updateClaim' => sub {
336     plan tests => 11;
337
338     my $today = output_pref({ dt => dt_from_string, dateonly => 1 });
339     # Given ... nothing much
340     # When ... Then ...
341     my $result_0 = C4::Serials::updateClaim(undef);
342     is($result_0, undef, 'Got the expected undef from update claim with nothin');
343
344     # Given ... 3 serial. 2 of them updated.
345     my $claimdate_1   = dt_from_string('2001-01-13'); # arbitrary date some time in the past.
346     my $claim_count_1 = 5;
347     my $biblio = $builder->build_sample_biblio;
348     my $serial1 = $builder->build_object(
349         {
350             class => 'Koha::Serials',
351             value => {
352                 serialseq      => 'serialseq',
353                 subscriptionid => $subscriptionid,
354                 status         => 3,
355                 biblionumber   => $biblio->biblionumber,
356                 claimdate      => $claimdate_1,
357                 claims_count   => $claim_count_1,
358             }
359         }
360     );
361     my $serial2 = $builder->build_object(
362         {
363             class => 'Koha::Serials',
364             value => {
365                 serialseq      => 'serialseq',
366                 subscriptionid => $subscriptionid,
367                 status         => 3,
368                 biblionumber   => $biblio->biblionumber,
369                 claimdate      => $claimdate_1,
370                 claims_count   => $claim_count_1,
371             }
372         }
373     );
374     my $serial3 = $builder->build_object(
375         {
376             class => 'Koha::Serials',
377             value => {
378                 serialseq      => 'serialseq',
379                 subscriptionid => $subscriptionid,
380                 status         => 3,
381                 biblionumber   => $biblio->biblionumber,
382                 claimdate      => $claimdate_1,
383                 claims_count   => $claim_count_1,
384             }
385         }
386     );
387
388     # When ...
389     my $result_1 = C4::Serials::updateClaim([$serial1->serialid, $serial2->serialid]);
390
391     # Then ...
392     is($result_1, 2, 'Got the expected 2 from update claim with 2 serial ids');
393
394     my @late_or_missing_issues_1_0 = C4::Serials::GetLateOrMissingIssues(undef, $serial1->serialid);
395     is(output_pref({str => $late_or_missing_issues_1_0[0]->{claimdate}, dateonly => 1}), $today, 'Got the expected first different claim date from update claim');
396     is($late_or_missing_issues_1_0[0]->{claims_count}, $claim_count_1+1, 'Got the expected first claim count from update claim');
397     is($late_or_missing_issues_1_0[0]->{status}, 7, 'Got the expected first claim status from update claim');
398
399     my @late_or_missing_issues_1_1 = C4::Serials::GetLateOrMissingIssues(undef, $serial2->serialid);
400     is(output_pref({str => $late_or_missing_issues_1_1[0]->{claimdate}, dateonly => 1}), $today, 'Got the expected second different claim date from update claim');
401     is($late_or_missing_issues_1_1[0]->{claims_count}, $claim_count_1+1, 'Got the expected second claim count from update claim');
402     is($late_or_missing_issues_1_1[0]->{status}, 7, 'Got the expected second claim status from update claim');
403
404     my @late_or_missing_issues_1_2 = C4::Serials::GetLateOrMissingIssues(undef, $serial3->serialid);
405     is(output_pref({str => $late_or_missing_issues_1_2[0]->{claimdate}, dateonly => 1}), output_pref({ dt => $claimdate_1, dateonly => 1}), 'Got the expected unchanged claim date from update claim');
406     is($late_or_missing_issues_1_2[0]->{claims_count}, $claim_count_1, 'Got the expected unchanged claim count from update claim');
407     is($late_or_missing_issues_1_2[0]->{status}, 3, 'Got the expected unchanged claim status from update claim');
408 };
409
410 is(C4::Serials::check_routing(), undef, 'test checking route');
411 is(C4::Serials::check_routing($subscriptionid), 0, 'There should not have any routing list for the subscription');
412 # TODO really test this check_routing subroutine
413
414 is(C4::Serials::addroutingmember(),undef, 'test adding route member');
415
416
417 # Unit tests for statuses management (Bug 11689)
418 $subscriptionid = NewSubscription(
419     undef,      "",     undef, undef, $budget_id, $biblionumber,
420     '2013-01-01', $frequency_id, undef, undef,  undef,
421     undef,      undef,  undef, undef, undef, undef,
422     1,          $notes,undef, '2013-01-01', undef, $pattern_id,
423     undef,       undef,  0,    $internalnotes,  0,
424     undef, undef, 0,          undef,         '2013-12-31', 0
425 );
426 my $total_issues;
427 ( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
428 is( $total_issues, 1, "NewSubscription created a first serial" );
429 is( @serials, 1, "GetSerials returns the serial" );
430 my $subscription = C4::Serials::GetSubscription($subscriptionid);
431 my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
432 ( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
433 my $publisheddate = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
434 ( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
435 $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity});
436 my $nextpublisheddate = C4::Serials::GetNextDate($subscription, $publisheddate, $frequency, 1);
437 my @statuses = qw( 2 2 3 3 3 3 3 4 4 41 42 43 44 5 );
438 # Add 14 serials
439 my $counter = 0;
440 for my $status ( @statuses ) {
441     my $serialseq = "No.".$counter;
442     my ( $expected_serial ) = GetSerials2( $subscriptionid, [1] );
443     C4::Serials::ModSerialStatus( $expected_serial->{serialid}, $serialseq, $publisheddate, $publisheddate, $publisheddate, $statuses[$counter], 'an useless note' );
444     $counter++;
445 }
446 # 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
447 my @serialsByStatus = C4::Serials::findSerialsByStatus(2,$subscriptionid);
448 is(@serialsByStatus,2,"findSerialsByStatus returns all serials with chosen status");
449 ( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid );
450 is( $total_issues, @statuses + 1, "GetSerials returns total_issues" );
451 my @arrived_missing = map { my $status = $_->{status}; ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? $_ : () } @serials;
452 my @others = map { my $status = $_->{status}; ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? () : $_ } @serials;
453 is( @arrived_missing, 5, "GetSerials returns 5 arrived/missing by default" );
454 is( @others, 6, "GetSerials returns all serials not arrived and not missing" );
455
456 ( $total_issues, @serials ) = C4::Serials::GetSerials( $subscriptionid, 10 );
457 is( $total_issues, @statuses + 1, "GetSerials returns total_issues" );
458 @arrived_missing = map { my $status = $_->{status}; ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? $_ : () } @serials;
459 @others = map { my $status = $_->{status}; ( grep { /^$status$/ } qw( 2 4 41 42 43 44 5 ) ) ? () : $_ } @serials;
460 is( @arrived_missing, 9, "GetSerials returns all arrived/missing if count given" );
461 is( @others, 6, "GetSerials returns all serials not arrived and not missing if count given" );
462
463 $subscription = C4::Serials::GetSubscription($subscriptionid); # Retrieve the updated subscription
464
465 my @serialseqs;
466 for my $am ( @arrived_missing ) {
467     if ( grep {/^$am->{status}$/} qw( 4 41 42 43 44 ) ) {
468         push @serialseqs, $am->{serialseq}
469     } elsif ( grep {/^$am->{status}$/} qw( 5 ) ) {
470         push @serialseqs, 'not issued ' . $am->{serialseq};
471     }
472 }
473 is( $subscription->{missinglist}, join('; ', @serialseqs), "subscription missinglist is updated after ModSerialStatus" );
474
475 subtest "Do not generate an expected if one already exists" => sub {
476     plan tests => 2;
477     my ($expected_serial) = GetSerials2( $subscriptionid, [1] );
478
479     #Find serialid for serial with status Expected
480     my $serialexpected = ( C4::Serials::findSerialsByStatus( 1, $subscriptionid ) )[0];
481
482     #delete serial with status Expected
483     C4::Serials::ModSerialStatus( $serialexpected->{serialid}, $serialexpected->{serialseq}, $publisheddate, $publisheddate, $publisheddate, '1', 'an useless note' );
484     @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid );
485     is( @serialsByStatus, 1, "ModSerialStatus delete corectly serial expected and create another if not exist" );
486
487     # add 1 serial with status=Expected 1
488     C4::Serials::ModSerialStatus( $expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate, $publisheddate, '1', 'an useless note' );
489
490     #Now we have two serials it have status expected
491     #put status delete for last serial
492     C4::Serials::ModSerialStatus( $serialexpected->{serialid}, $serialexpected->{serialseq}, $publisheddate, $publisheddate, $publisheddate, '1', 'an useless note' );
493
494     #try if create or not another serial with status is expected
495     @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid );
496     is( @serialsByStatus, 1, "ModSerialStatus delete corectly serial expected and not create another if exists" );
497 };
498
499 subtest "PreserveSerialNotes preference" => sub {
500     plan tests => 2;
501     my ($expected_serial) = GetSerials2( $subscriptionid, [1] );
502
503     t::lib::Mocks::mock_preference( 'PreserveSerialNotes', 1 );
504
505     C4::Serials::ModSerialStatus( $expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate, $publisheddate, '1', 'an useless note' );
506     @serialsByStatus = C4::Serials::findSerialsByStatus( 1, $subscriptionid );
507     is( $serialsByStatus[0]->{note},$expected_serial->{note}, "note passed through if supposed to");
508
509     t::lib::Mocks::mock_preference( 'PreserveSerialNotes', 0 );
510     $expected_serial = $serialsByStatus[0];
511     C4::Serials::ModSerialStatus( $expected_serial->{serialid}, 'NO.20', $publisheddate, $publisheddate, $publisheddate, '1', 'an useless note' );
512     is( $serialsByStatus[0]->{note},$expected_serial->{note}, "note not passed through if not supposed to");
513
514 };
515
516 subtest "NewSubscription|ModSubscription" => sub {
517     plan tests => 4;
518     my $subscriptionid = NewSubscription(
519         "",      "",     "", "", $budget_id, $biblionumber,
520         '2013-01-01', $frequency_id, "", "",  "",
521         "",      "",  "", "", "", "",
522         1,          $notes,"", '2013-01-01', "", $pattern_id,
523         "",       "",  0,    $internalnotes,  0,
524         "", "", 0,          "",         '2013-12-31', 0
525     );
526     ok($subscriptionid, "Sending empty string instead of undef to reflect use of the interface");
527
528     my $subscription = Koha::Subscriptions->find($subscriptionid);
529     my $serials = Koha::Serials->search({ subscriptionid => $subscriptionid });
530     is( $serials->count, 1, "NewSubscription created a first serial" );
531
532     my $biblio_2 = $builder->build_sample_biblio;
533     my $subscription_info = $subscription->unblessed;
534     $subscription_info->{biblionumber} = $biblio_2->biblionumber;
535     ModSubscription( @$subscription_info{qw(
536         librarian branchcode aqbooksellerid cost aqbudgetid startdate
537         periodicity firstacquidate irregularity numberpattern locale
538         numberlength weeklength monthlength lastvalue1 innerloop1 lastvalue2
539         innerloop2 lastvalue3 innerloop3 status biblionumber callnumber notes
540         letter manualhistory internalnotes serialsadditems staffdisplaycount
541         opacdisplaycount graceperiod location enddate subscriptionid
542         skip_serialseq
543     )} );
544
545     $serials = Koha::Serials->search({ subscriptionid => $subscriptionid });
546     is( $serials->count, 1, "Still only one serial" );
547     is( $serials->next->biblionumber, $biblio_2->biblionumber, 'ModSubscription should have updated serial.biblionumber');
548 };
549
550 subtest "_numeration" => sub {
551
552     plan tests => 6;
553
554     my $s = C4::Serials::_numeration(0, 'monthname', 'cat');
555     is( $s, "gener" );
556     $s = C4::Serials::_numeration(0, 'monthname', 'es');
557     is( $s, "enero" );
558     $s = C4::Serials::_numeration(0, 'monthname', 'fr');
559     is( $s, "janvier" );
560
561     $s = C4::Serials::_numeration(0, 'monthabrv', 'cat');
562     is( $s, "de gen." );
563     $s = C4::Serials::_numeration(0, 'monthabrv', 'es');
564     like( $s, qr{^ene\.?} );
565     $s = C4::Serials::_numeration(0, 'monthabrv', 'fr');
566     is( $s, "janv." );
567 };