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