From 794fa6e80558fc4fd5a3d4fd1fdb41983d316346 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 26 Aug 2014 12:56:08 -0300 Subject: [PATCH] Bug 10402: (QA followup) amend unit tests --- t/db_dependent/Bookseller.t | 13 ++++++++++--- t/db_dependent/Letters.t | 21 ++++++++++++--------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/t/db_dependent/Bookseller.t b/t/db_dependent/Bookseller.t index 251fb415f9..4cfd3c5211 100644 --- a/t/db_dependent/Bookseller.t +++ b/t/db_dependent/Bookseller.t @@ -2,8 +2,10 @@ use Modern::Perl; -use Test::More tests => 85; +use Test::More tests => 86; use Test::MockModule; +use Test::Warn; + use C4::Context; use Koha::DateUtils; use DateTime::Duration; @@ -450,8 +452,13 @@ ok( exists( $suppliers{$id_supplier3} ), isnt( exists( $suppliers{$id_supplier4} ), 1, "Supplier4 hasnt late orders" ); #Case 3: With $delay = -1 -is( C4::Bookseller::GetBooksellersWithLateOrders( -1, undef, undef ), - undef, "-1 is a wrong value for a delay" ); +my $bslo; +warning_like + { $bslo = C4::Bookseller::GetBooksellersWithLateOrders( -1, undef, undef ) } + qr/^WARNING: GetBooksellerWithLateOrders is called with a negative value/, + "GetBooksellerWithLateOrders prints a warning on negative values"; + +is( $bslo, undef, "-1 is a wrong value for a delay" ); #Case 4: With $delay = 0 # today == now-0 -LATE- (if no deliverytime or deliverytime == 0) diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index 7c0cf387fb..38d4a4ca83 100644 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -18,8 +18,9 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 56; +use Test::More tests => 58; use Test::MockModule; +use Test::Warn; use MARC::Record; @@ -318,10 +319,10 @@ if (C4::Context->preference('marcflavour') eq 'UNIMARC') { C4::Acquisition::CloseBasket( $basketno ); my $err; -eval { - warn "This test may issue a warning. Please ignore it.\n"; - $err = SendAlerts( 'claimacquisition', [ $ordernumber ], 'TESTACQCLAIM' ); -}; +warning_like { + $err = SendAlerts( 'claimacquisition', [ $ordernumber ], 'TESTACQCLAIM' ) } + qr/^Bookseller .* without emails at/, + "SendAlerts prints a warning"; is($err->{'error'}, 'no_email', "Trying to send an alert when there's no e-mail results in an error"); my $bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid); @@ -329,11 +330,13 @@ $bookseller->{'contacts'}->[0]->email('testemail@mydomain.com'); C4::Bookseller::ModBookseller($bookseller); $bookseller = C4::Bookseller::GetBookSellerFromId($booksellerid); -eval { - $err = SendAlerts( 'claimacquisition', [ $ordernumber ], 'TESTACQCLAIM' ); -}; +warning_is { + $err = SendAlerts( 'claimacquisition', [ $ordernumber ], 'TESTACQCLAIM' ) } + "Fake sendmail", + "SendAlerts is using the mocked sendmail routine"; + is($err, 1, "Successfully sent claim"); -is($mail{'To'}, 'testemail@mydomain.com'); +is($mail{'To'}, 'testemail@mydomain.com', "mailto correct in sent claim"); is($mail{'Message'}, 'my vendor|John Smith|Ordernumber ' . $ordernumber . ' (Silence in the library) (1 ordered)', 'Claim notice text constructed successfully'); $dbh->rollback; -- 2.39.5