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

(-)a/t/db_dependent/Reports/Guided.t (-18 / +25 lines)
Lines 252-270 subtest 'get_saved_reports' => sub { Link Here
252
        'running a query with a parameter returned the expected result'
252
        'running a query with a parameter returned the expected result'
253
    );
253
    );
254
254
255
    # for next test, we want to let execute_query capture any SQL errors
255
    {
256
    $dbh->{RaiseError} = 0;
256
        local $dbh->{RaiseError} = 0;
257
    my $errors;
257
        my $errors;
258
    warning_like { ($sth, $errors) = execute_query(
258
        warning_like { ($sth, $errors) = execute_query(
259
            'SELECT surname FRM borrowers',  # error in the query is intentional
259
                'SELECT surname FRM borrowers',  # error in the query is intentional
260
            0, 10 ) }
260
                0, 10 ) }
261
            qr/^DBD::mysql::st execute failed: You have an error in your SQL syntax;/,
261
                qr/^DBD::mysql::st execute failed: You have an error in your SQL syntax;/,
262
            "Wrong SQL syntax raises warning";
262
                "Wrong SQL syntax raises warning";
263
    ok(
263
        ok(
264
        defined($errors) && exists($errors->{queryerr}),
264
            defined($errors) && exists($errors->{queryerr}),
265
        'attempting to run a report with an SQL syntax error returns error message (Bug 12214)'
265
            'attempting to run a report with an SQL syntax error returns error message (Bug 12214)'
266
    );
266
        );
267
    $dbh->{RaiseError} = 1;
267
    }
268
268
269
    is_deeply( get_report_areas(), [ 'CIRC', 'CAT', 'PAT', 'ACQ', 'ACC', 'SER' ],
269
    is_deeply( get_report_areas(), [ 'CIRC', 'CAT', 'PAT', 'ACQ', 'ACC', 'SER' ],
270
        "get_report_areas returns the correct array of report areas");
270
        "get_report_areas returns the correct array of report areas");
Lines 367-372 count(h.reservedate) AS 'holds' Link Here
367
subtest 'Email report test' => sub {
367
subtest 'Email report test' => sub {
368
368
369
    plan tests => 12;
369
    plan tests => 12;
370
    my $dbh = C4::Context->dbh;
370
371
371
    my $id1 = $builder->build({ source => 'Borrower',value => { surname => 'mailer', email => 'a@b.com', emailpro => 'b@c.com' } })->{ borrowernumber };
372
    my $id1 = $builder->build({ source => 'Borrower',value => { surname => 'mailer', email => 'a@b.com', emailpro => 'b@c.com' } })->{ borrowernumber };
372
    my $id2 = $builder->build({ source => 'Borrower',value => { surname => 'nomailer', email => undef, emailpro => 'd@e.com' } })->{ borrowernumber };
373
    my $id2 = $builder->build({ source => 'Borrower',value => { surname => 'nomailer', email => undef, emailpro => 'd@e.com' } })->{ borrowernumber };
Lines 399-408 subtest 'Email report test' => sub { Link Here
399
    ($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report1, module => $letter1->{module}, code => $letter2->{code}});
400
    ($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report1, module => $letter1->{module}, code => $letter2->{code}});
400
    is( $errors->[0]{FATAL}, 'NO_LETTER', "Must have a letter that exists");
401
    is( $errors->[0]{FATAL}, 'NO_LETTER', "Must have a letter that exists");
401
402
402
    warning_like { ($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report2, module => $letter1->{module} , code => $letter1->{code} }) }
403
    {
403
        qr/^DBD::mysql::st execute failed/,
404
        local $dbh->{RaiseError} = 0;
404
        'Error from bad report';
405
        warning_like { ($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report2, module => $letter1->{module} , code => $letter1->{code} }) }
405
    is( $errors->[0]{FATAL}, 'REPORT_FAIL', "Bad report returns failure");
406
            qr/^DBD::mysql::st execute failed/,
407
            'Error from bad report';
408
        is( $errors->[0]{FATAL}, 'REPORT_FAIL', "Bad report returns failure");
409
    }
406
410
407
    ($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report1, module => $letter1->{module} , code => $letter1->{code} });
411
    ($emails, $errors ) = C4::Reports::Guided::EmailReport({report_id => $report1, module => $letter1->{module} , code => $letter1->{code} });
408
    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");
412
    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");
Lines 429-434 subtest 'nb_rows() tests' => sub { Link Here
429
433
430
    plan tests => 3;
434
    plan tests => 3;
431
435
436
    my $dbh = C4::Context->dbh;
432
    $schema->storage->txn_begin;
437
    $schema->storage->txn_begin;
433
438
434
    my $items_count = Koha::Items->search->count;
439
    my $items_count = Koha::Items->search->count;
Lines 448-459 subtest 'nb_rows() tests' => sub { Link Here
448
        SELECT * items xxx
453
        SELECT * items xxx
449
    };
454
    };
450
455
456
    # for next test, we want to let execute_query capture any SQL errors
457
    $dbh->{RaiseError} = 0;
451
    warning_like
458
    warning_like
452
        { $nb_rows = nb_rows( $bad_query ) }
459
        { $nb_rows = nb_rows( $bad_query ) }
453
        qr/^DBD::mysql::st execute failed:/,
460
        qr/^DBD::mysql::st execute failed:/,
454
        'Bad queries raise a warning';
461
        'Bad queries raise a warning';
455
462
456
    is( $nb_rows, 0, 'nb_rows returns 0 on bad queries' );
463
    is( $nb_rows, 0, 'nb_rows returns 0 on bad queries' );
464
    $dbh->{RaiseError} = 0;
457
465
458
    $schema->storage->txn_rollback;
466
    $schema->storage->txn_rollback;
459
};
467
};
460
- 

Return to bug 22001