Lines 19-33
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 8; |
22 |
use Test::More tests => 2; |
23 |
use t::lib::TestBuilder; |
23 |
use t::lib::TestBuilder; |
24 |
use DateTime; |
24 |
use t::lib::Mocks; |
25 |
use File::Spec; |
25 |
use File::Spec; |
26 |
use File::Basename; |
26 |
use File::Basename; |
27 |
use Data::Dumper; |
27 |
|
|
|
28 |
use Koha::DateUtils; |
28 |
|
29 |
|
29 |
my $scriptDir = dirname(File::Spec->rel2abs( __FILE__ )); |
30 |
my $scriptDir = dirname(File::Spec->rel2abs( __FILE__ )); |
30 |
|
31 |
|
|
|
32 |
my $schema = Koha::Database->new->schema; |
31 |
my $dbh = C4::Context->dbh; |
33 |
my $dbh = C4::Context->dbh; |
32 |
|
34 |
|
33 |
my $library1; |
35 |
my $library1; |
Lines 36-46
my $library3;
Link Here
|
36 |
my $borrower; |
38 |
my $borrower; |
37 |
|
39 |
|
38 |
sub build_test_objects { |
40 |
sub build_test_objects { |
39 |
$dbh->{AutoCommit} = 0; |
41 |
|
40 |
$dbh->{RaiseError} = 1; |
42 |
$dbh->{RaiseError} = 1; |
41 |
|
43 |
|
42 |
# Set only to avoid exception. |
44 |
# Set only to avoid exception. |
43 |
$ENV{"OVERRIDE_SYSPREF_dateformat"} = 'metric'; |
45 |
t::lib::Mocks::mock_preference('dateformat', 'metric'); |
44 |
|
46 |
|
45 |
my $builder = t::lib::TestBuilder->new; |
47 |
my $builder = t::lib::TestBuilder->new; |
46 |
|
48 |
|
Lines 126-132
DELETESQL
Link Here
|
126 |
my $item3 = $builder->build({ |
128 |
my $item3 = $builder->build({ |
127 |
source => 'Item' |
129 |
source => 'Item' |
128 |
}); |
130 |
}); |
129 |
my $now = DateTime->now(); |
131 |
my $now = dt_from_string(); |
130 |
my $tomorrow = $now->add(days => 1)->strftime('%F'); |
132 |
my $tomorrow = $now->add(days => 1)->strftime('%F'); |
131 |
|
133 |
|
132 |
my $issue1 = $builder->build({ |
134 |
my $issue1 = $builder->build({ |
Lines 191-262
close $scriptfh;
Link Here
|
191 |
|
193 |
|
192 |
my $sthmq = $dbh->prepare('SELECT * FROM message_queue WHERE borrowernumber = ?'); |
194 |
my $sthmq = $dbh->prepare('SELECT * FROM message_queue WHERE borrowernumber = ?'); |
193 |
|
195 |
|
194 |
# |
196 |
subtest 'Default behaviour tests' => sub { |
195 |
# Test default behavior |
|
|
196 |
# |
197 |
|
197 |
|
198 |
build_test_objects(); |
198 |
plan tests => 3; |
199 |
|
199 |
|
200 |
run_script($scriptContent, 'advanced_notices.pl', '-c'); |
200 |
$schema->storage->txn_begin; |
201 |
|
201 |
|
202 |
$sthmq->execute($borrower->{borrowernumber}); |
202 |
build_test_objects(); |
203 |
|
203 |
|
204 |
my $messages = $sthmq->fetchall_hashref('message_id'); |
204 |
run_script($scriptContent, 'advanced_notices.pl', '-c'); |
205 |
|
205 |
|
206 |
is(scalar(keys %$messages), 1, 'There is one message in the queue'); |
206 |
$sthmq->execute($borrower->{borrowernumber}); |
207 |
|
207 |
|
208 |
for my $message (keys %$messages) { |
208 |
my $messages = $sthmq->fetchall_hashref('message_id'); |
209 |
$messages->{$message}->{content} =~ /(\d+) (.*)/; |
|
|
210 |
my $count = $1; |
211 |
my $branchname = $2; |
212 |
|
209 |
|
213 |
is ($count, '3', 'Issue count is 3'); |
210 |
is(scalar(keys %$messages), 1, 'There is one message in the queue'); |
214 |
is ($branchname, $library1->{branchname}, 'Branchname is that of borrowers home branch.'); |
|
|
215 |
} |
216 |
|
211 |
|
217 |
$dbh->rollback; |
212 |
for my $message (keys %$messages) { |
|
|
213 |
$messages->{$message}->{content} =~ /(\d+) (.*)/; |
214 |
my $count = $1; |
215 |
my $branchname = $2; |
218 |
|
216 |
|
219 |
# |
217 |
is ($count, '3', 'Issue count is 3'); |
220 |
# Test -digest-per-branch |
218 |
is ($branchname, $library1->{branchname}, 'Branchname is that of borrowers home branch.'); |
221 |
# |
219 |
} |
222 |
|
220 |
|
223 |
build_test_objects(); |
221 |
$schema->storage->txn_rollback; |
|
|
222 |
}; |
224 |
|
223 |
|
225 |
run_script($scriptContent, 'advanced_notices.pl', '-c', '-digest-per-branch'); |
224 |
subtest '--digest-per-branch tests' => sub { |
226 |
|
225 |
|
227 |
$sthmq->execute($borrower->{borrowernumber}); |
226 |
plan tests => 5; |
228 |
|
227 |
|
229 |
$messages = $sthmq->fetchall_hashref('message_id'); |
228 |
$schema->storage->txn_begin; |
230 |
|
229 |
|
231 |
is(scalar(keys %$messages), 2, 'There are two messages in the queue'); |
230 |
build_test_objects(); |
232 |
|
231 |
|
233 |
my %expected = ( |
232 |
run_script($scriptContent, 'advanced_notices.pl', '-c', '-digest-per-branch'); |
234 |
$library2->{branchname} => { |
233 |
|
235 |
count => 1, |
234 |
$sthmq->execute($borrower->{borrowernumber}); |
236 |
}, |
|
|
237 |
$library3->{branchname} => { |
238 |
count => 2, |
239 |
} |
240 |
); |
241 |
|
235 |
|
242 |
my %expected_branchnames = ( |
236 |
my $messages = $sthmq->fetchall_hashref('message_id'); |
243 |
$library2->{branchname} => 1, |
|
|
244 |
$library3->{branchname} => 1 |
245 |
); |
246 |
|
237 |
|
247 |
my $i = 0; |
238 |
is(scalar(keys %$messages), 2, 'There are two messages in the queue'); |
248 |
for my $message (keys %$messages) { |
|
|
249 |
$messages->{$message}->{content} =~ /(\d+) (.*)/; |
250 |
my $count = $1; |
251 |
my $branchname = $2; |
252 |
|
239 |
|
253 |
ok ($expected_branchnames{$branchname}, 'Branchname is that of expected issuing branch.'); |
240 |
my %expected = ( |
|
|
241 |
$library2->{branchname} => { |
242 |
count => 1, |
243 |
}, |
244 |
$library3->{branchname} => { |
245 |
count => 2, |
246 |
} |
247 |
); |
254 |
|
248 |
|
255 |
$expected_branchnames{$branchname} = 0; |
249 |
my %expected_branchnames = ( |
|
|
250 |
$library2->{branchname} => 1, |
251 |
$library3->{branchname} => 1 |
252 |
); |
256 |
|
253 |
|
257 |
is ($count, $expected{$branchname}->{count}, 'Issue count is ' . $expected{$branchname}->{count}); |
254 |
my $i = 0; |
|
|
255 |
for my $message (keys %$messages) { |
256 |
$messages->{$message}->{content} =~ /(\d+) (.*)/; |
257 |
my $count = $1; |
258 |
my $branchname = $2; |
258 |
|
259 |
|
259 |
$i++; |
260 |
ok ($expected_branchnames{$branchname}, 'Branchname is that of expected issuing branch.'); |
260 |
} |
261 |
|
|
|
262 |
$expected_branchnames{$branchname} = 0; |
263 |
|
264 |
is ($count, $expected{$branchname}->{count}, 'Issue count is ' . $expected{$branchname}->{count}); |
265 |
|
266 |
$i++; |
267 |
} |
261 |
|
268 |
|
262 |
$dbh->rollback; |
269 |
$schema->storage->txn_rollback; |
|
|
270 |
}; |
263 |
- |
|
|