Bug 5327 shifting database dependent modules and scripts to t/db_dependent
[koha.git] / t / db_dependent / lib / KohaTest / Overdues / GetBranchcodesWithOverdueRules.pm
1 package KohaTest::Overdues::GetBranchcodesWithOverdueRules;
2 use base qw( KohaTest::Overdues );
3
4 use strict;
5 use warnings;
6
7 use C4::Overdues;
8 use Test::More;
9
10 sub my_branch_has_no_rules : Tests( 2 ) {
11     my $self = shift;
12
13     ok( $self->{'branchcode'}, "we're looking for branch $self->{'branchcode'}" );
14
15     my @branches = C4::Overdues::GetBranchcodesWithOverdueRules;
16     my @found_branches = grep { $_ eq $self->{'branchcode'} } @branches;
17     is( scalar @found_branches, 0, '...and it is not in the list of branches')
18     
19 }
20
21 sub my_branch_has_overdue_rules : Tests( 3 ) {
22     my $self = shift;
23
24     ok( $self->{'branchcode'}, "we're looking for branch $self->{'branchcode'}" );
25
26     my $dbh = C4::Context->dbh();
27     my $sql = <<'END_SQL';
28 INSERT INTO overduerules
29 (branchcode,    categorycode,
30 delay1,        letter1,       debarred1,
31 delay2,        letter2,       debarred2,
32 delay3,        letter3,       debarred3)
33 VALUES
34 ( ?, ?,
35 ?, ?, ?,
36 ?, ?, ?,
37 ?, ?, ?)
38 END_SQL
39
40     my $sth = $dbh->prepare($sql);
41     my $success = $sth->execute( $self->{'branchcode'}, $self->random_string(2),
42                                  1, $self->random_string(), 0,
43                                  5, $self->random_string(), 0,
44                                  9, $self->random_string(), 1, );
45     ok( $success, '...and we have successfully given it an overdue rule' );
46
47     my @branches = C4::Overdues::GetBranchcodesWithOverdueRules;
48     my @found_branches = grep { $_ eq $self->{'branchcode'} } @branches;
49     is( scalar @found_branches, 1, '...and it IS in the list of branches.')
50     
51 }
52
53 1;
54
55
56
57
58
59