|
Lines 3-15
Link Here
|
| 3 |
use Modern::Perl; |
3 |
use Modern::Perl; |
| 4 |
|
4 |
|
| 5 |
use C4::Context; |
5 |
use C4::Context; |
|
|
6 |
|
| 6 |
use Koha::Database; |
7 |
use Koha::Database; |
|
|
8 |
use Koha::DateUtils qw(dt_from_string); |
| 7 |
use Koha::Patrons; |
9 |
use Koha::Patrons; |
| 8 |
use Koha::Account; |
10 |
use Koha::Account; |
|
|
11 |
use Koha::ActionLogs; |
| 9 |
|
12 |
|
|
|
13 |
use t::lib::Mocks; |
| 10 |
use t::lib::TestBuilder; |
14 |
use t::lib::TestBuilder; |
| 11 |
|
15 |
|
| 12 |
use Test::More tests => 38; |
16 |
use Test::More tests => 39; |
| 13 |
|
17 |
|
| 14 |
use_ok('Koha::Patron::Debarments'); |
18 |
use_ok('Koha::Patron::Debarments'); |
| 15 |
|
19 |
|
|
Lines 294-296
is( $restrictions->next->type->code, "TEST2", "Restriction left has type value '
Link Here
|
| 294 |
$account->pay( { amount => 5 } ); |
298 |
$account->pay( { amount => 5 } ); |
| 295 |
$restrictions = $patron4->restrictions; |
299 |
$restrictions = $patron4->restrictions; |
| 296 |
is( $restrictions->count, 0, "->restrictions returns 0 restrictions after paying all fees" ); |
300 |
is( $restrictions->count, 0, "->restrictions returns 0 restrictions after paying all fees" ); |
| 297 |
- |
301 |
|
|
|
302 |
$schema->storage->txn_rollback; |
| 303 |
|
| 304 |
subtest 'BorrowersLog tests' => sub { |
| 305 |
|
| 306 |
plan tests => 16; |
| 307 |
|
| 308 |
$schema->storage->txn_begin; |
| 309 |
|
| 310 |
my $patron = $builder->build_object( |
| 311 |
{ |
| 312 |
class => 'Koha::Patrons', |
| 313 |
value => { debarred => undef, debarredcomment => undef, } |
| 314 |
} |
| 315 |
); |
| 316 |
|
| 317 |
my $type = $builder->build_object( { class => 'Koha::Patron::Restriction::Types' } ); |
| 318 |
|
| 319 |
foreach my $type (qw{CREATE_RESTRICTION MODIFY_RESTRICTION DELETE_RESTRICTION}) { |
| 320 |
is( |
| 321 |
Koha::ActionLogs->search( { module => 'MEMBERS', action => $type, object => $patron->id } )->count, 0, |
| 322 |
"No prior '$type' logs" |
| 323 |
); |
| 324 |
} |
| 325 |
|
| 326 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); |
| 327 |
|
| 328 |
my $add_comment = 'AddDebarment comment'; |
| 329 |
my $add_expiration = dt_from_string()->add( days => 1 ); |
| 330 |
|
| 331 |
Koha::Patron::Debarments::AddDebarment( |
| 332 |
{ |
| 333 |
borrowernumber => $patron->id, |
| 334 |
expiration => $add_expiration, |
| 335 |
type => $type->code, |
| 336 |
comment => $add_comment, |
| 337 |
} |
| 338 |
); |
| 339 |
|
| 340 |
my $restrictions = $patron->restrictions; |
| 341 |
is( $restrictions->count, 1, 'Only one restriction present' ); |
| 342 |
|
| 343 |
my $restriction = $restrictions->next; |
| 344 |
|
| 345 |
my $mod_comment = 'ModDebarment comment'; |
| 346 |
my $mod_expiration = dt_from_string()->add( days => 5 ); |
| 347 |
|
| 348 |
Koha::Patron::Debarments::ModDebarment( |
| 349 |
{ |
| 350 |
borrower_debarment_id => $restriction->id, |
| 351 |
comment => $mod_comment, |
| 352 |
expiration => $mod_expiration, |
| 353 |
} |
| 354 |
); |
| 355 |
|
| 356 |
Koha::Patron::Debarments::DelDebarment( $restriction->id ); |
| 357 |
|
| 358 |
is( $patron->restrictions->count, 0, 'No restrictions present' ); |
| 359 |
|
| 360 |
foreach my $type (qw{CREATE_RESTRICTION MODIFY_RESTRICTION DELETE_RESTRICTION}) { |
| 361 |
is( |
| 362 |
Koha::ActionLogs->search( { module => 'MEMBERS', action => $type, object => $patron->id } )->count, 0, |
| 363 |
"No added '$type' logs" |
| 364 |
); |
| 365 |
} |
| 366 |
|
| 367 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
| 368 |
|
| 369 |
Koha::Patron::Debarments::AddDebarment( |
| 370 |
{ |
| 371 |
borrowernumber => $patron->id, |
| 372 |
expiration => $add_expiration, |
| 373 |
type => $type->code, |
| 374 |
comment => $add_comment, |
| 375 |
} |
| 376 |
); |
| 377 |
|
| 378 |
$restrictions = $patron->restrictions; |
| 379 |
is( $restrictions->count, 1, 'Only one restriction present' ); |
| 380 |
|
| 381 |
$restriction = $restrictions->next; |
| 382 |
|
| 383 |
Koha::Patron::Debarments::ModDebarment( |
| 384 |
{ |
| 385 |
borrower_debarment_id => $restriction->id, |
| 386 |
comment => $mod_comment, |
| 387 |
expiration => $mod_expiration, |
| 388 |
} |
| 389 |
); |
| 390 |
|
| 391 |
Koha::Patron::Debarments::DelDebarment( $restriction->id ); |
| 392 |
|
| 393 |
is( $patron->restrictions->count, 0, 'No restrictions present' ); |
| 394 |
|
| 395 |
my $add_logs = |
| 396 |
Koha::ActionLogs->search( { module => 'MEMBERS', action => 'CREATE_RESTRICTION', object => $patron->id } ); |
| 397 |
my $mod_logs = |
| 398 |
Koha::ActionLogs->search( { module => 'MEMBERS', action => 'MODIFY_RESTRICTION', object => $patron->id } ); |
| 399 |
my $del_logs = |
| 400 |
Koha::ActionLogs->search( { module => 'MEMBERS', action => 'DELETE_RESTRICTION', object => $patron->id } ); |
| 401 |
|
| 402 |
is( $add_logs->count, 1, 'Restriction creation logged' ); |
| 403 |
like( $add_logs->next->info, qr/$add_comment/ ); |
| 404 |
|
| 405 |
is( $mod_logs->count, 1, 'Restriction modification logged' ); |
| 406 |
like( $mod_logs->next->info, qr/$mod_comment/ ); |
| 407 |
|
| 408 |
is( $del_logs->count, 1, 'Restriction deletion logged' ); |
| 409 |
is( $del_logs->next->info, q{}, 'Empty info field on deletion' ); |
| 410 |
|
| 411 |
$schema->storage->txn_rollback; |
| 412 |
}; |