From d40ad5f69a1caa6150e1d77b245fa9143a8dbd06 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 27 Mar 2020 11:12:41 +0000 Subject: [PATCH] Bug 22002: (RM follow-up) Allow RaiseError tests in Reports/Guided.t https://bugs.koha-community.org/show_bug.cgi?id=22001 --- t/db_dependent/Reports/Guided.t | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/t/db_dependent/Reports/Guided.t b/t/db_dependent/Reports/Guided.t index f9c2b738f7..9251863b95 100644 --- a/t/db_dependent/Reports/Guided.t +++ b/t/db_dependent/Reports/Guided.t @@ -367,6 +367,7 @@ count(h.reservedate) AS 'holds' subtest 'Email report test' => sub { plan tests => 12; + my $dbh = C4::Context->dbh; my $id1 = $builder->build({ source => 'Borrower',value => { surname => 'mailer', email => 'a@b.com', emailpro => 'b@c.com' } })->{ borrowernumber }; my $id2 = $builder->build({ source => 'Borrower',value => { surname => 'nomailer', email => undef, emailpro => 'd@e.com' } })->{ borrowernumber }; @@ -399,10 +400,13 @@ subtest 'Email report test' => sub { ($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report1, module => $letter1->{module}, code => $letter2->{code}}); is( $errors->[0]{FATAL}, 'NO_LETTER', "Must have a letter that exists"); + # for next test, we want to let execute_query capture any SQL errors + $dbh->{RaiseError} = 0; warning_like { ($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report2, module => $letter1->{module} , code => $letter1->{code} }) } qr/^DBD::mysql::st execute failed/, 'Error from bad report'; is( $errors->[0]{FATAL}, 'REPORT_FAIL', "Bad report returns failure"); + $dbh->{RaiseError} = 1; ($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report1, module => $letter1->{module} , code => $letter1->{code} }); is( $errors->[0]{NO_FROM_COL} == 1 && $errors->[1]{NO_EMAIL_COL} == 2 && $errors->[2]{NO_FROM_COL} == 2, 1, "Correct warnings from the routine"); @@ -429,6 +433,7 @@ subtest 'nb_rows() tests' => sub { plan tests => 3; + my $dbh = C4::Context->dbh; $schema->storage->txn_begin; my $items_count = Koha::Items->search->count; @@ -448,12 +453,15 @@ subtest 'nb_rows() tests' => sub { SELECT * items xxx }; + # for next test, we want to let execute_query capture any SQL errors + $dbh->{RaiseError} = 0; warning_like { $nb_rows = nb_rows( $bad_query ) } qr/^DBD::mysql::st execute failed:/, 'Bad queries raise a warning'; is( $nb_rows, 0, 'nb_rows returns 0 on bad queries' ); + $dbh->{RaiseError} = 0; $schema->storage->txn_rollback; }; -- 2.20.1