4 use Test::More tests => 16;
8 use_ok('C4::Overdues');
9 can_ok('C4::Overdues', 'GetOverdueMessageTransportTypes');
10 can_ok('C4::Overdues', 'GetBranchcodesWithOverdueRules');
12 my $dbh = C4::Context->dbh;
13 $dbh->{AutoCommit} = 0;
14 $dbh->{RaiseError} = 1;
16 $dbh->do(q|DELETE FROM letter|);
17 $dbh->do(q|DELETE FROM message_queue|);
18 $dbh->do(q|DELETE FROM message_transport_types|);
19 $dbh->do(q|DELETE FROM overduerules|);
20 $dbh->do(q|DELETE FROM overduerules_transport_types|);
23 INSERT INTO message_transport_types( message_transport_type ) VALUES ('email'), ('phone'), ('print'), ('sms')
27 INSERT INTO overduerules ( overduerules_id, branchcode, categorycode ) VALUES
34 $dbh->do(q|INSERT INTO overduerules_transport_types (overduerules_id, letternumber, message_transport_type) VALUES
50 $mtts = C4::Overdues::GetOverdueMessageTransportTypes('CPL', 'PT');
51 is( $mtts, undef, 'GetOverdueMessageTransportTypes: returns undef if no letternumber given' );
53 $mtts = C4::Overdues::GetOverdueMessageTransportTypes('CPL', undef, 1);
54 is( $mtts, undef, 'GetOverdueMessageTransportTypes: returns undef if no categorycode given' );
56 $mtts = C4::Overdues::GetOverdueMessageTransportTypes('CPL');
57 is( $mtts, undef, 'GetOverdueMessageTransportTypes: returns undef if no letternumber and categorycode given' );
59 $mtts = C4::Overdues::GetOverdueMessageTransportTypes('CPL', 'PT', 1);
60 is_deeply( $mtts, ['email'], 'GetOverdueMessageTransportTypes: first overdue is by email for PT (CPL)' );
62 $mtts = C4::Overdues::GetOverdueMessageTransportTypes('CPL', 'PT', 2);
63 is_deeply( $mtts, ['sms'], 'GetOverdueMessageTransportTypes: second overdue is by sms for PT (CPL)' );
65 $mtts = C4::Overdues::GetOverdueMessageTransportTypes('CPL', 'PT', 3);
66 is_deeply( $mtts, ['email'], 'GetOverdueMessageTransportTypes: third overdue is by email for PT (CPL)' );
68 $mtts = C4::Overdues::GetOverdueMessageTransportTypes('', 'PT', 1);
69 is_deeply( $mtts, ['email'], 'GetOverdueMessageTransportTypes: first overdue is by email for PT (default)' );
71 $mtts = C4::Overdues::GetOverdueMessageTransportTypes('', 'PT', 2);
72 is_deeply( $mtts, ['email', 'sms'], 'GetOverdueMessageTransportTypes: second overdue is by email and sms for PT (default)' );
74 $mtts = C4::Overdues::GetOverdueMessageTransportTypes('', 'PT', 3);
75 is_deeply( $mtts, ['print', 'sms', 'email'], 'GetOverdueMessageTransportTypes: third overdue is by print, sms and email for PT (default). With print in first.' );
77 # Test GetBranchcodesWithOverdueRules
78 $dbh->do(q|DELETE FROM overduerules|);
80 INSERT INTO overduerules
81 ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
83 ( '', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
86 my $all_branches = C4::Branch::GetBranches;
87 my @branchcodes = keys %$all_branches;
89 my @overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules();
90 is_deeply( [ sort @overdue_branches ], [ sort @branchcodes ], 'If a default rule exists, all branches should be returned' );
93 INSERT INTO overduerules
94 ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
96 ( 'CPL', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
99 @overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules();
100 is_deeply( [ sort @overdue_branches ], [ sort @branchcodes ], 'If a default rule exists and a specific rule exists, all branches should be returned' );
102 $dbh->do(q|DELETE FROM overduerules|);
104 INSERT INTO overduerules
105 ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
107 ( 'CPL', '', 1, 'LETTER_CODE1', 1, 5, 'LETTER_CODE2', 1, 10, 'LETTER_CODE3', 1 )
110 @overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules();
111 is_deeply( \@overdue_branches, ['CPL'] , 'If only a specific rule exist, only 1 branch should be returned' );
113 $dbh->do(q|DELETE FROM overduerules|);
115 INSERT INTO overduerules
116 ( branchcode,categorycode, delay1,letter1,debarred1, delay2,letter2,debarred2, delay3,letter3,debarred3 )
118 ( 'CPL', '', 1, 'LETTER_CODE1_CPL', 1, 5, 'LETTER_CODE2_CPL', 1, 10, 'LETTER_CODE3_CPL', 1 ),
119 ( 'MPL', '', 1, 'LETTER_CODE1_MPL', 1, 5, 'LETTER_CODE2_MPL', 1, 10, 'LETTER_CODE3_MPL', 1 )
122 @overdue_branches = C4::Overdues::GetBranchcodesWithOverdueRules();
123 is_deeply( \@overdue_branches, ['CPL', 'MPL'] , 'If only 2 specific rules exist, 2 branches should be returned' );