Lines 28-36
use C4::Context;
Link Here
|
28 |
|
28 |
|
29 |
use Koha::Notice::Templates; |
29 |
use Koha::Notice::Templates; |
30 |
use Koha::Patron::Categories; |
30 |
use Koha::Patron::Categories; |
31 |
use Koha::Patron::Message::Attributes; |
31 |
use Koha::Patron::MessagePreference::Attributes; |
32 |
use Koha::Patron::Message::Transport::Types; |
32 |
use Koha::Patron::MessagePreference::Transport::Types; |
33 |
use Koha::Patron::Message::Transports; |
33 |
use Koha::Patron::MessagePreference::Transports; |
34 |
use Koha::Patrons; |
34 |
use Koha::Patrons; |
35 |
|
35 |
|
36 |
use File::Temp qw/tempfile/; |
36 |
use File::Temp qw/tempfile/; |
Lines 42-60
my $builder = t::lib::TestBuilder->new;
Link Here
|
42 |
subtest 'Test class imports' => sub { |
42 |
subtest 'Test class imports' => sub { |
43 |
plan tests => 2; |
43 |
plan tests => 2; |
44 |
|
44 |
|
45 |
use_ok('Koha::Patron::Message::Preference'); |
45 |
use_ok('Koha::Patron::MessagePreference'); |
46 |
use_ok('Koha::Patron::Message::Preferences'); |
46 |
use_ok('Koha::Patron::MessagePreferences'); |
47 |
}; |
47 |
}; |
48 |
|
48 |
|
49 |
subtest 'Test Koha::Patron::Message::Preferences' => sub { |
49 |
subtest 'Test Koha::Patron::MessagePreferences' => sub { |
50 |
plan tests => 2; |
50 |
plan tests => 2; |
51 |
|
51 |
|
52 |
$schema->storage->txn_begin; |
52 |
$schema->storage->txn_begin; |
53 |
|
53 |
|
54 |
my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' }); |
54 |
my $attribute = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Attributes' }); |
55 |
my $letter = build_a_test_letter(); |
55 |
my $letter = build_a_test_letter(); |
56 |
my $mtt = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); |
56 |
my $mtt = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' }); |
57 |
Koha::Patron::Message::Transport->new({ |
57 |
Koha::Patron::MessagePreference::Transport->new({ |
58 |
message_attribute_id => $attribute->message_attribute_id, |
58 |
message_attribute_id => $attribute->message_attribute_id, |
59 |
message_transport_type => $mtt->message_transport_type, |
59 |
message_transport_type => $mtt->message_transport_type, |
60 |
is_digest => 0, |
60 |
is_digest => 0, |
Lines 66-79
subtest 'Test Koha::Patron::Message::Preferences' => sub {
Link Here
|
66 |
plan tests => 3; |
66 |
plan tests => 3; |
67 |
|
67 |
|
68 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
68 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
69 |
Koha::Patron::Message::Preference->new({ |
69 |
Koha::Patron::MessagePreference->new({ |
70 |
borrowernumber => $patron->borrowernumber, |
70 |
borrowernumber => $patron->borrowernumber, |
71 |
message_attribute_id => $attribute->message_attribute_id, |
71 |
message_attribute_id => $attribute->message_attribute_id, |
72 |
wants_digest => 0, |
72 |
wants_digest => 0, |
73 |
days_in_advance => undef, |
73 |
days_in_advance => undef, |
74 |
})->store; |
74 |
})->store; |
75 |
|
75 |
|
76 |
my $preference = Koha::Patron::Message::Preferences->find({ |
76 |
my $preference = Koha::Patron::MessagePreferences->find({ |
77 |
borrowernumber => $patron->borrowernumber, |
77 |
borrowernumber => $patron->borrowernumber, |
78 |
message_attribute_id => $attribute->message_attribute_id |
78 |
message_attribute_id => $attribute->message_attribute_id |
79 |
}); |
79 |
}); |
Lines 83-98
subtest 'Test Koha::Patron::Message::Preferences' => sub {
Link Here
|
83 |
subtest 'Test set not throwing an exception on duplicate object' => sub { |
83 |
subtest 'Test set not throwing an exception on duplicate object' => sub { |
84 |
plan tests => 1; |
84 |
plan tests => 1; |
85 |
|
85 |
|
86 |
Koha::Patron::Message::Attributes->find({ |
86 |
Koha::Patron::MessagePreference::Attributes->find({ |
87 |
message_attribute_id => $attribute->message_attribute_id |
87 |
message_attribute_id => $attribute->message_attribute_id |
88 |
})->set({ takes_days => 1 })->store; |
88 |
})->set({ takes_days => 1 })->store; |
89 |
$preference->set({ days_in_advance => 1 })->store; |
89 |
$preference->set({ days_in_advance => 1 })->store; |
90 |
is(ref($preference), 'Koha::Patron::Message::Preference', |
90 |
is(ref($preference), 'Koha::Patron::MessagePreference', |
91 |
'Updating the preference does not cause duplicate object exception'); |
91 |
'Updating the preference does not cause duplicate object exception'); |
92 |
}; |
92 |
}; |
93 |
|
93 |
|
94 |
$preference->delete; |
94 |
$preference->delete; |
95 |
is(Koha::Patron::Message::Preferences->search({ |
95 |
is(Koha::Patron::MessagePreferences->search({ |
96 |
borrowernumber => $patron->borrowernumber, |
96 |
borrowernumber => $patron->borrowernumber, |
97 |
message_attribute_id => $attribute->message_attribute_id |
97 |
message_attribute_id => $attribute->message_attribute_id |
98 |
})->count, 0, 'Deleted the messaging preference.'); |
98 |
})->count, 0, 'Deleted the messaging preference.'); |
Lines 100-113
subtest 'Test Koha::Patron::Message::Preferences' => sub {
Link Here
|
100 |
|
100 |
|
101 |
subtest 'Test for a category' => sub { |
101 |
subtest 'Test for a category' => sub { |
102 |
my $category = $builder->build_object({ class => 'Koha::Patron::Categories' }); |
102 |
my $category = $builder->build_object({ class => 'Koha::Patron::Categories' }); |
103 |
Koha::Patron::Message::Preference->new({ |
103 |
Koha::Patron::MessagePreference->new({ |
104 |
categorycode => $category->categorycode, |
104 |
categorycode => $category->categorycode, |
105 |
message_attribute_id => $attribute->message_attribute_id, |
105 |
message_attribute_id => $attribute->message_attribute_id, |
106 |
wants_digest => 0, |
106 |
wants_digest => 0, |
107 |
days_in_advance => undef, |
107 |
days_in_advance => undef, |
108 |
})->store; |
108 |
})->store; |
109 |
|
109 |
|
110 |
my $preference = Koha::Patron::Message::Preferences->find({ |
110 |
my $preference = Koha::Patron::MessagePreferences->find({ |
111 |
categorycode => $category->categorycode, |
111 |
categorycode => $category->categorycode, |
112 |
message_attribute_id => $attribute->message_attribute_id |
112 |
message_attribute_id => $attribute->message_attribute_id |
113 |
}); |
113 |
}); |
Lines 115-121
subtest 'Test Koha::Patron::Message::Preferences' => sub {
Link Here
|
115 |
'Added a new messaging preference for category.'); |
115 |
'Added a new messaging preference for category.'); |
116 |
|
116 |
|
117 |
$preference->delete; |
117 |
$preference->delete; |
118 |
is(Koha::Patron::Message::Preferences->search({ |
118 |
is(Koha::Patron::MessagePreferences->search({ |
119 |
categorycode => $category->categorycode, |
119 |
categorycode => $category->categorycode, |
120 |
message_attribute_id => $attribute->message_attribute_id |
120 |
message_attribute_id => $attribute->message_attribute_id |
121 |
})->count, 0, 'Deleted the messaging preference.'); |
121 |
})->count, 0, 'Deleted the messaging preference.'); |
Lines 124-154
subtest 'Test Koha::Patron::Message::Preferences' => sub {
Link Here
|
124 |
$schema->storage->txn_rollback; |
124 |
$schema->storage->txn_rollback; |
125 |
}; |
125 |
}; |
126 |
|
126 |
|
127 |
subtest 'Test Koha::Patron::Message::Preferences->get_options' => sub { |
127 |
subtest 'Test Koha::Patron::MessagePreferences->get_options' => sub { |
128 |
plan tests => 2; |
128 |
plan tests => 2; |
129 |
|
129 |
|
130 |
subtest 'Test method availability and return value' => sub { |
130 |
subtest 'Test method availability and return value' => sub { |
131 |
plan tests => 3; |
131 |
plan tests => 3; |
132 |
|
132 |
|
133 |
ok(Koha::Patron::Message::Preferences->can('get_options'), |
133 |
ok(Koha::Patron::MessagePreferences->can('get_options'), |
134 |
'Method get_options is available.'); |
134 |
'Method get_options is available.'); |
135 |
ok(my $options = Koha::Patron::Message::Preferences->get_options, |
135 |
ok(my $options = Koha::Patron::MessagePreferences->get_options, |
136 |
'Called get_options successfully.'); |
136 |
'Called get_options successfully.'); |
137 |
is(ref($options), 'ARRAY', 'get_options returns a ARRAYref'); |
137 |
is(ref($options), 'ARRAY', 'get_options returns a ARRAYref'); |
138 |
}; |
138 |
}; |
139 |
|
139 |
|
140 |
subtest 'Make sure options are correct' => sub { |
140 |
subtest 'Make sure options are correct' => sub { |
141 |
$schema->storage->txn_begin; |
141 |
$schema->storage->txn_begin; |
142 |
my $options = Koha::Patron::Message::Preferences->get_options; |
142 |
my $options = Koha::Patron::MessagePreferences->get_options; |
143 |
|
143 |
|
144 |
foreach my $option (@$options) { |
144 |
foreach my $option (@$options) { |
145 |
my $n = $option->{'message_name'}; |
145 |
my $n = $option->{'message_name'}; |
146 |
my $attr = Koha::Patron::Message::Attributes->find($option->{'message_attribute_id'}); |
146 |
my $attr = Koha::Patron::MessagePreference::Attributes->find($option->{'message_attribute_id'}); |
147 |
is($option->{'message_attribute_id'}, $attr->message_attribute_id, |
147 |
is($option->{'message_attribute_id'}, $attr->message_attribute_id, |
148 |
'$n: message_attribute_id is set'); |
148 |
'$n: message_attribute_id is set'); |
149 |
is($option->{'message_name'}, $attr->message_name, '$n: message_name is set'); |
149 |
is($option->{'message_name'}, $attr->message_name, '$n: message_name is set'); |
150 |
is($option->{'takes_days'}, $attr->takes_days, '$n: takes_days is set'); |
150 |
is($option->{'takes_days'}, $attr->takes_days, '$n: takes_days is set'); |
151 |
my $transports = Koha::Patron::Message::Transports->search({ |
151 |
my $transports = Koha::Patron::MessagePreference::Transports->search({ |
152 |
message_attribute_id => $option->{'message_attribute_id'}, |
152 |
message_attribute_id => $option->{'message_attribute_id'}, |
153 |
is_digest => $option->{'has_digest'} || 0, |
153 |
is_digest => $option->{'has_digest'} || 0, |
154 |
}); |
154 |
}); |
Lines 171-196
subtest 'Add preferences from defaults' => sub {
Link Here
|
171 |
my ($default, $mtt1, $mtt2) = build_a_test_category_preference({ |
171 |
my ($default, $mtt1, $mtt2) = build_a_test_category_preference({ |
172 |
patron => $patron, |
172 |
patron => $patron, |
173 |
}); |
173 |
}); |
174 |
ok(Koha::Patron::Message::Preference->new_from_default({ |
174 |
ok(Koha::Patron::MessagePreference->new_from_default({ |
175 |
borrowernumber => $patron->borrowernumber, |
175 |
borrowernumber => $patron->borrowernumber, |
176 |
categorycode => $patron->categorycode, |
176 |
categorycode => $patron->categorycode, |
177 |
message_attribute_id => $default->message_attribute_id, |
177 |
message_attribute_id => $default->message_attribute_id, |
178 |
})->store, 'Added a default preference to patron.'); |
178 |
})->store, 'Added a default preference to patron.'); |
179 |
ok(my $pref = Koha::Patron::Message::Preferences->find({ |
179 |
ok(my $pref = Koha::Patron::MessagePreferences->find({ |
180 |
borrowernumber => $patron->borrowernumber, |
180 |
borrowernumber => $patron->borrowernumber, |
181 |
message_attribute_id => $default->message_attribute_id, |
181 |
message_attribute_id => $default->message_attribute_id, |
182 |
}), 'Found the default preference from patron.'); |
182 |
}), 'Found the default preference from patron.'); |
183 |
is(Koha::Patron::Message::Transport::Preferences->search({ |
183 |
is(Koha::Patron::MessagePreference::Transport::Preferences->search({ |
184 |
borrower_message_preference_id => $pref->borrower_message_preference_id |
184 |
borrower_message_preference_id => $pref->borrower_message_preference_id |
185 |
})->count, 2, 'Found the two transport types that we set earlier'); |
185 |
})->count, 2, 'Found the two transport types that we set earlier'); |
186 |
|
186 |
|
187 |
$schema->storage->txn_rollback; |
187 |
$schema->storage->txn_rollback; |
188 |
}; |
188 |
}; |
189 |
|
189 |
|
190 |
subtest 'Test Koha::Patron::Message::Preference->message_transport_types' => sub { |
190 |
subtest 'Test Koha::Patron::MessagePreference->message_transport_types' => sub { |
191 |
plan tests => 4; |
191 |
plan tests => 4; |
192 |
|
192 |
|
193 |
ok(Koha::Patron::Message::Preference->can('message_transport_types'), |
193 |
ok(Koha::Patron::MessagePreference->can('message_transport_types'), |
194 |
'Method message_transport_types available'); |
194 |
'Method message_transport_types available'); |
195 |
|
195 |
|
196 |
subtest 'get message_transport_types' => sub { |
196 |
subtest 'get message_transport_types' => sub { |
Lines 202-226
subtest 'Test Koha::Patron::Message::Preference->message_transport_types' => sub
Link Here
|
202 |
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({ |
202 |
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({ |
203 |
patron => $patron |
203 |
patron => $patron |
204 |
}); |
204 |
}); |
205 |
Koha::Patron::Message::Transport::Preferences->search({ |
205 |
Koha::Patron::MessagePreference::Transport::Preferences->search({ |
206 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
206 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
207 |
})->delete; |
207 |
})->delete; |
208 |
Koha::Patron::Message::Transport::Preference->new({ |
208 |
Koha::Patron::MessagePreference::Transport::Preference->new({ |
209 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
209 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
210 |
message_transport_type => $mtt1->message_transport_type, |
210 |
message_transport_type => $mtt1->message_transport_type, |
211 |
})->store; |
211 |
})->store; |
212 |
Koha::Patron::Message::Transport::Preference->new({ |
212 |
Koha::Patron::MessagePreference::Transport::Preference->new({ |
213 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
213 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
214 |
message_transport_type => $mtt2->message_transport_type, |
214 |
message_transport_type => $mtt2->message_transport_type, |
215 |
})->store; |
215 |
})->store; |
216 |
my $stored_transports = Koha::Patron::Message::Transport::Preferences->search({ |
216 |
my $stored_transports = Koha::Patron::MessagePreference::Transport::Preferences->search({ |
217 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
217 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
218 |
}); |
218 |
}); |
219 |
my $transport1 = Koha::Patron::Message::Transports->find({ |
219 |
my $transport1 = Koha::Patron::MessagePreference::Transports->find({ |
220 |
message_attribute_id => $preference->message_attribute_id, |
220 |
message_attribute_id => $preference->message_attribute_id, |
221 |
message_transport_type => $mtt1->message_transport_type, |
221 |
message_transport_type => $mtt1->message_transport_type, |
222 |
}); |
222 |
}); |
223 |
my $transport2 = Koha::Patron::Message::Transports->find({ |
223 |
my $transport2 = Koha::Patron::MessagePreference::Transports->find({ |
224 |
message_attribute_id => $preference->message_attribute_id, |
224 |
message_attribute_id => $preference->message_attribute_id, |
225 |
message_transport_type => $mtt2->message_transport_type, |
225 |
message_transport_type => $mtt2->message_transport_type, |
226 |
}); |
226 |
}); |
Lines 255-273
HERE
Link Here
|
255 |
my $appenders = Log::Log4perl->appenders; |
255 |
my $appenders = Log::Log4perl->appenders; |
256 |
my $appender = Log::Log4perl->appenders->{OPAC}; |
256 |
my $appender = Log::Log4perl->appenders->{OPAC}; |
257 |
|
257 |
|
258 |
my $pref = Koha::Patron::Message::Preferences->find( |
258 |
my $pref = Koha::Patron::MessagePreferences->find( |
259 |
$preference->borrower_message_preference_id |
259 |
$preference->borrower_message_preference_id |
260 |
); |
260 |
); |
261 |
my $transports = $pref->message_transport_types; |
261 |
my $transports = $pref->message_transport_types; |
262 |
is($appender, undef, 'Nothing in buffer yet'); |
262 |
is($appender, undef, 'Nothing in buffer yet'); |
263 |
|
263 |
|
264 |
my $mtt_new = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); |
264 |
my $mtt_new = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' }); |
265 |
Koha::Patron::Message::Transport::Preference->new({ |
265 |
Koha::Patron::MessagePreference::Transport::Preference->new({ |
266 |
borrower_message_preference_id => |
266 |
borrower_message_preference_id => |
267 |
$pref->borrower_message_preference_id, |
267 |
$pref->borrower_message_preference_id, |
268 |
message_transport_type => $mtt_new->message_transport_type, |
268 |
message_transport_type => $mtt_new->message_transport_type, |
269 |
})->store; |
269 |
})->store; |
270 |
$pref = Koha::Patron::Message::Preferences->find( |
270 |
$pref = Koha::Patron::MessagePreferences->find( |
271 |
$pref->borrower_message_preference_id |
271 |
$pref->borrower_message_preference_id |
272 |
); |
272 |
); |
273 |
$transports = $pref->message_transport_types; |
273 |
$transports = $pref->message_transport_types; |
Lines 294-305
HERE
Link Here
|
294 |
my $mtt1_str = $mtt1->message_transport_type; |
294 |
my $mtt1_str = $mtt1->message_transport_type; |
295 |
my $mtt2_str = $mtt2->message_transport_type; |
295 |
my $mtt2_str = $mtt2->message_transport_type; |
296 |
# 1/3, use message_transport_types(list) |
296 |
# 1/3, use message_transport_types(list) |
297 |
Koha::Patron::Message::Transport::Preferences->search({ |
297 |
Koha::Patron::MessagePreference::Transport::Preferences->search({ |
298 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
298 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
299 |
})->delete; |
299 |
})->delete; |
300 |
ok($preference->message_transport_types($mtt1_str, $mtt2_str)->store, |
300 |
ok($preference->message_transport_types($mtt1_str, $mtt2_str)->store, |
301 |
'1/3 Set returned true.'); |
301 |
'1/3 Set returned true.'); |
302 |
my $stored_transports = Koha::Patron::Message::Transport::Preferences->search({ |
302 |
my $stored_transports = Koha::Patron::MessagePreference::Transport::Preferences->search({ |
303 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
303 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
304 |
'-or' => [ |
304 |
'-or' => [ |
305 |
message_transport_type => $mtt1_str, |
305 |
message_transport_type => $mtt1_str, |
Lines 309-320
HERE
Link Here
|
309 |
is($stored_transports->count, 2, 'Two transports selected'); |
309 |
is($stored_transports->count, 2, 'Two transports selected'); |
310 |
|
310 |
|
311 |
# 2/3, use message_transport_types(ARRAYREF) |
311 |
# 2/3, use message_transport_types(ARRAYREF) |
312 |
Koha::Patron::Message::Transport::Preferences->search({ |
312 |
Koha::Patron::MessagePreference::Transport::Preferences->search({ |
313 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
313 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
314 |
})->delete; |
314 |
})->delete; |
315 |
ok($preference->message_transport_types([$mtt1_str, $mtt2_str])->store, |
315 |
ok($preference->message_transport_types([$mtt1_str, $mtt2_str])->store, |
316 |
'2/3 Set returned true.'); |
316 |
'2/3 Set returned true.'); |
317 |
$stored_transports = Koha::Patron::Message::Transport::Preferences->search({ |
317 |
$stored_transports = Koha::Patron::MessagePreference::Transport::Preferences->search({ |
318 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
318 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
319 |
'-or' => [ |
319 |
'-or' => [ |
320 |
message_transport_type => $mtt1_str, |
320 |
message_transport_type => $mtt1_str, |
Lines 324-336
HERE
Link Here
|
324 |
is($stored_transports->count, 2, 'Two transports selected'); |
324 |
is($stored_transports->count, 2, 'Two transports selected'); |
325 |
|
325 |
|
326 |
# 3/3, use set({ message_transport_types => ARRAYREF }) |
326 |
# 3/3, use set({ message_transport_types => ARRAYREF }) |
327 |
Koha::Patron::Message::Transport::Preferences->search({ |
327 |
Koha::Patron::MessagePreference::Transport::Preferences->search({ |
328 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
328 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
329 |
})->delete; |
329 |
})->delete; |
330 |
ok($preference->set({ |
330 |
ok($preference->set({ |
331 |
message_transport_types => [$mtt1_str, $mtt2_str]})->store, |
331 |
message_transport_types => [$mtt1_str, $mtt2_str]})->store, |
332 |
'3/3 Set returned true.'); |
332 |
'3/3 Set returned true.'); |
333 |
$stored_transports = Koha::Patron::Message::Transport::Preferences->search({ |
333 |
$stored_transports = Koha::Patron::MessagePreference::Transport::Preferences->search({ |
334 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
334 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
335 |
'-or' => [ |
335 |
'-or' => [ |
336 |
message_transport_type => $mtt1_str, |
336 |
message_transport_type => $mtt1_str, |
Lines 340-373
HERE
Link Here
|
340 |
is($stored_transports->count, 2, 'Two transports selected'); |
340 |
is($stored_transports->count, 2, 'Two transports selected'); |
341 |
|
341 |
|
342 |
# Test contact information validation |
342 |
# Test contact information validation |
343 |
eval { Koha::Patron::Message::Transport::Types->new({ |
343 |
eval { Koha::Patron::MessagePreference::Transport::Types->new({ |
344 |
message_transport_type => 'email' |
344 |
message_transport_type => 'email' |
345 |
})->store }; |
345 |
})->store }; |
346 |
eval { Koha::Patron::Message::Transport::Types->new({ |
346 |
eval { Koha::Patron::MessagePreference::Transport::Types->new({ |
347 |
message_transport_type => 'itiva' |
347 |
message_transport_type => 'itiva' |
348 |
})->store }; |
348 |
})->store }; |
349 |
eval { Koha::Patron::Message::Transport::Types->new({ |
349 |
eval { Koha::Patron::MessagePreference::Transport::Types->new({ |
350 |
message_transport_type => 'phone' |
350 |
message_transport_type => 'phone' |
351 |
})->store }; |
351 |
})->store }; |
352 |
eval { Koha::Patron::Message::Transport::Types->new({ |
352 |
eval { Koha::Patron::MessagePreference::Transport::Types->new({ |
353 |
message_transport_type => 'sms' |
353 |
message_transport_type => 'sms' |
354 |
})->store }; |
354 |
})->store }; |
355 |
Koha::Patron::Message::Transport->new({ |
355 |
Koha::Patron::MessagePreference::Transport->new({ |
356 |
message_attribute_id => $preference->message_attribute_id, |
356 |
message_attribute_id => $preference->message_attribute_id, |
357 |
message_transport_type => 'email', |
357 |
message_transport_type => 'email', |
358 |
is_digest => 1 |
358 |
is_digest => 1 |
359 |
})->store; |
359 |
})->store; |
360 |
Koha::Patron::Message::Transport->new({ |
360 |
Koha::Patron::MessagePreference::Transport->new({ |
361 |
message_attribute_id => $preference->message_attribute_id, |
361 |
message_attribute_id => $preference->message_attribute_id, |
362 |
message_transport_type => 'itiva', |
362 |
message_transport_type => 'itiva', |
363 |
is_digest => 1 |
363 |
is_digest => 1 |
364 |
})->store; |
364 |
})->store; |
365 |
Koha::Patron::Message::Transport->new({ |
365 |
Koha::Patron::MessagePreference::Transport->new({ |
366 |
message_attribute_id => $preference->message_attribute_id, |
366 |
message_attribute_id => $preference->message_attribute_id, |
367 |
message_transport_type => 'phone', |
367 |
message_transport_type => 'phone', |
368 |
is_digest => 1 |
368 |
is_digest => 1 |
369 |
})->store; |
369 |
})->store; |
370 |
Koha::Patron::Message::Transport->new({ |
370 |
Koha::Patron::MessagePreference::Transport->new({ |
371 |
message_attribute_id => $preference->message_attribute_id, |
371 |
message_attribute_id => $preference->message_attribute_id, |
372 |
message_transport_type => 'sms', |
372 |
message_transport_type => 'sms', |
373 |
is_digest => 1 |
373 |
is_digest => 1 |
Lines 377-385
HERE
Link Here
|
377 |
eval { |
377 |
eval { |
378 |
$preference->message_transport_types('email')->store; |
378 |
$preference->message_transport_types('email')->store; |
379 |
}; |
379 |
}; |
380 |
is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::EmailAddressRequired', |
380 |
is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::EmailAddressRequired', |
381 |
'Adding a message preference with invalid message_transport_type' |
381 |
'Adding a message preference with invalid message_transport_type' |
382 |
.' => Koha::Exceptions::Patron::Message::Preference::EmailAddressRequired'); |
382 |
.' => Koha::Exceptions::Patron::MessagePreference::EmailAddressRequired'); |
383 |
is ($@->message_name, $preference->message_name, 'The previous exception ' |
383 |
is ($@->message_name, $preference->message_name, 'The previous exception ' |
384 |
.' tells us it which message name it was.'); |
384 |
.' tells us it which message name it was.'); |
385 |
is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception ' |
385 |
is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception ' |
Lines 387-395
HERE
Link Here
|
387 |
eval { |
387 |
eval { |
388 |
$preference->message_transport_types('itiva')->store; |
388 |
$preference->message_transport_types('itiva')->store; |
389 |
}; |
389 |
}; |
390 |
is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::TalkingTechItivaPhoneNotificationRequired', |
390 |
is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::TalkingTechItivaPhoneNotificationRequired', |
391 |
'Adding a message preference with invalid message_transport_type' |
391 |
'Adding a message preference with invalid message_transport_type' |
392 |
.' => Koha::Exceptions::Patron::Message::Preference::TalkingTechItivaPhoneNotificationRequired'); |
392 |
.' => Koha::Exceptions::Patron::MessagePreference::TalkingTechItivaPhoneNotificationRequired'); |
393 |
is ($@->message_name, $preference->message_name, 'The previous exception ' |
393 |
is ($@->message_name, $preference->message_name, 'The previous exception ' |
394 |
.' tells us it which message name it was.'); |
394 |
.' tells us it which message name it was.'); |
395 |
is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception ' |
395 |
is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception ' |
Lines 397-405
HERE
Link Here
|
397 |
eval { |
397 |
eval { |
398 |
$preference->message_transport_types('phone')->store; |
398 |
$preference->message_transport_types('phone')->store; |
399 |
}; |
399 |
}; |
400 |
is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::PhoneNumberRequired', |
400 |
is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::PhoneNumberRequired', |
401 |
'Adding a message preference with invalid message_transport_type' |
401 |
'Adding a message preference with invalid message_transport_type' |
402 |
.' => Koha::Exceptions::Patron::Message::Preference::PhoneNumberRequired'); |
402 |
.' => Koha::Exceptions::Patron::MessagePreference::PhoneNumberRequired'); |
403 |
is ($@->message_name, $preference->message_name, 'The previous exception ' |
403 |
is ($@->message_name, $preference->message_name, 'The previous exception ' |
404 |
.' tells us it which message name it was.'); |
404 |
.' tells us it which message name it was.'); |
405 |
is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception ' |
405 |
is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception ' |
Lines 407-415
HERE
Link Here
|
407 |
eval { |
407 |
eval { |
408 |
$preference->message_transport_types('sms')->store; |
408 |
$preference->message_transport_types('sms')->store; |
409 |
}; |
409 |
}; |
410 |
is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired', |
410 |
is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::SMSNumberRequired', |
411 |
'Adding a message preference with invalid message_transport_type' |
411 |
'Adding a message preference with invalid message_transport_type' |
412 |
.' => Koha::Exceptions::Patron::Message::Preference::SMSNumberRequired'); |
412 |
.' => Koha::Exceptions::Patron::MessagePreference::SMSNumberRequired'); |
413 |
is ($@->message_name, $preference->message_name, 'The previous exception ' |
413 |
is ($@->message_name, $preference->message_name, 'The previous exception ' |
414 |
.' tells us it which message name it was.'); |
414 |
.' tells us it which message name it was.'); |
415 |
is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception ' |
415 |
is ($@->borrowernumber, $patron->borrowernumber, 'The previous exception ' |
Lines 425-440
HERE
Link Here
|
425 |
|
425 |
|
426 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
426 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
427 |
my $letter = build_a_test_letter(); |
427 |
my $letter = build_a_test_letter(); |
428 |
my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' }); |
428 |
my $attribute = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Attributes' }); |
429 |
my $mtt = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); |
429 |
my $mtt = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' }); |
430 |
Koha::Patron::Message::Transport->new({ |
430 |
Koha::Patron::MessagePreference::Transport->new({ |
431 |
message_attribute_id => $attribute->message_attribute_id, |
431 |
message_attribute_id => $attribute->message_attribute_id, |
432 |
message_transport_type => $mtt->message_transport_type, |
432 |
message_transport_type => $mtt->message_transport_type, |
433 |
is_digest => 0, |
433 |
is_digest => 0, |
434 |
letter_module => $letter->module, |
434 |
letter_module => $letter->module, |
435 |
letter_code => $letter->code, |
435 |
letter_code => $letter->code, |
436 |
})->store; |
436 |
})->store; |
437 |
ok(my $preference = Koha::Patron::Message::Preference->new({ |
437 |
ok(my $preference = Koha::Patron::MessagePreference->new({ |
438 |
borrowernumber => $patron->borrowernumber, |
438 |
borrowernumber => $patron->borrowernumber, |
439 |
message_attribute_id => $attribute->message_attribute_id, |
439 |
message_attribute_id => $attribute->message_attribute_id, |
440 |
wants_digest => 0, |
440 |
wants_digest => 0, |
Lines 443-449
HERE
Link Here
|
443 |
})->store, 'Added a new messaging preference and transport types to patron.'); |
443 |
})->store, 'Added a new messaging preference and transport types to patron.'); |
444 |
ok($preference->message_transport_types->{$mtt->message_transport_type}, |
444 |
ok($preference->message_transport_types->{$mtt->message_transport_type}, |
445 |
'The transport type is stored in the object.'); |
445 |
'The transport type is stored in the object.'); |
446 |
my $stored_transports = Koha::Patron::Message::Transport::Preferences->search({ |
446 |
my $stored_transports = Koha::Patron::MessagePreference::Transport::Preferences->search({ |
447 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
447 |
borrower_message_preference_id => $preference->borrower_message_preference_id, |
448 |
}); |
448 |
}); |
449 |
is($stored_transports->next->message_transport_type, $mtt->message_transport_type, |
449 |
is($stored_transports->next->message_transport_type, $mtt->message_transport_type, |
Lines 453-470
HERE
Link Here
|
453 |
}; |
453 |
}; |
454 |
}; |
454 |
}; |
455 |
|
455 |
|
456 |
subtest 'Test Koha::Patron::Message::Preference->message_name' => sub { |
456 |
subtest 'Test Koha::Patron::MessagePreference->message_name' => sub { |
457 |
plan tests => 1; |
457 |
plan tests => 1; |
458 |
|
458 |
|
459 |
$schema->storage->txn_begin; |
459 |
$schema->storage->txn_begin; |
460 |
|
460 |
|
461 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
461 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
462 |
my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' }); |
462 |
my $attribute = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Attributes' }); |
463 |
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({ |
463 |
my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({ |
464 |
patron => $patron, |
464 |
patron => $patron, |
465 |
attr => $attribute, |
465 |
attr => $attribute, |
466 |
}); |
466 |
}); |
467 |
my $message_name_pref = Koha::Patron::Message::Preferences->search_with_message_name({ |
467 |
my $message_name_pref = Koha::Patron::MessagePreferences->search_with_message_name({ |
468 |
borrowernumber => $patron->{'borrowernumber'}, |
468 |
borrowernumber => $patron->{'borrowernumber'}, |
469 |
message_name => $attribute->message_name, |
469 |
message_name => $attribute->message_name, |
470 |
})->next; |
470 |
})->next; |
Lines 473-479
subtest 'Test Koha::Patron::Message::Preference->message_name' => sub {
Link Here
|
473 |
$schema->storage->txn_rollback; |
473 |
$schema->storage->txn_rollback; |
474 |
}; |
474 |
}; |
475 |
|
475 |
|
476 |
subtest 'Test Koha::Patron::Message::Preference->mtt_deliverable' => sub { |
476 |
subtest 'Test Koha::Patron::MessagePreference->mtt_deliverable' => sub { |
477 |
plan tests => 10; |
477 |
plan tests => 10; |
478 |
|
478 |
|
479 |
$schema->storage->txn_begin; |
479 |
$schema->storage->txn_begin; |
Lines 484-517
subtest 'Test Koha::Patron::Message::Preference->mtt_deliverable' => sub {
Link Here
|
484 |
}); |
484 |
}); |
485 |
|
485 |
|
486 |
# Test email and smsalertnumber validation |
486 |
# Test email and smsalertnumber validation |
487 |
eval { Koha::Patron::Message::Transport::Types->new({ |
487 |
eval { Koha::Patron::MessagePreference::Transport::Types->new({ |
488 |
message_transport_type => 'email' |
488 |
message_transport_type => 'email' |
489 |
})->store }; |
489 |
})->store }; |
490 |
eval { Koha::Patron::Message::Transport::Types->new({ |
490 |
eval { Koha::Patron::MessagePreference::Transport::Types->new({ |
491 |
message_transport_type => 'sms' |
491 |
message_transport_type => 'sms' |
492 |
})->store }; |
492 |
})->store }; |
493 |
eval { Koha::Patron::Message::Transport::Types->new({ |
493 |
eval { Koha::Patron::MessagePreference::Transport::Types->new({ |
494 |
message_transport_type => 'phone' |
494 |
message_transport_type => 'phone' |
495 |
})->store }; |
495 |
})->store }; |
496 |
eval { Koha::Patron::Message::Transport::Types->new({ |
496 |
eval { Koha::Patron::MessagePreference::Transport::Types->new({ |
497 |
message_transport_type => 'itiva' |
497 |
message_transport_type => 'itiva' |
498 |
})->store }; |
498 |
})->store }; |
499 |
Koha::Patron::Message::Transport->new({ |
499 |
Koha::Patron::MessagePreference::Transport->new({ |
500 |
message_attribute_id => $preference->message_attribute_id, |
500 |
message_attribute_id => $preference->message_attribute_id, |
501 |
message_transport_type => 'email', |
501 |
message_transport_type => 'email', |
502 |
is_digest => 1 |
502 |
is_digest => 1 |
503 |
})->store; |
503 |
})->store; |
504 |
Koha::Patron::Message::Transport->new({ |
504 |
Koha::Patron::MessagePreference::Transport->new({ |
505 |
message_attribute_id => $preference->message_attribute_id, |
505 |
message_attribute_id => $preference->message_attribute_id, |
506 |
message_transport_type => 'sms', |
506 |
message_transport_type => 'sms', |
507 |
is_digest => 1 |
507 |
is_digest => 1 |
508 |
})->store; |
508 |
})->store; |
509 |
Koha::Patron::Message::Transport->new({ |
509 |
Koha::Patron::MessagePreference::Transport->new({ |
510 |
message_attribute_id => $preference->message_attribute_id, |
510 |
message_attribute_id => $preference->message_attribute_id, |
511 |
message_transport_type => 'phone', |
511 |
message_transport_type => 'phone', |
512 |
is_digest => 1 |
512 |
is_digest => 1 |
513 |
})->store; |
513 |
})->store; |
514 |
Koha::Patron::Message::Transport->new({ |
514 |
Koha::Patron::MessagePreference::Transport->new({ |
515 |
message_attribute_id => $preference->message_attribute_id, |
515 |
message_attribute_id => $preference->message_attribute_id, |
516 |
message_transport_type => 'itiva', |
516 |
message_transport_type => 'itiva', |
517 |
is_digest => 1 |
517 |
is_digest => 1 |
Lines 557-563
subtest 'Test adding a new preference with invalid parameters' => sub {
Link Here
|
557 |
subtest 'Missing parameters' => sub { |
557 |
subtest 'Missing parameters' => sub { |
558 |
plan tests => 1; |
558 |
plan tests => 1; |
559 |
|
559 |
|
560 |
eval { Koha::Patron::Message::Preference->new->store }; |
560 |
eval { Koha::Patron::MessagePreference->new->store }; |
561 |
is(ref $@, 'Koha::Exceptions::MissingParameter', |
561 |
is(ref $@, 'Koha::Exceptions::MissingParameter', |
562 |
'Adding a message preference without parameters' |
562 |
'Adding a message preference without parameters' |
563 |
.' => Koha::Exceptions::MissingParameter'); |
563 |
.' => Koha::Exceptions::MissingParameter'); |
Lines 569-575
subtest 'Test adding a new preference with invalid parameters' => sub {
Link Here
|
569 |
$schema->storage->txn_begin; |
569 |
$schema->storage->txn_begin; |
570 |
|
570 |
|
571 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
571 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
572 |
eval { Koha::Patron::Message::Preference->new({ |
572 |
eval { Koha::Patron::MessagePreference->new({ |
573 |
borrowernumber => $patron->borrowernumber, |
573 |
borrowernumber => $patron->borrowernumber, |
574 |
categorycode => $patron->categorycode, |
574 |
categorycode => $patron->categorycode, |
575 |
})->store }; |
575 |
})->store }; |
Lines 585-598
subtest 'Test adding a new preference with invalid parameters' => sub {
Link Here
|
585 |
|
585 |
|
586 |
$schema->storage->txn_begin; |
586 |
$schema->storage->txn_begin; |
587 |
|
587 |
|
588 |
eval { Koha::Patron::Message::Preference->new({ |
588 |
eval { Koha::Patron::MessagePreference->new({ |
589 |
borrowernumber => -999, |
589 |
borrowernumber => -999, |
590 |
})->store }; |
590 |
})->store }; |
591 |
is(ref $@, 'Koha::Exceptions::Patron::NotFound', |
591 |
is(ref $@, 'Koha::Exceptions::Patron::NotFound', |
592 |
'Adding a message preference with invalid borrowernumber' |
592 |
'Adding a message preference with invalid borrowernumber' |
593 |
.' => Koha::Exceptions::Patron::NotFound'); |
593 |
.' => Koha::Exceptions::Patron::NotFound'); |
594 |
|
594 |
|
595 |
eval { Koha::Patron::Message::Preference->new({ |
595 |
eval { Koha::Patron::MessagePreference->new({ |
596 |
categorycode => 'nonexistent', |
596 |
categorycode => 'nonexistent', |
597 |
})->store }; |
597 |
})->store }; |
598 |
is(ref $@, 'Koha::Exceptions::Patron::Category::NotFound', |
598 |
is(ref $@, 'Koha::Exceptions::Patron::Category::NotFound', |
Lines 601-696
subtest 'Test adding a new preference with invalid parameters' => sub {
Link Here
|
601 |
|
601 |
|
602 |
my $attribute = build_a_test_attribute({ takes_days => 0 }); |
602 |
my $attribute = build_a_test_attribute({ takes_days => 0 }); |
603 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
603 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
604 |
eval { Koha::Patron::Message::Preference->new({ |
604 |
eval { Koha::Patron::MessagePreference->new({ |
605 |
borrowernumber => $patron->borrowernumber, |
605 |
borrowernumber => $patron->borrowernumber, |
606 |
message_attribute_id => $attribute->message_attribute_id, |
606 |
message_attribute_id => $attribute->message_attribute_id, |
607 |
days_in_advance => 10, |
607 |
days_in_advance => 10, |
608 |
})->store }; |
608 |
})->store }; |
609 |
is(ref $@, 'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceNotAvailable', |
609 |
is(ref $@, 'Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceNotAvailable', |
610 |
'Adding a message preference with days in advance option when not' |
610 |
'Adding a message preference with days in advance option when not' |
611 |
.' available => Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceNotAvailable'); |
611 |
.' available => Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceNotAvailable'); |
612 |
|
612 |
|
613 |
$attribute->set({ takes_days => 1 })->store; |
613 |
$attribute->set({ takes_days => 1 })->store; |
614 |
eval { Koha::Patron::Message::Preference->new({ |
614 |
eval { Koha::Patron::MessagePreference->new({ |
615 |
borrowernumber => $patron->borrowernumber, |
615 |
borrowernumber => $patron->borrowernumber, |
616 |
message_attribute_id => $attribute->message_attribute_id, |
616 |
message_attribute_id => $attribute->message_attribute_id, |
617 |
days_in_advance => -1, |
617 |
days_in_advance => -1, |
618 |
})->store }; |
618 |
})->store }; |
619 |
is(ref $@, 'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange', |
619 |
is(ref $@, 'Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceOutOfRange', |
620 |
'Adding a message preference with days in advance option is out of range' |
620 |
'Adding a message preference with days in advance option is out of range' |
621 |
.' => Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange'); |
621 |
.' => Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceOutOfRange'); |
622 |
is ($@->min, 0, 'The previous exception min value is 0.'); |
622 |
is ($@->min, 0, 'The previous exception min value is 0.'); |
623 |
|
623 |
|
624 |
eval { Koha::Patron::Message::Preference->new({ |
624 |
eval { Koha::Patron::MessagePreference->new({ |
625 |
borrowernumber => $patron->borrowernumber, |
625 |
borrowernumber => $patron->borrowernumber, |
626 |
message_attribute_id => $attribute->message_attribute_id, |
626 |
message_attribute_id => $attribute->message_attribute_id, |
627 |
days_in_advance => 31, |
627 |
days_in_advance => 31, |
628 |
})->store }; |
628 |
})->store }; |
629 |
is(ref $@, 'Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange', |
629 |
is(ref $@, 'Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceOutOfRange', |
630 |
'Adding a message preference with days in advance option is out of range' |
630 |
'Adding a message preference with days in advance option is out of range' |
631 |
.' => Koha::Exceptions::Patron::Message::Preference::DaysInAdvanceOutOfRange'); |
631 |
.' => Koha::Exceptions::Patron::MessagePreference::DaysInAdvanceOutOfRange'); |
632 |
is ($@->max, 30, 'The previous exception max value is 30.'); |
632 |
is ($@->max, 30, 'The previous exception max value is 30.'); |
633 |
|
633 |
|
634 |
eval { Koha::Patron::Message::Preference->new({ |
634 |
eval { Koha::Patron::MessagePreference->new({ |
635 |
borrowernumber => $patron->borrowernumber, |
635 |
borrowernumber => $patron->borrowernumber, |
636 |
message_transport_types => ['nonexistent'] |
636 |
message_transport_types => ['nonexistent'] |
637 |
})->store }; |
637 |
})->store }; |
638 |
is (ref $@, 'Koha::Exceptions::Patron::Message::Transport::TypeNotFound', |
638 |
is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::Transport::TypeNotFound', |
639 |
'Adding a message preference with invalid message_transport_type' |
639 |
'Adding a message preference with invalid message_transport_type' |
640 |
.' => Koha::Exceptions::Patron::Message::Transport::TypeNotFound'); |
640 |
.' => Koha::Exceptions::Patron::MessagePreference::Transport::TypeNotFound'); |
641 |
is ($@->transport_type, 'nonexistent', 'The previous exception ' |
641 |
is ($@->transport_type, 'nonexistent', 'The previous exception ' |
642 |
.'tells us it which transport type it was.'); |
642 |
.'tells us it which transport type it was.'); |
643 |
|
643 |
|
644 |
my $mtt_new = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); |
644 |
my $mtt_new = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' }); |
645 |
eval { |
645 |
eval { |
646 |
Koha::Patron::Message::Preference->new({ |
646 |
Koha::Patron::MessagePreference->new({ |
647 |
borrowernumber => $patron->borrowernumber, |
647 |
borrowernumber => $patron->borrowernumber, |
648 |
message_attribute_id => $attribute->message_attribute_id, |
648 |
message_attribute_id => $attribute->message_attribute_id, |
649 |
message_transport_types => [$mtt_new->message_transport_type], |
649 |
message_transport_types => [$mtt_new->message_transport_type], |
650 |
wants_digest => 1, |
650 |
wants_digest => 1, |
651 |
})->store }; |
651 |
})->store }; |
652 |
is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::NoTransportType', |
652 |
is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::NoTransportType', |
653 |
'Adding a message preference with invalid message_transport_type' |
653 |
'Adding a message preference with invalid message_transport_type' |
654 |
.' => Koha::Exceptions::Patron::Message::Preference::NoTransportType'); |
654 |
.' => Koha::Exceptions::Patron::MessagePreference::NoTransportType'); |
655 |
is ($@->message_name, $attribute->message_name, 'The previous exception ' |
655 |
is ($@->message_name, $attribute->message_name, 'The previous exception ' |
656 |
.'tells us which message it was.'); |
656 |
.'tells us which message it was.'); |
657 |
is ($@->transport_type, $mtt_new->message_transport_type, 'The previous exception ' |
657 |
is ($@->transport_type, $mtt_new->message_transport_type, 'The previous exception ' |
658 |
.'tells us which message transport type it was.'); |
658 |
.'tells us which message transport type it was.'); |
659 |
|
659 |
|
660 |
eval { |
660 |
eval { |
661 |
Koha::Patron::Message::Preference->new({ |
661 |
Koha::Patron::MessagePreference->new({ |
662 |
borrowernumber => $patron->borrowernumber, |
662 |
borrowernumber => $patron->borrowernumber, |
663 |
message_attribute_id => $attribute->message_attribute_id, |
663 |
message_attribute_id => $attribute->message_attribute_id, |
664 |
message_transport_types => [], |
664 |
message_transport_types => [], |
665 |
wants_digest => 1, |
665 |
wants_digest => 1, |
666 |
})->store }; |
666 |
})->store }; |
667 |
is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::DigestNotAvailable', |
667 |
is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::DigestNotAvailable', |
668 |
'Adding a message preference that has no digest setting' |
668 |
'Adding a message preference that has no digest setting' |
669 |
.' => Koha::Exceptions::Patron::Message::Preference::DigestNotAvailable'); |
669 |
.' => Koha::Exceptions::Patron::MessagePreference::DigestNotAvailable'); |
670 |
is ($@->message_name, $attribute->message_name, 'The previous exception tells us' |
670 |
is ($@->message_name, $attribute->message_name, 'The previous exception tells us' |
671 |
.' which message it was'); |
671 |
.' which message it was'); |
672 |
|
672 |
|
673 |
eval { |
673 |
eval { |
674 |
Koha::Patron::Message::Preference->new({ |
674 |
Koha::Patron::MessagePreference->new({ |
675 |
borrowernumber => $patron->borrowernumber, |
675 |
borrowernumber => $patron->borrowernumber, |
676 |
message_attribute_id => $attribute->message_attribute_id, |
676 |
message_attribute_id => $attribute->message_attribute_id, |
677 |
message_transport_types => [], |
677 |
message_transport_types => [], |
678 |
wants_digest => 0, |
678 |
wants_digest => 0, |
679 |
})->store }; |
679 |
})->store }; |
680 |
is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::DigestRequired', |
680 |
is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::DigestRequired', |
681 |
'Adding a message preference, that requires digest, with no digest' |
681 |
'Adding a message preference, that requires digest, with no digest' |
682 |
.' => Koha::Exceptions::Patron::Message::Preference::DigestRequired'); |
682 |
.' => Koha::Exceptions::Patron::MessagePreference::DigestRequired'); |
683 |
is ($@->message_name, $attribute->message_name, 'The previous exception tells us' |
683 |
is ($@->message_name, $attribute->message_name, 'The previous exception tells us' |
684 |
.' which message it was'); |
684 |
.' which message it was'); |
685 |
eval { |
685 |
eval { |
686 |
Koha::Patron::Message::Preference->new({ |
686 |
Koha::Patron::MessagePreference->new({ |
687 |
borrowernumber => $patron->borrowernumber, |
687 |
borrowernumber => $patron->borrowernumber, |
688 |
message_attribute_id => -1, |
688 |
message_attribute_id => -1, |
689 |
message_transport_types => [], |
689 |
message_transport_types => [], |
690 |
})->store }; |
690 |
})->store }; |
691 |
is (ref $@, 'Koha::Exceptions::Patron::Message::Preference::AttributeNotFound', |
691 |
is (ref $@, 'Koha::Exceptions::Patron::MessagePreference::AttributeNotFound', |
692 |
'Adding a message preference with invalid message_transport_type' |
692 |
'Adding a message preference with invalid message_transport_type' |
693 |
.' => KKoha::Exceptions::Patron::Message::Preference::AttributeNotFound'); |
693 |
.' => KKoha::Exceptions::Patron::MessagePreference::AttributeNotFound'); |
694 |
is ($@->message_attribute_id, -1, 'The previous exception tells' |
694 |
is ($@->message_attribute_id, -1, 'The previous exception tells' |
695 |
.' us which message attribute id it was.'); |
695 |
.' us which message attribute id it was.'); |
696 |
|
696 |
|
Lines 702-711
subtest 'Test adding a new preference with invalid parameters' => sub {
Link Here
|
702 |
|
702 |
|
703 |
$schema->storage->txn_begin; |
703 |
$schema->storage->txn_begin; |
704 |
|
704 |
|
705 |
my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' }); |
705 |
my $attribute = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Attributes' }); |
706 |
my $letter = build_a_test_letter(); |
706 |
my $letter = build_a_test_letter(); |
707 |
my $mtt = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); |
707 |
my $mtt = $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' }); |
708 |
Koha::Patron::Message::Transport->new({ |
708 |
Koha::Patron::MessagePreference::Transport->new({ |
709 |
message_attribute_id => $attribute->message_attribute_id, |
709 |
message_attribute_id => $attribute->message_attribute_id, |
710 |
message_transport_type => $mtt->message_transport_type, |
710 |
message_transport_type => $mtt->message_transport_type, |
711 |
is_digest => 0, |
711 |
is_digest => 0, |
Lines 713-719
subtest 'Test adding a new preference with invalid parameters' => sub {
Link Here
|
713 |
letter_code => $letter->code, |
713 |
letter_code => $letter->code, |
714 |
})->store; |
714 |
})->store; |
715 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
715 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
716 |
my $preference = Koha::Patron::Message::Preference->new({ |
716 |
my $preference = Koha::Patron::MessagePreference->new({ |
717 |
borrowernumber => $patron->borrowernumber, |
717 |
borrowernumber => $patron->borrowernumber, |
718 |
message_attribute_id => $attribute->message_attribute_id, |
718 |
message_attribute_id => $attribute->message_attribute_id, |
719 |
wants_digest => 0, |
719 |
wants_digest => 0, |
Lines 721-727
subtest 'Test adding a new preference with invalid parameters' => sub {
Link Here
|
721 |
})->store; |
721 |
})->store; |
722 |
ok($preference->borrower_message_preference_id, |
722 |
ok($preference->borrower_message_preference_id, |
723 |
'Added a new messaging preference for patron.'); |
723 |
'Added a new messaging preference for patron.'); |
724 |
eval { Koha::Patron::Message::Preference->new({ |
724 |
eval { Koha::Patron::MessagePreference->new({ |
725 |
borrowernumber => $patron->borrowernumber, |
725 |
borrowernumber => $patron->borrowernumber, |
726 |
message_attribute_id => $attribute->message_attribute_id, |
726 |
message_attribute_id => $attribute->message_attribute_id, |
727 |
wants_digest => 0, |
727 |
wants_digest => 0, |
Lines 746-752
sub build_a_test_attribute {
Link Here
|
746 |
value => $params, |
746 |
value => $params, |
747 |
}); |
747 |
}); |
748 |
|
748 |
|
749 |
return Koha::Patron::Message::Attributes->find( |
749 |
return Koha::Patron::MessagePreference::Attributes->find( |
750 |
$attribute->{message_attribute_id} |
750 |
$attribute->{message_attribute_id} |
751 |
); |
751 |
); |
752 |
} |
752 |
} |
Lines 782-791
sub build_a_test_category_preference {
Link Here
|
782 |
: build_a_test_attribute($params->{days_in_advance}); |
782 |
: build_a_test_attribute($params->{days_in_advance}); |
783 |
|
783 |
|
784 |
my $letter = $params->{letter} ? $params->{letter} : build_a_test_letter(); |
784 |
my $letter = $params->{letter} ? $params->{letter} : build_a_test_letter(); |
785 |
my $mtt1 = $params->{mtt1} ? $params->{mtt1} : $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); |
785 |
my $mtt1 = $params->{mtt1} ? $params->{mtt1} : $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' }); |
786 |
my $mtt2 = $params->{mtt2} ? $params->{mtt2} : $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' }); |
786 |
my $mtt2 = $params->{mtt2} ? $params->{mtt2} : $builder->build_object({ class => 'Koha::Patron::MessagePreference::Transport::Types' }); |
787 |
|
787 |
|
788 |
Koha::Patron::Message::Transport->new({ |
788 |
Koha::Patron::MessagePreference::Transport->new({ |
789 |
message_attribute_id => $attr->message_attribute_id, |
789 |
message_attribute_id => $attr->message_attribute_id, |
790 |
message_transport_type => $mtt1->message_transport_type, |
790 |
message_transport_type => $mtt1->message_transport_type, |
791 |
is_digest => $params->{digest} ? 1 : 0, |
791 |
is_digest => $params->{digest} ? 1 : 0, |
Lines 793-799
sub build_a_test_category_preference {
Link Here
|
793 |
letter_code => $letter->code, |
793 |
letter_code => $letter->code, |
794 |
})->store; |
794 |
})->store; |
795 |
|
795 |
|
796 |
Koha::Patron::Message::Transport->new({ |
796 |
Koha::Patron::MessagePreference::Transport->new({ |
797 |
message_attribute_id => $attr->message_attribute_id, |
797 |
message_attribute_id => $attr->message_attribute_id, |
798 |
message_transport_type => $mtt2->message_transport_type, |
798 |
message_transport_type => $mtt2->message_transport_type, |
799 |
is_digest => $params->{digest} ? 1 : 0, |
799 |
is_digest => $params->{digest} ? 1 : 0, |
Lines 801-807
sub build_a_test_category_preference {
Link Here
|
801 |
letter_code => $letter->code, |
801 |
letter_code => $letter->code, |
802 |
})->store; |
802 |
})->store; |
803 |
|
803 |
|
804 |
my $default = Koha::Patron::Message::Preference->new({ |
804 |
my $default = Koha::Patron::MessagePreference->new({ |
805 |
categorycode => $patron->categorycode, |
805 |
categorycode => $patron->categorycode, |
806 |
message_attribute_id => $attr->message_attribute_id, |
806 |
message_attribute_id => $attr->message_attribute_id, |
807 |
wants_digest => $params->{digest} ? 1 : 0, |
807 |
wants_digest => $params->{digest} ? 1 : 0, |
Lines 809-819
sub build_a_test_category_preference {
Link Here
|
809 |
? $params->{days_in_advance} : undef, |
809 |
? $params->{days_in_advance} : undef, |
810 |
})->store; |
810 |
})->store; |
811 |
|
811 |
|
812 |
Koha::Patron::Message::Transport::Preference->new({ |
812 |
Koha::Patron::MessagePreference::Transport::Preference->new({ |
813 |
borrower_message_preference_id => $default->borrower_message_preference_id, |
813 |
borrower_message_preference_id => $default->borrower_message_preference_id, |
814 |
message_transport_type => $mtt1->message_transport_type, |
814 |
message_transport_type => $mtt1->message_transport_type, |
815 |
})->store; |
815 |
})->store; |
816 |
Koha::Patron::Message::Transport::Preference->new({ |
816 |
Koha::Patron::MessagePreference::Transport::Preference->new({ |
817 |
borrower_message_preference_id => $default->borrower_message_preference_id, |
817 |
borrower_message_preference_id => $default->borrower_message_preference_id, |
818 |
message_transport_type => $mtt2->message_transport_type, |
818 |
message_transport_type => $mtt2->message_transport_type, |
819 |
})->store; |
819 |
})->store; |
Lines 827-833
sub build_a_test_complete_preference {
Link Here
|
827 |
my ($default, $mtt1, $mtt2) = build_a_test_category_preference($params); |
827 |
my ($default, $mtt1, $mtt2) = build_a_test_category_preference($params); |
828 |
my $patron = $params->{patron}; |
828 |
my $patron = $params->{patron}; |
829 |
$patron->set_default_messaging_preferences; |
829 |
$patron->set_default_messaging_preferences; |
830 |
return (Koha::Patron::Message::Preferences->search({ |
830 |
return (Koha::Patron::MessagePreferences->search({ |
831 |
borrowernumber => $patron->borrowernumber |
831 |
borrowernumber => $patron->borrowernumber |
832 |
})->next, $mtt1, $mtt2); |
832 |
})->next, $mtt1, $mtt2); |
833 |
} |
833 |
} |
834 |
- |
|
|