Bug 11439: (follow up) add missing rollback call
[koha.git] / t / db_dependent / Reports_Guided.t
1 #!/usr/bin/perl
2 #
3 # This Koha test module is a stub!
4 # Add more tests here!!!
5
6 use Modern::Perl;
7
8 use Test::More tests => 12;
9
10 use C4::Context;
11
12 BEGIN {
13     use_ok('C4::Reports::Guided');
14 }
15 can_ok(
16     'C4::Reports::Guided',
17     qw(save_report
18       delete_report)
19 );
20
21 #Start transaction
22 my $dbh = C4::Context->dbh;
23 $dbh->{RaiseError} = 1;
24 $dbh->{AutoCommit} = 0;
25
26 $dbh->do(q|DELETE FROM saved_sql|);
27
28 #Start tests
29
30 #Test save_report
31 my $count = scalar( @{ get_saved_reports() } );
32 is( $count, 0, "There is no report" );
33
34 my @report_ids;
35 for my $id ( 1 .. 3 ) {
36     push @report_ids, save_report({
37         borrowernumber => $id,
38         savedsql       => "SQL$id",
39         name           => "Name$id",
40         area           => "area$id",
41         group          => "group$id",
42         subgroup       => "subgroup$id",
43         type           => "type$id",
44         notes          => "note$id",
45         cache_expiry   => "null",
46         public         => "null"
47     });
48     $count++;
49 }
50 like( $report_ids[0], '/^\d+$/', "Save_report returns an id for first" );
51 like( $report_ids[1], '/^\d+$/', "Save_report returns an id for second" );
52 like( $report_ids[2], '/^\d+$/', "Save_report returns an id for third" );
53
54 is( scalar( @{ get_saved_reports() } ),
55     $count, "$count reports have been added" );
56
57 #Test delete_report
58 is (delete_report(),undef, "Without id delete_report returns undef");
59
60 is( delete_report( $report_ids[0] ), 1, "report 1 is deleted" );
61 $count--;
62
63 is( scalar( @{ get_saved_reports() } ), $count, "Report1 has been deleted" );
64
65 is( delete_report( $report_ids[1], $report_ids[2] ), 2, "report 2 and 3 are deleted" );
66 $count -= 2;
67
68 is( scalar( @{ get_saved_reports() } ),
69     $count, "Report2 and report3 have been deleted" );
70
71 #End transaction
72 $dbh->rollback;
73