3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 16;
25 use_ok('C4::Reports::Guided');
28 'C4::Reports::Guided',
29 qw(save_report delete_report execute_query)
33 my $dbh = C4::Context->dbh;
34 $dbh->{RaiseError} = 1;
35 $dbh->{AutoCommit} = 0;
37 $dbh->do(q|DELETE FROM saved_sql|);
42 my $count = scalar( @{ get_saved_reports() } );
43 is( $count, 0, "There is no report" );
46 for my $id ( 1 .. 3 ) {
47 push @report_ids, save_report({
48 borrowernumber => $id,
53 subgroup => "subgroup$id",
56 cache_expiry => "null",
61 like( $report_ids[0], '/^\d+$/', "Save_report returns an id for first" );
62 like( $report_ids[1], '/^\d+$/', "Save_report returns an id for second" );
63 like( $report_ids[2], '/^\d+$/', "Save_report returns an id for third" );
65 is( scalar( @{ get_saved_reports() } ),
66 $count, "$count reports have been added" );
69 is (delete_report(),undef, "Without id delete_report returns undef");
71 is( delete_report( $report_ids[0] ), 1, "report 1 is deleted" );
74 is( scalar( @{ get_saved_reports() } ), $count, "Report1 has been deleted" );
76 is( delete_report( $report_ids[1], $report_ids[2] ), 2, "report 2 and 3 are deleted" );
79 is( scalar( @{ get_saved_reports() } ),
80 $count, "Report2 and report3 have been deleted" );
82 my $sth = execute_query('SELECT COUNT(*) FROM systempreferences', 0, 10);
83 my $results = $sth->fetchall_arrayref;
84 is(scalar(@$results), 1, 'running a query returned a result');
86 my $version = C4::Context->preference('Version');
88 'SELECT value FROM systempreferences WHERE variable = ?',
93 $results = $sth->fetchall_arrayref;
97 'running a query with a parameter returned the expected result'
100 # for next test, we want to let execute_query capture any SQL errors
101 $dbh->{RaiseError} = 0;
103 ($sth, $errors) = execute_query(
104 'SELECT surname FRM borrowers', # error in the query is intentional
109 defined($errors) && exists($errors->{queryerr}),
110 'attempting to run a report with an SQL syntax error returns error message (Bug 12214)'
113 is_deeply( get_report_areas(), [ 'CIRC', 'CAT', 'PAT', 'ACQ', 'ACC' ],
114 "get_report_areas returns the correct array of report areas");