Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 4; |
22 |
use Test::More tests => 9; |
23 |
|
23 |
|
24 |
use Koha::Notice::Templates; |
24 |
use Koha::Notice::Templates; |
25 |
use Koha::Database; |
25 |
use Koha::Database; |
Lines 67-72
$retrieved_template->delete;
Link Here
|
67 |
is( Koha::Notice::Templates->search->count, |
67 |
is( Koha::Notice::Templates->search->count, |
68 |
$nb_of_templates, 'Delete should have deleted the template' ); |
68 |
$nb_of_templates, 'Delete should have deleted the template' ); |
69 |
|
69 |
|
|
|
70 |
## Tests for Koha::Notice::Messages->get_failed_notices |
71 |
|
72 |
# Remove all existing messages in the message_queue |
73 |
Koha::Notice::Messages->delete; |
74 |
|
75 |
# Make a patron |
76 |
my $patron_category = $builder->build( { source => 'Category' } )->{categorycode}; |
77 |
my $patron = Koha::Patron->new( |
78 |
{ |
79 |
firstname => 'Jane', |
80 |
surname => 'Smith', |
81 |
categorycode => $patron_category, |
82 |
branchcode => $library->{branchcode}, |
83 |
smsalertnumber => '123', |
84 |
} |
85 |
)->store; |
86 |
my $borrowernumber = $patron->borrowernumber; |
87 |
|
88 |
# With all notices removed from the message_queue table confirm get_failed_notices() returns 0 |
89 |
my @failed_notices = Koha::Notice::Messages->get_failed_notices->as_list; |
90 |
is( @failed_notices, 0, 'No failed notices currently exist' ); |
91 |
|
92 |
# Add a failed notice to the message_queue table |
93 |
my $message = Koha::Notice::Message->new( |
94 |
{ |
95 |
borrowernumber => $borrowernumber, |
96 |
subject => 'subject', |
97 |
content => 'content', |
98 |
message_transport_type => 'sms', |
99 |
status => 'failed', |
100 |
letter_code => 'just_a_code', |
101 |
time_queued => \"NOW()", |
102 |
} |
103 |
)->store; |
104 |
|
105 |
# With one failed notice in the message_queue table confirm get_failed_notices() returns 1 |
106 |
my @failed_notices2 = Koha::Notice::Messages->get_failed_notices->as_list; |
107 |
is( @failed_notices2, 1, 'One failed notice currently exists' ); |
108 |
|
109 |
# Change failed notice status to 'pending' |
110 |
$message->update( { status => 'pending' } ); |
111 |
|
112 |
# With the 1 failed notice in the message_queue table marked 'pending' confirm get_failed_notices() returns 0 |
113 |
my @failed_notices3 = Koha::Notice::Messages->get_failed_notices->as_list; |
114 |
is( @failed_notices3, 0, 'No failed notices currently existing, now the notice has been marked pending' ); |
115 |
|
116 |
## Tests for Koha::Notice::Message::restrict_patron_when_notice_fails |
117 |
|
118 |
# Empty the borrower_debarments table |
119 |
my $dbh = C4::Context->dbh; |
120 |
$dbh->do(q|DELETE FROM borrower_debarments|); |
121 |
|
122 |
# Change the status of the notice back to 'failed' |
123 |
$message->update( { status => 'failed' } ); |
124 |
|
125 |
my @failed_notices4 = Koha::Notice::Messages->get_failed_notices->as_list; |
126 |
|
127 |
# There should be one failed notice |
128 |
if (@failed_notices4) { |
129 |
|
130 |
# Restrict the borrower who has the failed notice |
131 |
foreach my $failed_notice (@failed_notices4) { |
132 |
if ( $failed_notice->message_transport_type eq 'sms' || $failed_notice->message_transport_type eq 'email' ) { |
133 |
$failed_notice->restrict_patron_when_notice_fails; |
134 |
} |
135 |
} |
136 |
} |
137 |
|
138 |
# Confirm that the restrict_patron_when_notice_fails() has added a restriction to the patron |
139 |
is( |
140 |
$patron->restrictions->search( { comment => 'SMS number invalid' } )->count, 1, |
141 |
"Patron has a restriction placed on them" |
142 |
); |
143 |
|
144 |
# Restrict the borrower who has the failed notice |
145 |
foreach my $failed_notice (@failed_notices4) { |
146 |
if ( $failed_notice->message_transport_type eq 'sms' || $failed_notice->message_transport_type eq 'email' ) { |
147 |
|
148 |
# If the borrower already has a debarment for failed SMS or email notice then don't apply |
149 |
# a new debarment to their account |
150 |
if ( $patron->restrictions->search( { comment => 'SMS number invalid' } )->count > 0 ) { |
151 |
next; |
152 |
} elsif ( $patron->restrictions->search( { comment => 'Email address invalid' } )->count > 0 ) { |
153 |
next; |
154 |
} |
155 |
|
156 |
# Place the debarment if the borrower doesn't already have one for failed SMS or email |
157 |
# notice |
158 |
$failed_notice->restrict_patron_when_notice_fails; |
159 |
} |
160 |
} |
161 |
|
162 |
# Confirm that no new debarment is added to the borrower |
163 |
is( |
164 |
$patron->restrictions->search( { comment => 'SMS number invalid' } )->count, 1, |
165 |
"No new restriction has been placed on the patron" |
166 |
); |
167 |
|
70 |
subtest 'find_effective_template' => sub { |
168 |
subtest 'find_effective_template' => sub { |
71 |
plan tests => 7; |
169 |
plan tests => 7; |
72 |
|
170 |
|
Lines 135-138
subtest 'find_effective_template' => sub {
Link Here
|
135 |
}; |
233 |
}; |
136 |
|
234 |
|
137 |
$schema->storage->txn_rollback; |
235 |
$schema->storage->txn_rollback; |
138 |
|
|
|
139 |
- |