Lines 18-30
Link Here
|
18 |
|
18 |
|
19 |
use Modern::Perl; |
19 |
use Modern::Perl; |
20 |
|
20 |
|
21 |
use Test::More tests => 9; |
21 |
use Test::More tests => 10; |
22 |
use Test::Warn; |
22 |
use Test::Warn; |
23 |
|
23 |
|
24 |
use t::lib::TestBuilder; |
24 |
use t::lib::TestBuilder; |
25 |
use C4::Context; |
25 |
use C4::Context; |
26 |
use Koha::Database; |
26 |
use Koha::Database; |
27 |
use Koha::Reports; |
27 |
use Koha::Reports; |
|
|
28 |
use Koha::Notice::Messages; |
28 |
|
29 |
|
29 |
use_ok('C4::Reports::Guided'); |
30 |
use_ok('C4::Reports::Guided'); |
30 |
can_ok( |
31 |
can_ok( |
Lines 355-360
count(h.reservedate) AS 'holds'
Link Here
|
355 |
is( C4::Reports::Guided::convert_sql( $sql ), $expected_converted_sql, "Query with multiple instances of marcxml and biblioitems should have them all replaced"); |
356 |
is( C4::Reports::Guided::convert_sql( $sql ), $expected_converted_sql, "Query with multiple instances of marcxml and biblioitems should have them all replaced"); |
356 |
}; |
357 |
}; |
357 |
|
358 |
|
|
|
359 |
subtest 'Email report test' => sub { |
360 |
|
361 |
plan tests => 8; |
362 |
|
363 |
my $id1 = $builder->build({ source => 'Borrower',value => { surname => 'mailer', email => 'a@b.com' } })->{ borrowernumber }; |
364 |
my $id2 = $builder->build({ source => 'Borrower',value => { surname => 'nomailer', email => undef } })->{ borrowernumber }; |
365 |
my $report1 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT surname,borrowernumber,email FROM borrowers WHERE borrowernumber IN ($id1,$id2)" } })->{ id }; |
366 |
my $report2 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT potato FROM mashed" } })->{ id }; |
367 |
|
368 |
my $letter1 = $builder->build({ |
369 |
source => 'Letter', |
370 |
value => { |
371 |
content => "[% surname %]", |
372 |
branchcode => "", |
373 |
message_transport_type => 'email' |
374 |
} |
375 |
}); |
376 |
my $letter2 = $builder->build({ |
377 |
source => 'Letter', |
378 |
value => { |
379 |
content => "[% firstname %]", |
380 |
branchcode => "", |
381 |
message_transport_type => 'email' |
382 |
} |
383 |
}); |
384 |
|
385 |
my $message_count = Koha::Notice::Messages->search({})->count; |
386 |
|
387 |
my ( $emails, $errors ) = C4::Reports::Guided::EmailReport(); |
388 |
is( $errors->[0]{FATAL}, 'MISSING_PARAMS', "Need to enter required params"); |
389 |
|
390 |
($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report1, module => $letter1->{module}, code => $letter2->{code}}); |
391 |
is( $errors->[0]{FATAL}, 'NO_LETTER', "Must have a letter that exists"); |
392 |
|
393 |
warning_like { ($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report2, module => $letter1->{module} , code => $letter1->{code} }) } |
394 |
qr/^DBD::mysql::st execute failed/, |
395 |
'Error from bad report'; |
396 |
is( $errors->[0]{FATAL}, 'REPORT_FAIL', "Bad report returns failure"); |
397 |
|
398 |
($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report1, module => $letter1->{module} , code => $letter1->{code} }); |
399 |
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"); |
400 |
|
401 |
($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report1, module => $letter1->{module} , code => $letter1->{code}, from => 'the@future.ooh' }); |
402 |
is( $errors->[0]{NO_EMAIL_COL}, 2, "Warning only for patron with no email"); |
403 |
|
404 |
is( $message_count, Koha::Notice::Messages->search({})->count, "Messages not added without commit"); |
405 |
|
406 |
($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report1, module => $letter1->{module} , code => $letter1->{code}, from => 'the@future.ooh' }); |
407 |
is( $emails->[0]{letter}->{content}, "mailer", "Message has expected content"); |
408 |
|
409 |
}; |
410 |
|
358 |
$schema->storage->txn_rollback; |
411 |
$schema->storage->txn_rollback; |
359 |
|
412 |
|
360 |
sub trim { |
413 |
sub trim { |
361 |
- |
|
|