Lines 409-418
subtest 'merge_and_replace_with' => sub {
Link Here
|
409 |
}; |
409 |
}; |
410 |
|
410 |
|
411 |
subtest 'action log tests' => sub { |
411 |
subtest 'action log tests' => sub { |
412 |
plan tests => 4; |
412 |
plan tests => 9; |
413 |
my $schema = Koha::Database->new->schema; |
413 |
my $schema = Koha::Database->new->schema; |
414 |
$schema->storage->txn_begin; |
414 |
$schema->storage->txn_begin; |
415 |
|
415 |
|
|
|
416 |
my $get_info = sub { |
417 |
my ($before, $after, $code, $repeatable) = @_; |
418 |
my $change = { |
419 |
before => $before, |
420 |
after => $after |
421 |
}; |
422 |
if ($repeatable) { |
423 |
while (my ($k, $v) = each %{$change}) { |
424 |
$change->{$k} = $v ? [$v] : []; |
425 |
} |
426 |
} |
427 |
return "Patron attribute " . $code . ": " . to_json($change, { pretty => 1, canonical => 1 }); |
428 |
}; |
429 |
|
416 |
my $patron = $builder->build_object({ class=> 'Koha::Patrons' }); |
430 |
my $patron = $builder->build_object({ class=> 'Koha::Patrons' }); |
417 |
my $attribute_type = $builder->build_object( |
431 |
my $attribute_type = $builder->build_object( |
418 |
{ |
432 |
{ |
Lines 429-439
subtest 'action log tests' => sub {
Link Here
|
429 |
} |
443 |
} |
430 |
]; |
444 |
]; |
431 |
$patron->extended_attributes($attributes); |
445 |
$patron->extended_attributes($attributes); |
432 |
my $change = { |
446 |
|
433 |
before => "", |
447 |
my $info = $get_info->('', 'Foo', $attribute_type->code); |
434 |
after => 'Foo', |
|
|
435 |
}; |
436 |
my $info = "Patron attribute " . $attribute_type->code . ": " . to_json($change, { pretty => 1, canonical => 1 }); |
437 |
my $action_logs = Koha::ActionLogs->search( |
448 |
my $action_logs = Koha::ActionLogs->search( |
438 |
{ |
449 |
{ |
439 |
module => "MEMBERS", |
450 |
module => "MEMBERS", |
Lines 447-510
subtest 'action log tests' => sub {
Link Here
|
447 |
0, |
458 |
0, |
448 |
'No action log entry has been created when adding patron attribute if BorrowersLog syspref disabled' |
459 |
'No action log entry has been created when adding patron attribute if BorrowersLog syspref disabled' |
449 |
); |
460 |
); |
450 |
$patron->extended_attributes([]); |
|
|
451 |
|
461 |
|
452 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
462 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
453 |
$patron->extended_attributes($attributes); |
463 |
my $current_action_logs_count; |
454 |
$action_logs = Koha::ActionLogs->search( |
464 |
my $repeatable_text; |
455 |
{ |
465 |
for my $repeatable (0, 1) { |
456 |
module => "MEMBERS", |
466 |
$repeatable_text = $repeatable ? ' repeatable' : ''; |
457 |
action => "MODIFY", |
|
|
458 |
object => $patron->borrowernumber, |
459 |
info => $info |
460 |
} |
461 |
); |
462 |
is( |
463 |
$action_logs->count, |
464 |
1, |
465 |
'An action log entry has been created when adding patron attribute' |
466 |
); |
467 |
|
467 |
|
468 |
$patron->extended_attributes($attributes); |
468 |
$patron->extended_attributes([]); |
469 |
$action_logs = Koha::ActionLogs->search( |
|
|
470 |
{ |
471 |
module => "MEMBERS", |
472 |
action => "MODIFY", |
473 |
object => $patron->borrowernumber, |
474 |
info => $info |
475 |
} |
476 |
); |
477 |
is( |
478 |
$action_logs->count, |
479 |
1, |
480 |
'No additional action log entry has been created when updating patron attribute with same value' |
481 |
); |
482 |
|
469 |
|
483 |
$attributes = [ |
470 |
$attribute_type = $builder->build_object( |
484 |
{ |
471 |
{ |
485 |
attribute => 'Bar', |
472 |
class => 'Koha::Patron::Attribute::Types', |
486 |
code => $attribute_type->code, |
473 |
value => { repeatable => $repeatable } |
487 |
} |
474 |
} |
488 |
]; |
475 |
); |
489 |
$patron->extended_attributes($attributes); |
476 |
$attributes = [ |
490 |
$change = { |
477 |
{ |
491 |
before => 'Foo', |
478 |
attribute => 'Foo', |
492 |
after => 'Bar' |
479 |
code => $attribute_type->code, |
493 |
}; |
480 |
} |
494 |
$info = "Patron attribute " . $attribute_type->code . ": " . to_json($change, { pretty => 1, canonical => 1 }); |
481 |
]; |
495 |
$action_logs = Koha::ActionLogs->search( |
482 |
|
496 |
{ |
483 |
$patron->extended_attributes($attributes); |
497 |
module => "MEMBERS", |
484 |
$info = $get_info->('', 'Foo', $attribute_type->code, $repeatable); |
498 |
action => "MODIFY", |
485 |
$action_logs = Koha::ActionLogs->search( |
499 |
object => $patron->borrowernumber, |
486 |
{ |
500 |
info => $info |
487 |
module => "MEMBERS", |
501 |
} |
488 |
action => "MODIFY", |
502 |
); |
489 |
object => $patron->borrowernumber, |
503 |
is( |
490 |
info => $info |
504 |
$action_logs->count, |
491 |
} |
505 |
1, |
492 |
); |
506 |
'New action log entry has been created when updating patron attribute with different value' |
493 |
is( |
507 |
); |
494 |
$action_logs->count, |
|
|
495 |
1, |
496 |
"An action log entry has been created when adding$repeatable_text patron attribute" |
497 |
); |
498 |
|
499 |
$current_action_logs_count = Koha::ActionLogs->search( |
500 |
{ |
501 |
module => "MEMBERS", |
502 |
action => "MODIFY", |
503 |
object => $patron->borrowernumber |
504 |
} |
505 |
)->count; |
506 |
|
507 |
$patron->extended_attributes($attributes); |
508 |
$action_logs = Koha::ActionLogs->search( |
509 |
{ |
510 |
module => "MEMBERS", |
511 |
action => "MODIFY", |
512 |
object => $patron->borrowernumber |
513 |
} |
514 |
); |
515 |
is( |
516 |
$action_logs->count, |
517 |
$current_action_logs_count, |
518 |
"No additional action log entry has been created when updating$repeatable_text patron attribute with same value" |
519 |
); |
520 |
|
521 |
$attributes = [ |
522 |
{ |
523 |
attribute => 'Bar', |
524 |
code => $attribute_type->code, |
525 |
} |
526 |
]; |
527 |
$patron->extended_attributes($attributes); |
528 |
$info = $get_info->('Foo', 'Bar', $attribute_type->code, $repeatable); |
529 |
$action_logs = Koha::ActionLogs->search( |
530 |
{ |
531 |
module => "MEMBERS", |
532 |
action => "MODIFY", |
533 |
object => $patron->borrowernumber, |
534 |
info => $info |
535 |
} |
536 |
); |
537 |
is( |
538 |
$action_logs->count, |
539 |
1, |
540 |
"New action log entry has been created when updating$repeatable_text patron attribute with different value" |
541 |
); |
542 |
|
543 |
$patron->extended_attributes([]); |
544 |
$info = $get_info->('Bar', '', $attribute_type->code, $repeatable); |
545 |
$action_logs = Koha::ActionLogs->search( |
546 |
{ |
547 |
module => "MEMBERS", |
548 |
action => "MODIFY", |
549 |
object => $patron->borrowernumber, |
550 |
info => $info |
551 |
} |
552 |
); |
553 |
is( |
554 |
$action_logs->count, |
555 |
1, |
556 |
"New action log entry has been created when deleting$repeatable_text patron attribute value" |
557 |
); |
558 |
} |
508 |
|
559 |
|
509 |
$schema->storage->txn_rollback; |
560 |
$schema->storage->txn_rollback; |
510 |
}; |
561 |
}; |
511 |
- |
|
|