View | Details | Raw Unified | Return to bug 17964
Collapse All | Expand All

(-)a/t/db_dependent/Letters/TemplateToolkit.t (-39 / +133 lines)
Lines 25-30 use MARC::Record; Link Here
25
25
26
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
27
27
28
use C4::Circulation;
28
use C4::Letters;
29
use C4::Letters;
29
use C4::Members;
30
use C4::Members;
30
use C4::Biblio;
31
use C4::Biblio;
Lines 284-308 $prepared_letter = GetPreparedLetter( Link Here
284
is( $prepared_letter->{content}, $modification->id(), 'Patron modification object used correctly' );
285
is( $prepared_letter->{content}, $modification->id(), 'Patron modification object used correctly' );
285
286
286
subtest 'regression tests' => sub {
287
subtest 'regression tests' => sub {
287
    plan tests => 2;
288
    plan tests => 3;
288
289
289
    my $library = $builder->build( { source => 'Branch' } );
290
    my $library = $builder->build( { source => 'Branch' } );
290
    my $patron  = $builder->build( { source => 'Borrower' } );
291
    my $patron  = $builder->build( { source => 'Borrower' } );
291
    my $biblio = Koha::Biblio->new({title => 'Test Biblio'})->store->unblessed;
292
    my $biblio1 = Koha::Biblio->new({title => 'Test Biblio 1'})->store->unblessed;
292
    my $biblioitem = Koha::Biblioitem->new({biblionumber => $biblio->{biblionumber}})->store()->unblessed;
293
    my $biblioitem1 = Koha::Biblioitem->new({biblionumber => $biblio1->{biblionumber}})->store()->unblessed;
293
    my $item1 = Koha::Item->new(
294
    my $item1 = Koha::Item->new(
294
        {
295
        {
295
            biblionumber     => $biblio->{biblionumber},
296
            biblionumber     => $biblio1->{biblionumber},
296
            biblioitemnumber => $biblioitem->{biblioitemnumber},
297
            biblioitemnumber => $biblioitem1->{biblioitemnumber},
298
            barcode          => 'a_t_barcode',
299
            homebranch       => $library->{branchcode},
300
            holdingbranch    => $library->{branchcode},
301
            itype            => 'BK',
297
        }
302
        }
298
    )->store->unblessed;
303
    )->store->unblessed;
304
    my $biblio2 = Koha::Biblio->new({title => 'Test Biblio 2'})->store->unblessed;
305
    my $biblioitem2 = Koha::Biblioitem->new({biblionumber => $biblio2->{biblionumber}})->store()->unblessed;
299
    my $item2 = Koha::Item->new(
306
    my $item2 = Koha::Item->new(
300
        {
307
        {
301
            biblionumber     => $biblio->{biblionumber},
308
            biblionumber     => $biblio2->{biblionumber},
302
            biblioitemnumber => $biblioitem->{biblioitemnumber},
309
            biblioitemnumber => $biblioitem2->{biblioitemnumber},
310
            barcode          => 'another_t_barcode',
311
            homebranch       => $library->{branchcode},
312
            holdingbranch    => $library->{branchcode},
313
            itype            => 'BK',
303
        }
314
        }
304
    )->store->unblessed;
315
    )->store->unblessed;
305
316
317
    C4::Context->_new_userenv('xxx');
318
    C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Midway Public Library', '', '', '');
319
306
    subtest 'ACQ_NOTIF_ON_RECEIV ' => sub {
320
    subtest 'ACQ_NOTIF_ON_RECEIV ' => sub {
307
        plan tests => 1;
321
        plan tests => 1;
308
        my $code = 'ACQ_NOTIF_ON_RECEIV';
322
        my $code = 'ACQ_NOTIF_ON_RECEIV';
Lines 310-325 subtest 'regression tests' => sub { Link Here
310
        my $order = $builder->build({ source => 'Aqorder' });
324
        my $order = $builder->build({ source => 'Aqorder' });
311
325
312
        my $template = q|
326
        my $template = q|
313
            Dear <<borrowers.firstname>> <<borrowers.surname>>,
327
Dear <<borrowers.firstname>> <<borrowers.surname>>,
314
            The order <<aqorders.ordernumber>> (<<biblio.title>>) has been received.
328
The order <<aqorders.ordernumber>> (<<biblio.title>>) has been received.
315
            Your library.
329
Your library.
316
        |;
330
        |;
317
        my $params = { code => $code, branchcode => $branchcode, tables => { branches => $library, borrowers => $patron, biblio => $biblio, aqorders => $order } };
331
        my $params = { code => $code, branchcode => $branchcode, tables => { branches => $library, borrowers => $patron, biblio => $biblio1, aqorders => $order } };
318
        my $letter = process_letter( { template => $template, %$params });
332
        my $letter = process_letter( { template => $template, %$params });
319
        my $tt_template = q|
333
        my $tt_template = q|
320
            Dear [% borrower.firstname %] [% borrower.surname %],
334
Dear [% borrower.firstname %] [% borrower.surname %],
321
            The order [% order.ordernumber %] ([% biblio.title %]) has been received.
335
The order [% order.ordernumber %] ([% biblio.title %]) has been received.
322
            Your library.
336
Your library.
323
        |;
337
        |;
324
        my $tt_letter = process_letter( { template => $tt_template, %$params });
338
        my $tt_letter = process_letter( { template => $tt_template, %$params });
325
339
Lines 332-352 subtest 'regression tests' => sub { Link Here
332
        my $branchcode = $library->{branchcode};
346
        my $branchcode = $library->{branchcode};
333
347
334
        my $template = q|
348
        my $template = q|
335
            <<borrowers.firstname>> <<borrowers.surname>> (<<borrowers.cardnumber>>)
349
<<borrowers.firstname>> <<borrowers.surname>> (<<borrowers.cardnumber>>)
336
350
337
            Your request for an article from <<biblio.title>> (<<items.barcode>>) has been canceled for the following reason:
351
Your request for an article from <<biblio.title>> (<<items.barcode>>) has been canceled for the following reason:
338
352
339
            <<article_requests.notes>>
353
<<article_requests.notes>>
340
354
341
            Article requested:
355
Article requested:
342
            Title: <<article_requests.title>>
356
Title: <<article_requests.title>>
343
            Author: <<article_requests.author>>
357
Author: <<article_requests.author>>
344
            Volume: <<article_requests.volume>>
358
Volume: <<article_requests.volume>>
345
            Issue: <<article_requests.issue>>
359
Issue: <<article_requests.issue>>
346
            Date: <<article_requests.date>>
360
Date: <<article_requests.date>>
347
            Pages: <<article_requests.pages>>
361
Pages: <<article_requests.pages>>
348
            Chapters: <<article_requests.chapters>>
362
Chapters: <<article_requests.chapters>>
349
            Notes: <<article_requests.patron_notes>>
363
Notes: <<article_requests.patron_notes>>
350
        |;
364
        |;
351
        reset_template( { template => $template, code => $code, module => 'circulation' } );
365
        reset_template( { template => $template, code => $code, module => 'circulation' } );
352
        my $article_request = $builder->build({ source => 'ArticleRequest' });
366
        my $article_request = $builder->build({ source => 'ArticleRequest' });
Lines 354-374 subtest 'regression tests' => sub { Link Here
354
        my $letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
368
        my $letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
355
369
356
        my $tt_template = q|
370
        my $tt_template = q|
357
            [% borrower.firstname %] [% borrower.surname %] ([% borrower.cardnumber %])
371
[% borrower.firstname %] [% borrower.surname %] ([% borrower.cardnumber %])
358
372
359
            Your request for an article from [% biblio.title %] ([% item.barcode %]) has been canceled for the following reason:
373
Your request for an article from [% biblio.title %] ([% item.barcode %]) has been canceled for the following reason:
360
374
361
            [% article_request.notes %]
375
[% article_request.notes %]
362
376
363
            Article requested:
377
Article requested:
364
            Title: [% article_request.title %]
378
Title: [% article_request.title %]
365
            Author: [% article_request.author %]
379
Author: [% article_request.author %]
366
            Volume: [% article_request.volume %]
380
Volume: [% article_request.volume %]
367
            Issue: [% article_request.issue %]
381
Issue: [% article_request.issue %]
368
            Date: [% article_request.date %]
382
Date: [% article_request.date %]
369
            Pages: [% article_request.pages %]
383
Pages: [% article_request.pages %]
370
            Chapters: [% article_request.chapters %]
384
Chapters: [% article_request.chapters %]
371
            Notes: [% article_request.patron_notes %]
385
Notes: [% article_request.patron_notes %]
372
        |;
386
        |;
373
        reset_template( { template => $tt_template, code => $code, module => 'circulation' } );
387
        reset_template( { template => $tt_template, code => $code, module => 'circulation' } );
374
        Koha::ArticleRequests->find( $article_request->{id} )->cancel;
388
        Koha::ArticleRequests->find( $article_request->{id} )->cancel;
Lines 376-381 subtest 'regression tests' => sub { Link Here
376
        is( $tt_letter->content, $letter->content, 'Compare AR_* notices' );
390
        is( $tt_letter->content, $letter->content, 'Compare AR_* notices' );
377
        isnt( $tt_letter->message_id, $letter->message_id, 'Comparing AR_* notices should compare 2 different messages' );
391
        isnt( $tt_letter->message_id, $letter->message_id, 'Comparing AR_* notices should compare 2 different messages' );
378
    };
392
    };
393
394
    subtest 'CHECKOUT+CHECKIN' => sub {
395
        plan tests => 4;
396
397
        my $checkout_code = 'CHECKOUT';
398
        my $checkin_code = 'CHECKIN';
399
400
        my $dbh = C4::Context->dbh;
401
        # Enable notification for CHECKOUT - Things are hardcoded here but should work with default data
402
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 6 );
403
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
404
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
405
        # Enable notification for CHECKIN - Things are hardcoded here but should work with default data
406
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 5 );
407
        $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
408
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
409
410
        # historic syntax
411
        my $checkout_template = q|
412
The following items have been checked out:
413
----
414
<<biblio.title>>
415
----
416
Thank you for visiting <<branches.branchname>>.
417
|;
418
        reset_template( { template => $checkout_template, code => $checkout_code, module => 'circulation' } );
419
        my $checkin_template = q|
420
The following items have been checkin out:
421
----
422
<<biblio.title>>
423
----
424
Thank you for visiting <<branches.branchname>>.
425
|;
426
        reset_template( { template => $checkin_template, code => $checkin_code, module => 'circulation' } );
427
428
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
429
        my $first_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
430
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
431
        my $second_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
432
433
        AddReturn( $item1->{barcode} );
434
        my $first_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
435
        AddReturn( $item2->{barcode} );
436
        my $second_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
437
438
        Koha::Notice::Messages->delete;
439
440
        # TT syntax
441
        $checkout_template = q|
442
The following items have been checked out:
443
----
444
[% biblio.title %]
445
----
446
Thank you for visiting [% branch.branchname %].
447
|;
448
        reset_template( { template => $checkout_template, code => $checkout_code, module => 'circulation' } );
449
        $checkin_template = q|
450
The following items have been checkin out:
451
----
452
[% biblio.title %]
453
----
454
Thank you for visiting [% branch.branchname %].
455
|;
456
        reset_template( { template => $checkin_template, code => $checkin_code, module => 'circulation' } );
457
458
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
459
        my $first_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
460
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
461
        my $second_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
462
463
        AddReturn( $item1->{barcode} );
464
        my $first_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
465
        AddReturn( $item2->{barcode} );
466
        my $second_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
467
468
        is( $first_checkout_tt_letter->content, $first_checkout_letter->content, );
469
        is( $second_checkout_tt_letter->content, $second_checkout_letter->content, );
470
        is( $first_checkin_tt_letter->content, $first_checkin_letter->content, );
471
        is( $second_checkin_tt_letter->content, $second_checkin_letter->content, );
472
473
    };
379
};
474
};
380
475
381
sub reset_template {
476
sub reset_template {
382
- 

Return to bug 17964