3 # This Koha test module is a stub!
4 # Add more tests here!!!
8 use Test::More tests => 14;
13 use_ok('C4::Reports::Guided');
16 'C4::Reports::Guided',
17 qw(save_report delete_report execute_query)
21 my $dbh = C4::Context->dbh;
22 $dbh->{RaiseError} = 1;
23 $dbh->{AutoCommit} = 0;
25 $dbh->do(q|DELETE FROM saved_sql|);
30 my $count = scalar( @{ get_saved_reports() } );
31 is( $count, 0, "There is no report" );
34 for my $id ( 1 .. 3 ) {
35 push @report_ids, save_report({
36 borrowernumber => $id,
41 subgroup => "subgroup$id",
44 cache_expiry => "null",
49 like( $report_ids[0], '/^\d+$/', "Save_report returns an id for first" );
50 like( $report_ids[1], '/^\d+$/', "Save_report returns an id for second" );
51 like( $report_ids[2], '/^\d+$/', "Save_report returns an id for third" );
53 is( scalar( @{ get_saved_reports() } ),
54 $count, "$count reports have been added" );
57 is (delete_report(),undef, "Without id delete_report returns undef");
59 is( delete_report( $report_ids[0] ), 1, "report 1 is deleted" );
62 is( scalar( @{ get_saved_reports() } ), $count, "Report1 has been deleted" );
64 is( delete_report( $report_ids[1], $report_ids[2] ), 2, "report 2 and 3 are deleted" );
67 is( scalar( @{ get_saved_reports() } ),
68 $count, "Report2 and report3 have been deleted" );
70 my $sth = execute_query('SELECT COUNT(*) FROM systempreferences', 0, 10);
71 my $results = $sth->fetchall_arrayref;
72 is(scalar(@$results), 1, 'running a query returned a result');
74 my $version = C4::Context->preference('Version');
76 'SELECT value FROM systempreferences WHERE variable = ?',
81 $results = $sth->fetchall_arrayref;
85 'running a query with a parameter returned the expected result'