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 333-380 subtest 'regression tests' => sub { Link Here
333
        my $branchcode = $library->{branchcode};
347
        my $branchcode = $library->{branchcode};
334
348
335
        my $template = q|
349
        my $template = q|
336
            <<borrowers.firstname>> <<borrowers.surname>> (<<borrowers.cardnumber>>)
350
<<borrowers.firstname>> <<borrowers.surname>> (<<borrowers.cardnumber>>)
337
351
338
            Your request for an article from <<biblio.title>> (<<items.barcode>>) has been canceled for the following reason:
352
Your request for an article from <<biblio.title>> (<<items.barcode>>) has been canceled for the following reason:
339
353
340
            <<article_requests.notes>>
354
<<article_requests.notes>>
341
355
342
            Article requested:
356
Article requested:
343
            Title: <<article_requests.title>>
357
Title: <<article_requests.title>>
344
            Author: <<article_requests.author>>
358
Author: <<article_requests.author>>
345
            Volume: <<article_requests.volume>>
359
Volume: <<article_requests.volume>>
346
            Issue: <<article_requests.issue>>
360
Issue: <<article_requests.issue>>
347
            Date: <<article_requests.date>>
361
Date: <<article_requests.date>>
348
            Pages: <<article_requests.pages>>
362
Pages: <<article_requests.pages>>
349
            Chapters: <<article_requests.chapters>>
363
Chapters: <<article_requests.chapters>>
350
            Notes: <<article_requests.patron_notes>>
364
Notes: <<article_requests.patron_notes>>
351
        |;
365
        |;
352
        reset_template( { template => $template, code => $code, module => 'circulation' } );
366
        reset_template( { template => $template, code => $code, module => 'circulation' } );
353
        Koha::ArticleRequests->find( $article_request->{id} )->cancel;
367
        Koha::ArticleRequests->find( $article_request->{id} )->cancel;
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 %] ([% items.barcode %]) has been canceled for the following reason:
373
Your request for an article from [% biblio.title %] ([% items.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 => $template, code => $code, module => 'circulation' } );
387
        reset_template( { template => $template, code => $code, module => 'circulation' } );
374
        Koha::ArticleRequests->find( $article_request->{id} )->cancel;
388
        Koha::ArticleRequests->find( $article_request->{id} )->cancel;
375
        my $tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
389
        my $tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
376
        is( $tt_letter->{content}, $letter->{content}, );
390
        is( $tt_letter->{content}, $letter->{content}, );
377
    };
391
    };
392
393
    subtest 'CHECKOUT+CHECKIN' => sub {
394
        plan tests => 4;
395
396
        my $checkout_code = 'CHECKOUT';
397
        my $checkin_code = 'CHECKIN';
398
399
        my $dbh = C4::Context->dbh;
400
        # Enable notification for CHECKOUT - Things are hardcoded here but should work with default data
401
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 6 );
402
        my $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
403
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
404
        # Enable notification for CHECKIN - Things are hardcoded here but should work with default data
405
        $dbh->do(q|INSERT INTO borrower_message_preferences( borrowernumber, message_attribute_id ) VALUES ( ?, ? )|, undef, $patron->{borrowernumber}, 5 );
406
        $borrower_message_preference_id = $dbh->last_insert_id(undef, undef, "borrower_message_preferences", undef);
407
        $dbh->do(q|INSERT INTO borrower_message_transport_preferences( borrower_message_preference_id, message_transport_type) VALUES ( ?, ? )|, undef, $borrower_message_preference_id, 'email' );
408
409
        # historic syntax
410
        my $checkout_template = q|
411
The following items have been checked out:
412
----
413
<<biblio.title>>
414
----
415
Thank you for visiting <<branches.branchname>>.
416
|;
417
        reset_template( { template => $checkout_template, code => $checkout_code, module => 'circulation' } );
418
        my $checkin_template = q|
419
The following items have been checkin out:
420
----
421
<<biblio.title>>
422
----
423
Thank you for visiting <<branches.branchname>>.
424
|;
425
        reset_template( { template => $checkin_template, code => $checkin_code, module => 'circulation' } );
426
427
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
428
        my $first_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
429
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
430
        my $second_checkout_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
431
432
        AddReturn( $item1->{barcode} );
433
        my $first_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
434
        AddReturn( $item2->{barcode} );
435
        my $second_checkin_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
436
437
        Koha::Notice::Messages->delete;
438
439
        # TT syntax
440
        $checkout_template = q|
441
The following items have been checked out:
442
----
443
[% biblio.title %]
444
----
445
Thank you for visiting [% branch.branchname %].
446
|;
447
        reset_template( { template => $checkout_template, code => $checkout_code, module => 'circulation' } );
448
        $checkin_template = q|
449
The following items have been checkin out:
450
----
451
[% biblio.title %]
452
----
453
Thank you for visiting [% branch.branchname %].
454
|;
455
        reset_template( { template => $checkin_template, code => $checkin_code, module => 'circulation' } );
456
457
        C4::Circulation::AddIssue( $patron, $item1->{barcode} );
458
        my $first_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
459
        C4::Circulation::AddIssue( $patron, $item2->{barcode} );
460
        my $second_checkout_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
461
462
        AddReturn( $item1->{barcode} );
463
        my $first_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
464
        AddReturn( $item2->{barcode} );
465
        my $second_checkin_tt_letter = Koha::Notice::Messages->search( {}, { order_by => { -desc => 'message_id' } } )->next;
466
467
        is( $first_checkout_tt_letter->content, $first_checkout_letter->content, );
468
        is( $second_checkout_tt_letter->content, $second_checkout_letter->content, );
469
        is( $first_checkin_tt_letter->content, $first_checkin_letter->content, );
470
        is( $second_checkin_tt_letter->content, $second_checkin_letter->content, );
471
472
    };
378
};
473
};
379
474
380
sub reset_template {
475
sub reset_template {
381
- 

Return to bug 17964