|
Lines 18-29
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::Notice::Messages; |
| 27 |
|
28 |
|
| 28 |
use_ok('C4::Reports::Guided'); |
29 |
use_ok('C4::Reports::Guided'); |
| 29 |
can_ok( |
30 |
can_ok( |
|
Lines 343-348
count(h.reservedate) AS 'holds'
Link Here
|
| 343 |
is( C4::Reports::Guided::convert_sql( $sql ), $expected_converted_sql, "Query with 2 joins should have been correctly converted"); |
344 |
is( C4::Reports::Guided::convert_sql( $sql ), $expected_converted_sql, "Query with 2 joins should have been correctly converted"); |
| 344 |
}; |
345 |
}; |
| 345 |
|
346 |
|
|
|
347 |
subtest 'Email report test' => sub { |
| 348 |
|
| 349 |
plan tests => 9; |
| 350 |
|
| 351 |
my $id1 = $builder->build({ source => 'Borrower',value => { surname => 'mailer', email => 'a@b.com' } })->{ borrowernumber }; |
| 352 |
my $id2 = $builder->build({ source => 'Borrower',value => { surname => 'nomailer', email => undef } })->{ borrowernumber }; |
| 353 |
my $report1 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT surname,borrowernumber,email FROM borrowers WHERE borrowernumber IN ($id1,$id2)" } })->{ id }; |
| 354 |
my $report2 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT potato FROM mashed" } })->{ id }; |
| 355 |
|
| 356 |
my $letter1 = $builder->build({ |
| 357 |
source => 'Letter', |
| 358 |
value => { |
| 359 |
content => "[% surname %]", |
| 360 |
branchcode => "", |
| 361 |
message_transport_type => 'email' |
| 362 |
} |
| 363 |
}); |
| 364 |
my $letter2 = $builder->build({ |
| 365 |
source => 'Letter', |
| 366 |
value => { |
| 367 |
content => "[% firstname %]", |
| 368 |
branchcode => "", |
| 369 |
message_transport_type => 'email' |
| 370 |
} |
| 371 |
}); |
| 372 |
|
| 373 |
my $message_count = Koha::Notice::Messages->search({})->count; |
| 374 |
|
| 375 |
my @result = C4::Reports::Guided::EmailReport(); |
| 376 |
is( $result[0]{FATAL}, 'MISSING_PARAMS', "Need to enter required params"); |
| 377 |
|
| 378 |
@result = C4::Reports::Guided::EmailReport({report => $report1, module => $letter1->{module}, code => $letter2->{code}}); |
| 379 |
is( $result[0]{FATAL}, 'NO_LETTER', "Must have a letter that exists"); |
| 380 |
|
| 381 |
warning_like { @result = C4::Reports::Guided::EmailReport({report => $report2, module => $letter1->{module} , code => $letter1->{code} }) } |
| 382 |
qr/^DBD::mysql::st execute failed/, |
| 383 |
'Error from bad report'; |
| 384 |
is( $result[0]{FATAL}, 'REPORT_FAIL', "Bad report returns failure"); |
| 385 |
|
| 386 |
@result = C4::Reports::Guided::EmailReport({report => $report1, module => $letter1->{module} , code => $letter1 ->{code} }); |
| 387 |
is( $result[0]{NO_FROM_COL} == 0 && $result[1]{NO_EMAIL_COL} == 1 && $result[2]{NO_FROM_COL} == 1, 1, "Correct warnings from the routine"); |
| 388 |
|
| 389 |
@result = C4::Reports::Guided::EmailReport({report => $report1, module => $letter1->{module} , code => $letter1 ->{code}, from => 'the@future.ooh' }); |
| 390 |
is( $result[0]{NO_EMAIL_COL}, 1, "Warning only for patron with no email"); |
| 391 |
|
| 392 |
is( $message_count, Koha::Notice::Messages->search({})->count, "Messages not added without commit"); |
| 393 |
|
| 394 |
@result = C4::Reports::Guided::EmailReport({report => $report1, module => $letter1->{module} , code => $letter1 ->{code}, from => 'the@future.ooh', commit => 1 }); |
| 395 |
|
| 396 |
my $notices = Koha::Notice::Messages->search( undef,{ order_by => { -desc => 'message_id' } } ); |
| 397 |
is( $notices->count, $message_count+1, "Message added with commit option"); |
| 398 |
|
| 399 |
is( $notices->next()->content, "mailer", "Message has expected content"); |
| 400 |
|
| 401 |
}; |
| 402 |
|
| 346 |
$schema->storage->txn_rollback; |
403 |
$schema->storage->txn_rollback; |
| 347 |
|
404 |
|
| 348 |
sub trim { |
405 |
sub trim { |
| 349 |
- |
|
|