Bug 15878 - Updated unit tests for hbyymmincr barcodes
[koha.git] / t / db_dependent / Letters.t
index 2d8c9bb..ed5c972 100644 (file)
@@ -18,7 +18,7 @@
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
-use Test::More tests => 69;
+use Test::More tests => 72;
 use Test::MockModule;
 use Test::Warn;
 
@@ -36,7 +36,6 @@ $module->mock(
 
 use_ok('C4::Context');
 use_ok('C4::Members');
-use_ok('C4::Branch');
 use_ok('C4::Acquisition');
 use_ok('C4::Biblio');
 use_ok('C4::Bookseller');
@@ -47,6 +46,7 @@ use Koha::Database;
 use Koha::DateUtils qw( dt_from_string output_pref );
 use Koha::Acquisition::Order;
 use Koha::Acquisition::Bookseller;
+use Koha::Libraries;
 my $schema = Koha::Database->schema;
 $schema->storage->txn_begin();
 
@@ -137,6 +137,16 @@ is(
     'message marked failed if tried to send SMS message for borrower with no smsalertnumber set (bug 11208)'
 );
 
+# ResendMessage
+my $resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
+my $message = C4::Letters::GetMessage( $messages->[0]->{message_id});
+is( $resent, 1, 'The message should have been resent' );
+is($message->{status},'pending', 'ResendMessage sets status to pending correctly (bug 12426)');
+$resent = C4::Letters::ResendMessage($messages->[0]->{message_id});
+is( $resent, 0, 'The message should not have been resent again' );
+$resent = C4::Letters::ResendMessage();
+is( $resent, undef, 'ResendMessage should return undef if not message_id given' );
+
 # GetLetters
 my $letters = C4::Letters::GetLetters();
 is( @$letters, 0, 'GetLetters returns the correct number of letters' );
@@ -263,13 +273,13 @@ my $prepared_letter = GetPreparedLetter((
     substitute  => $substitute,
     repeat      => $repeat,
 ));
-my $branch = GetBranchDetail($library->{branchcode});
-my $my_title_letter = qq|$branch->{branchname} - $substitute->{status}|;
+my $retrieved_library = Koha::Libraries->find($library->{branchcode});
+my $my_title_letter = $retrieved_library->branchname . qq| - $substitute->{status}|;
 my $my_content_letter = qq|Dear Jane Smith,
 According to our current records, you have items that are overdue.Your library does not charge late fines, but please return or renew them at the branch below as soon as possible.
 
-$branch->{branchname}
-$branch->{branchaddress1}
+|.$retrieved_library->branchname.qq|
+|.$retrieved_library->branchaddress1.qq|
 URL: http://thisisatest.com
 
 The following item(s) is/are currently $substitute->{status}:
@@ -393,6 +403,9 @@ $bookseller->contacts->[0]->email('testemail@mydomain.com');
 C4::Bookseller::ModBookseller($bookseller);
 $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
 
+# Ensure that the preference 'LetterLog' is set to logging
+t::lib::Mocks::mock_preference( 'LetterLog', 'on' );
+
 {
 warning_is {
     $err = SendAlerts( 'claimacquisition', [ $ordernumber ], 'TESTACQCLAIM' ) }