|
Lines 18-25
Link Here
|
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
|
|
21 |
use JSON qw( to_json ); |
| 21 |
|
22 |
|
| 22 |
use Test::More tests => 3; |
23 |
use Test::More tests => 4; |
| 23 |
|
24 |
|
| 24 |
use t::lib::TestBuilder; |
25 |
use t::lib::TestBuilder; |
| 25 |
use Test::Exception; |
26 |
use Test::Exception; |
|
Lines 27-32
use Test::Exception;
Link Here
|
| 27 |
use Koha::Database; |
28 |
use Koha::Database; |
| 28 |
use Koha::Patron::Attribute; |
29 |
use Koha::Patron::Attribute; |
| 29 |
use Koha::Patron::Attributes; |
30 |
use Koha::Patron::Attributes; |
|
|
31 |
use Koha::ActionLogs; |
| 30 |
|
32 |
|
| 31 |
my $schema = Koha::Database->new->schema; |
33 |
my $schema = Koha::Database->new->schema; |
| 32 |
my $builder = t::lib::TestBuilder->new; |
34 |
my $builder = t::lib::TestBuilder->new; |
|
Lines 404-406
subtest 'merge_and_replace_with' => sub {
Link Here
|
| 404 |
$schema->storage->txn_rollback; |
406 |
$schema->storage->txn_rollback; |
| 405 |
|
407 |
|
| 406 |
}; |
408 |
}; |
| 407 |
- |
409 |
|
|
|
410 |
subtest 'action log tests' => sub { |
| 411 |
plan tests => 3; |
| 412 |
my $schema = Koha::Database->new->schema; |
| 413 |
$schema->storage->txn_begin; |
| 414 |
|
| 415 |
my $patron = $builder->build_object({ class=> 'Koha::Patrons' }); |
| 416 |
my $attribute_type = $builder->build_object( |
| 417 |
{ |
| 418 |
class => 'Koha::Patron::Attribute::Types', |
| 419 |
value => { repeatable => 0 } |
| 420 |
} |
| 421 |
); |
| 422 |
|
| 423 |
my $attributes = [ |
| 424 |
{ |
| 425 |
attribute => 'Foo', |
| 426 |
code => $attribute_type->code, |
| 427 |
} |
| 428 |
]; |
| 429 |
$patron->extended_attributes($attributes); |
| 430 |
my $change = { |
| 431 |
before => "", |
| 432 |
after => 'Foo', |
| 433 |
}; |
| 434 |
my $info = "Patron attribute " . $attribute_type->code . ": " . to_json($change, { pretty => 1, canonical => 1 }); |
| 435 |
my $action_logs = Koha::ActionLogs->search( |
| 436 |
{ |
| 437 |
module => "MEMBERS", |
| 438 |
action => "MODIFY", |
| 439 |
object => $patron->borrowernumber, |
| 440 |
info => $info |
| 441 |
} |
| 442 |
); |
| 443 |
is( |
| 444 |
$action_logs->count, |
| 445 |
1, |
| 446 |
'An action log entry has been created when adding patron attribute' |
| 447 |
); |
| 448 |
|
| 449 |
$patron->extended_attributes($attributes); |
| 450 |
$action_logs = Koha::ActionLogs->search( |
| 451 |
{ |
| 452 |
module => "MEMBERS", |
| 453 |
action => "MODIFY", |
| 454 |
object => $patron->borrowernumber, |
| 455 |
info => $info |
| 456 |
} |
| 457 |
); |
| 458 |
is( |
| 459 |
$action_logs->count, |
| 460 |
1, |
| 461 |
'No additional action log entry has been created when updating patron attribute with same value' |
| 462 |
); |
| 463 |
|
| 464 |
$attributes = [ |
| 465 |
{ |
| 466 |
attribute => 'Bar', |
| 467 |
code => $attribute_type->code, |
| 468 |
} |
| 469 |
]; |
| 470 |
$patron->extended_attributes($attributes); |
| 471 |
$change = { |
| 472 |
before => 'Foo', |
| 473 |
after => 'Bar' |
| 474 |
}; |
| 475 |
$info = "Patron attribute " . $attribute_type->code . ": " . to_json($change, { pretty => 1, canonical => 1 }); |
| 476 |
$action_logs = Koha::ActionLogs->search( |
| 477 |
{ |
| 478 |
module => "MEMBERS", |
| 479 |
action => "MODIFY", |
| 480 |
object => $patron->borrowernumber, |
| 481 |
info => $info |
| 482 |
} |
| 483 |
); |
| 484 |
is( |
| 485 |
$action_logs->count, |
| 486 |
1, |
| 487 |
'New action log entry has been created when updating patron attribute with different value' |
| 488 |
); |
| 489 |
|
| 490 |
$schema->storage->txn_rollback; |
| 491 |
}; |