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

(-)a/t/db_dependent/Reports/Guided.t (-2 / +58 lines)
Lines 18-29 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 8;
21
use Test::More tests => 9;
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 288-293 subtest 'Ensure last_run is populated' => sub { Link Here
288
    isnt( $report->last_run, $previous_last_run, 'Second run of report updates last_run' );
289
    isnt( $report->last_run, $previous_last_run, 'Second run of report updates last_run' );
289
};
290
};
290
291
292
subtest 'Email report test' => sub {
293
294
    plan tests => 9;
295
296
    my $id1 = $builder->build({ source => 'Borrower',value => { surname => 'mailer', email => 'a@b.com' } })->{ borrowernumber };
297
    my $id2 = $builder->build({ source => 'Borrower',value => { surname => 'nomailer', email => undef } })->{ borrowernumber };
298
    my $report1 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT surname,borrowernumber,email FROM borrowers WHERE borrowernumber IN ($id1,$id2)" } })->{ id };
299
    my $report2 = $builder->build({ source => 'SavedSql', value => { savedsql => "SELECT potato FROM mashed" } })->{ id };
300
301
    my $letter1 = $builder->build({
302
            source => 'Letter',
303
            value => {
304
                content => "[% surname %]",
305
                branchcode => "",
306
                message_transport_type => 'email'
307
            }
308
        });
309
    my $letter2 = $builder->build({
310
            source => 'Letter',
311
            value => {
312
                content => "[% firstname %]",
313
                branchcode => "",
314
                message_transport_type => 'email'
315
            }
316
        });
317
318
    my $message_count = Koha::Notice::Messages->search({})->count;
319
320
    my @result = C4::Reports::Guided::EmailReport();
321
    is( $result[0]{FATAL}, 'MISSING_PARAMS', "Need to enter required params");
322
323
    @result = C4::Reports::Guided::EmailReport({report => $report1, module => $letter1->{module}, code => $letter2->{code}});
324
    is( $result[0]{FATAL}, 'NO_LETTER', "Must have a letter that exists");
325
326
    warning_like { @result = C4::Reports::Guided::EmailReport({report => $report2, module => $letter1->{module} , code => $letter1->{code} }) }
327
        qr/^DBD::mysql::st execute failed/,
328
        'Error from bad report';
329
    is( $result[0]{FATAL}, 'REPORT_FAIL', "Bad report returns failure");
330
331
    @result =  C4::Reports::Guided::EmailReport({report => $report1, module => $letter1->{module} , code => $letter1    ->{code} });
332
    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");
333
334
    @result =  C4::Reports::Guided::EmailReport({report => $report1, module => $letter1->{module} , code => $letter1    ->{code}, from => 'the@future.ooh' });
335
    is( $result[0]{NO_EMAIL_COL}, 1, "Warning only for patron with no email");
336
337
    is( $message_count,  Koha::Notice::Messages->search({})->count, "Messages not added without commit");
338
339
    @result =  C4::Reports::Guided::EmailReport({report => $report1, module => $letter1->{module} , code => $letter1    ->{code}, from => 'the@future.ooh', commit => 1 });
340
341
    my $notices = Koha::Notice::Messages->search( undef,{ order_by => { -desc => 'message_id' } } );
342
    is(  $notices->count, $message_count+1, "Message added with commit option");
343
344
    is( $notices->next()->content, "mailer", "Message has expected content");
345
346
};
347
291
$schema->storage->txn_rollback;
348
$schema->storage->txn_rollback;
292
349
293
sub trim {
350
sub trim {
294
- 

Return to bug 16149