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