Lines 24-29
use Test::More tests => 7;
Link Here
|
24 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
25 |
use t::lib::TestBuilder; |
25 |
use t::lib::TestBuilder; |
26 |
|
26 |
|
|
|
27 |
use C4::Context; |
28 |
|
27 |
use Koha::Notice::Templates; |
29 |
use Koha::Notice::Templates; |
28 |
use Koha::Patron::Categories; |
30 |
use Koha::Patron::Categories; |
29 |
use Koha::Patron::Message::Attributes; |
31 |
use Koha::Patron::Message::Attributes; |
Lines 31-36
use Koha::Patron::Message::Transport::Types;
Link Here
|
31 |
use Koha::Patron::Message::Transports; |
33 |
use Koha::Patron::Message::Transports; |
32 |
use Koha::Patrons; |
34 |
use Koha::Patrons; |
33 |
|
35 |
|
|
|
36 |
use File::Temp qw/tempfile/; |
37 |
use Log::Log4perl; |
38 |
|
34 |
my $schema = Koha::Database->new->schema; |
39 |
my $schema = Koha::Database->new->schema; |
35 |
my $builder = t::lib::TestBuilder->new; |
40 |
my $builder = t::lib::TestBuilder->new; |
36 |
|
41 |
|
Lines 189-195
subtest 'Test Koha::Patron::Message::Preference->message_transport_types' => sub
Link Here
|
189 |
'Method message_transport_types available'); |
194 |
'Method message_transport_types available'); |
190 |
|
195 |
|
191 |
subtest 'get message_transport_types' => sub { |
196 |
subtest 'get message_transport_types' => sub { |
192 |
plan tests => 4; |
197 |
plan tests => 5; |
193 |
|
198 |
|
194 |
$schema->storage->txn_begin; |
199 |
$schema->storage->txn_begin; |
195 |
|
200 |
|
Lines 229-234
subtest 'Test Koha::Patron::Message::Preference->message_transport_types' => sub
Link Here
|
229 |
ok(!$preference->message_transport_types->{'nonexistent'}, |
234 |
ok(!$preference->message_transport_types->{'nonexistent'}, |
230 |
'Didn\'t find nonexistent transport type.'); |
235 |
'Didn\'t find nonexistent transport type.'); |
231 |
|
236 |
|
|
|
237 |
subtest 'test logging of warnings by invalid message transport type' => sub { |
238 |
plan tests => 2; |
239 |
|
240 |
my $log = mytempfile(); |
241 |
my $conf = mytempfile( <<"HERE" |
242 |
log4perl.logger.opac = WARN, OPAC |
243 |
log4perl.appender.OPAC=Log::Log4perl::Appender::TestBuffer |
244 |
log4perl.appender.OPAC.filename=$log |
245 |
log4perl.appender.OPAC.mode=append |
246 |
log4perl.appender.OPAC.layout=SimpleLayout |
247 |
log4perl.logger.intranet = WARN, INTRANET |
248 |
log4perl.appender.INTRANET=Log::Log4perl::Appender::TestBuffer |
249 |
log4perl.appender.INTRANET.filename=$log |
250 |
log4perl.appender.INTRANET.mode=append |
251 |
log4perl.appender.INTRANET.layout=SimpleLayout |
252 |
HERE |
253 |
); |
254 |
t::lib::Mocks::mock_config('log4perl_conf', $conf); |
255 |
my $appenders = Log::Log4perl->appenders; |
256 |
my $appender = Log::Log4perl->appenders->{OPAC}; |
257 |
|
258 |
my $pref = Koha::Patron::Message::Preferences->find( |
259 |
$preference->borrower_message_preference_id |
260 |
); |
261 |
my $transports = $pref->message_transport_types; |
262 |
is($appender, undef, 'Nothing in buffer yet'); |
263 |
|
264 |
my $mtt_new = build_a_test_transport_type(); |
265 |
Koha::Patron::Message::Transport::Preference->new({ |
266 |
borrower_message_preference_id => |
267 |
$pref->borrower_message_preference_id, |
268 |
message_transport_type => $mtt_new->message_transport_type, |
269 |
})->store; |
270 |
$pref = Koha::Patron::Message::Preferences->find( |
271 |
$pref->borrower_message_preference_id |
272 |
); |
273 |
$transports = $pref->message_transport_types; |
274 |
$appender = Log::Log4perl->appenders->{OPAC}; |
275 |
my $name = $pref->message_name; |
276 |
my $tt = $mtt_new->message_transport_type; |
277 |
like($appender->buffer, qr/WARN - $name has no transport with $tt/, |
278 |
'Logged invalid message transport type'); |
279 |
}; |
280 |
|
232 |
$schema->storage->txn_rollback; |
281 |
$schema->storage->txn_rollback; |
233 |
}; |
282 |
}; |
234 |
|
283 |
|
Lines 432-453
subtest 'Test adding a new preference with invalid parameters' => sub {
Link Here
|
432 |
is (ref $@, 'Koha::Exceptions::BadParameter', |
481 |
is (ref $@, 'Koha::Exceptions::BadParameter', |
433 |
'Adding a message preference with invalid message_transport_type' |
482 |
'Adding a message preference with invalid message_transport_type' |
434 |
.' => Koha::Exceptions::BadParameter'); |
483 |
.' => Koha::Exceptions::BadParameter'); |
435 |
is ($@->parameter, 'message_transport_type', 'The previous exception tells us it' |
484 |
is ($@->parameter, 'message_transport_types', 'The previous exception ' |
436 |
.' was the message_transport_type.'); |
485 |
.'tells us it was the message_transport_types.'); |
|
|
486 |
|
487 |
my $mtt_new = build_a_test_transport_type(); |
437 |
eval { |
488 |
eval { |
438 |
Koha::Patron::Message::Preference->new({ |
489 |
Koha::Patron::Message::Preference->new({ |
439 |
borrowernumber => $patron->borrowernumber, |
490 |
borrowernumber => $patron->borrowernumber, |
440 |
message_attribute_id => $attribute->message_attribute_id, |
491 |
message_attribute_id => $attribute->message_attribute_id, |
441 |
message_transport_types => ['sms'], |
492 |
message_transport_types => [$mtt_new->message_transport_type], |
442 |
wants_digest => 1, |
493 |
wants_digest => 1, |
443 |
})->store }; |
494 |
})->store }; |
444 |
is (ref $@, 'Koha::Exceptions::BadParameter', |
495 |
is (ref $@, 'Koha::Exceptions::BadParameter', |
445 |
'Adding a message preference with invalid message_transport_type' |
496 |
'Adding a message preference with invalid message_transport_type' |
446 |
.' => Koha::Exceptions::BadParameter'); |
497 |
.' => Koha::Exceptions::BadParameter'); |
447 |
is ($@->parameter, 'message_transport_type', 'The previous exception tells us it' |
498 |
is ($@->parameter, 'message_transport_types', 'The previous exception ' |
448 |
.' was the message_transport_type.'); |
499 |
.'tells us it was the message_transport_types.'); |
449 |
like ($@->error, qr/^Message transport option/, 'Exception s because of given' |
500 |
like ($@->error, qr/^No transport configured/, 'Exception is because of ' |
450 |
.' message_transport_type is not a valid option.'); |
501 |
.'given message_transport_type is not a valid option.'); |
451 |
|
502 |
|
452 |
eval { |
503 |
eval { |
453 |
Koha::Patron::Message::Preference->new({ |
504 |
Koha::Patron::Message::Preference->new({ |
Lines 643-646
sub build_a_test_complete_preference {
Link Here
|
643 |
})->next, $mtt1, $mtt2); |
694 |
})->next, $mtt1, $mtt2); |
644 |
} |
695 |
} |
645 |
|
696 |
|
|
|
697 |
sub mytempfile { |
698 |
my ( $fh, $fn ) = tempfile( SUFFIX => '.logger.test', UNLINK => 1 ); |
699 |
print $fh $_[0]//''; |
700 |
close $fh; |
701 |
return $fn; |
702 |
} |
703 |
|
646 |
1; |
704 |
1; |
647 |
- |
|
|