3 # This file is part of Koha.
5 # Copyright (C) 2016 ByWater Solutions
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 use Test::More tests => 13;
25 use t::lib::TestBuilder;
38 use Koha::Subscription;
41 use Koha::Patron::Modification;
43 my $schema = Koha::Database->schema;
44 $schema->storage->txn_begin();
46 my $builder = t::lib::TestBuilder->new();
48 my $dbh = C4::Context->dbh;
49 $dbh->{RaiseError} = 1;
51 $dbh->do(q|DELETE FROM letter|);
53 my $date = dt_from_string;
55 my $library = $builder->build( { source => 'Branch' } );
56 my $patron = $builder->build( { source => 'Borrower' } );
57 my $patron2 = $builder->build( { source => 'Borrower' } );
59 my $biblio = Koha::Biblio->new(
61 title => 'Test Biblio'
65 my $biblioitem = Koha::Biblioitem->new(
67 biblionumber => $biblio->id()
71 my $item = Koha::Item->new(
73 biblionumber => $biblio->id(),
74 biblioitemnumber => $biblioitem->id()
78 my $hold = Koha::Hold->new(
80 borrowernumber => $patron->{borrowernumber},
81 biblionumber => $biblio->id()
85 my $news = Koha::NewsItem->new()->store();
86 my $serial = Koha::Serial->new()->store();
87 my $subscription = Koha::Subscription->new()->store();
88 my $suggestion = Koha::Suggestion->new()->store();
89 my $checkout = Koha::Checkout->new( { itemnumber => $item->id() } )->store();
90 my $modification = Koha::Patron::Modification->new( { verification_token => "TEST" } )->store();
95 $dbh->prepare(q{INSERT INTO letter (module, code, name, title, content) VALUES ('test',?,'Test','Test',?)});
97 $sth->execute( "TEST_PATRON", "[% borrower.id %]" );
98 $prepared_letter = GetPreparedLetter(
101 letter_code => 'TEST_PATRON',
103 borrowers => $patron->{borrowernumber},
107 is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with scalar' );
109 $prepared_letter = GetPreparedLetter(
112 letter_code => 'TEST_PATRON',
114 borrowers => $patron,
118 is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with hashref' );
120 $prepared_letter = GetPreparedLetter(
123 letter_code => 'TEST_PATRON',
125 borrowers => [ $patron->{borrowernumber} ],
129 is( $prepared_letter->{content}, $patron->{borrowernumber}, 'Patron object used correctly with arrayref' );
131 $sth->execute( "TEST_BIBLIO", "[% biblio.id %]" );
132 $prepared_letter = GetPreparedLetter(
135 letter_code => 'TEST_BIBLIO',
137 biblio => $biblio->id(),
141 is( $prepared_letter->{content}, $biblio->id, 'Biblio object used correctly' );
143 $sth->execute( "TEST_LIBRARY", "[% branch.id %]" );
144 $prepared_letter = GetPreparedLetter(
147 letter_code => 'TEST_LIBRARY',
149 branches => $library->{branchcode}
153 is( $prepared_letter->{content}, $library->{branchcode}, 'Library object used correctly' );
155 $sth->execute( "TEST_ITEM", "[% item.id %]" );
156 $prepared_letter = GetPreparedLetter(
159 letter_code => 'TEST_ITEM',
165 is( $prepared_letter->{content}, $item->id(), 'Item object used correctly' );
167 $sth->execute( "TEST_NEWS", "[% news.id %]" );
168 $prepared_letter = GetPreparedLetter(
171 letter_code => 'TEST_NEWS',
173 opac_news => $news->id()
177 is( $prepared_letter->{content}, $news->id(), 'News object used correctly' );
179 $sth->execute( "TEST_HOLD", "[% hold.id %]" );
180 $prepared_letter = GetPreparedLetter(
183 letter_code => 'TEST_HOLD',
185 reserves => [ $patron->{borrowernumber}, $biblio->id() ]
189 is( $prepared_letter->{content}, $hold->id(), 'Hold object used correctly' );
191 $sth->execute( "TEST_SERIAL", "[% serial.id %]" );
192 $prepared_letter = GetPreparedLetter(
195 letter_code => 'TEST_SERIAL',
197 serial => $serial->id()
201 is( $prepared_letter->{content}, $serial->id(), 'Serial object used correctly' );
203 $sth->execute( "TEST_SUBSCRIPTION", "[% subscription.id %]" );
204 $prepared_letter = GetPreparedLetter(
207 letter_code => 'TEST_SUBSCRIPTION',
209 subscription => $subscription->id()
213 is( $prepared_letter->{content}, $subscription->id(), 'Subscription object used correctly' );
215 $sth->execute( "TEST_SUGGESTION", "[% suggestion.id %]" );
216 $prepared_letter = GetPreparedLetter(
219 letter_code => 'TEST_SUGGESTION',
221 suggestions => $suggestion->id()
225 is( $prepared_letter->{content}, $suggestion->id(), 'Suggestion object used correctly' );
227 $sth->execute( "TEST_ISSUE", "[% checkout.id %]" );
228 $prepared_letter = GetPreparedLetter(
231 letter_code => 'TEST_ISSUE',
233 issues => $item->id()
237 is( $prepared_letter->{content}, $checkout->id(), 'Checkout object used correctly' );
239 $sth->execute( "TEST_MODIFICATION", "[% patron_modification.id %]" );
240 $prepared_letter = GetPreparedLetter(
243 letter_code => 'TEST_MODIFICATION',
245 borrower_modifications => $modification->verification_token,
249 is( $prepared_letter->{content}, $modification->id(), 'Patron modification object used correctly' );