View | Details | Raw Unified | Return to bug 16149
Collapse All | Expand All

(-)a/t/db_dependent/Reports/Guided.t (-2 / +58 lines)
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 => 9;
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 @result = C4::Reports::Guided::EmailReport();
388
    is( $result[0]{FATAL}, 'MISSING_PARAMS', "Need to enter required params");
389
390
    @result = C4::Reports::Guided::EmailReport({report => $report1, module => $letter1->{module}, code => $letter2->{code}});
391
    is( $result[0]{FATAL}, 'NO_LETTER', "Must have a letter that exists");
392
393
    warning_like { @result = C4::Reports::Guided::EmailReport({report => $report2, module => $letter1->{module} , code => $letter1->{code} }) }
394
        qr/^DBD::mysql::st execute failed/,
395
        'Error from bad report';
396
    is( $result[0]{FATAL}, 'REPORT_FAIL', "Bad report returns failure");
397
398
    @result =  C4::Reports::Guided::EmailReport({report => $report1, module => $letter1->{module} , code => $letter1    ->{code} });
399
    is( $result[0]{NO_FROM_COL} == 1 && $result[1]{NO_EMAIL_COL} == 2  && $result[2]{NO_FROM_COL} == 2, 1, "Correct warnings from the routine");
400
401
    @result =  C4::Reports::Guided::EmailReport({report => $report1, module => $letter1->{module} , code => $letter1    ->{code}, from => 'the@future.ooh' });
402
    is( $result[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
    @result =  C4::Reports::Guided::EmailReport({report => $report1, module => $letter1->{module} , code => $letter1    ->{code}, from => 'the@future.ooh', commit => 1 });
407
408
    my $notices = Koha::Notice::Messages->search( undef,{ order_by => { -desc => 'message_id' } } );
409
    is(  $notices->count, $message_count+1, "Message added with commit option");
410
411
    is( $notices->next()->content, "mailer", "Message has expected content");
412
413
};
414
358
$schema->storage->txn_rollback;
415
$schema->storage->txn_rollback;
359
416
360
sub trim {
417
sub trim {
361
- 

Return to bug 16149