Lines 5-11
Link Here
|
5 |
|
5 |
|
6 |
use Modern::Perl; |
6 |
use Modern::Perl; |
7 |
|
7 |
|
8 |
use Test::More tests => 7; |
8 |
use Test::More tests => 12; |
9 |
|
9 |
|
10 |
use C4::Context; |
10 |
use C4::Context; |
11 |
|
11 |
|
Lines 30-74
$dbh->do(q|DELETE FROM saved_sql|);
Link Here
|
30 |
#Test save_report |
30 |
#Test save_report |
31 |
my $count = scalar( keys get_saved_reports() ); |
31 |
my $count = scalar( keys get_saved_reports() ); |
32 |
is( $count, 0, "There is no report" ); |
32 |
is( $count, 0, "There is no report" ); |
33 |
my $sample_report1 = { |
33 |
|
34 |
borrowernumber => 1, |
34 |
my @report_ids; |
35 |
savedsql => 'SQL1', |
35 |
for my $id ( 1 .. 3 ) { |
36 |
name => 'Name1', |
36 |
push @report_ids, save_report({ |
37 |
area => 'area1', |
37 |
borrowernumber => $id, |
38 |
group => 'group1', |
38 |
savedsql => "SQL$id", |
39 |
subgroup => 'subgroup1', |
39 |
name => "Name$id", |
40 |
type => 'type1', |
40 |
area => "area$id", |
41 |
notes => 'note1', |
41 |
group => "group$id", |
42 |
cache_expiry => 'null', |
42 |
subgroup => "subgroup$id", |
43 |
public => 'null' |
43 |
type => "type$id", |
44 |
}; |
44 |
notes => "note$id", |
45 |
my $sample_report2 = { |
45 |
cache_expiry => "null", |
46 |
borrowernumber => 2, |
46 |
public => "null" |
47 |
savedsql => 'SQL2', |
47 |
}); |
48 |
name => 'Name2', |
48 |
$count++; |
49 |
area => 'area2', |
49 |
} |
50 |
group => 'group2', |
50 |
like( $report_ids[0], '/^\d+$/', "Save_report returns an id for first" ); |
51 |
subgroup => 'subgroup2', |
51 |
like( $report_ids[1], '/^\d+$/', "Save_report returns an id for second" ); |
52 |
type => 'type2', |
52 |
like( $report_ids[2], '/^\d+$/', "Save_report returns an id for third" ); |
53 |
notes => 'note2', |
53 |
|
54 |
cache_expiry => 'null', |
|
|
55 |
public => 'null' |
56 |
}; |
57 |
my $report_id1 = save_report($sample_report1); |
58 |
my $report_id2 = save_report($sample_report2); |
59 |
like( $report_id1, '/^\d+$/', "Save_report returns an id" ); |
60 |
like( $report_id2, '/^\d+$/', "Save_report returns an id" ); |
61 |
is( scalar( keys get_saved_reports() ), |
54 |
is( scalar( keys get_saved_reports() ), |
62 |
$count + 2, "Report1 and report2 have been added" ); |
55 |
$count, "$count reports have been added" ); |
63 |
|
56 |
|
64 |
#Test delete_report |
57 |
#Test delete_report |
65 |
#It would be better if delete_report has return values |
58 |
is (delete_report(),undef, "Without id delete_report returns undef"); |
66 |
delete_report( $report_id1, $report_id2 ); |
|
|
67 |
is( scalar( keys get_saved_reports() ), |
68 |
$count, "Report1 and report2 have been deleted" ); |
69 |
|
59 |
|
70 |
#FIX ME: Currently, this test doesn't pass because delete_report doesn't test if one or more parameters are given |
60 |
is( delete_report( $report_ids[0] ), 1, "report 1 is deleted" ); |
71 |
#is (deleted_report(),undef, "Without id deleted_report returns undef"); |
61 |
$count--; |
|
|
62 |
|
63 |
is( scalar( keys 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( keys get_saved_reports() ), |
69 |
$count, "Report2 and report3 have been deleted" ); |
72 |
|
70 |
|
73 |
#End transaction |
71 |
#End transaction |
74 |
$dbh->rollback; |
72 |
$dbh->rollback; |
75 |
- |
|
|