Lines 2019-2028
$nb_of_patrons = Koha::Patrons->search->count;
Link Here
|
2019 |
$retrieved_patron_1->delete; |
2019 |
$retrieved_patron_1->delete; |
2020 |
is( Koha::Patrons->search->count, $nb_of_patrons - 1, 'Delete should have deleted the patron' ); |
2020 |
is( Koha::Patrons->search->count, $nb_of_patrons - 1, 'Delete should have deleted the patron' ); |
2021 |
|
2021 |
|
2022 |
subtest 'BorrowersLog tests' => sub { |
2022 |
subtest 'BorrowersLog and CardnumberLog tests' => sub { |
2023 |
plan tests => 5; |
2023 |
plan tests => 13; |
2024 |
|
2024 |
|
2025 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
2025 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 1 ); |
|
|
2026 |
t::lib::Mocks::mock_preference( 'CardnumberLog', 0 ); |
2026 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2027 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2027 |
|
2028 |
|
2028 |
my $cardnumber = $patron->cardnumber; |
2029 |
my $cardnumber = $patron->cardnumber; |
Lines 2042-2048
subtest 'BorrowersLog tests' => sub {
Link Here
|
2042 |
->search( { module => 'MEMBERS', action => 'MODIFY', object => $patron->borrowernumber } ); |
2043 |
->search( { module => 'MEMBERS', action => 'MODIFY', object => $patron->borrowernumber } ); |
2043 |
is( scalar @logs, 1, 'With BorrowerLogs and TrackLastPatronActivityTriggers we should not spam the logs' ); |
2044 |
is( scalar @logs, 1, 'With BorrowerLogs and TrackLastPatronActivityTriggers we should not spam the logs' ); |
2044 |
|
2045 |
|
2045 |
Koha::ActionLogs->search()->delete(); |
2046 |
# Clear the logs for this patron |
|
|
2047 |
Koha::ActionLogs->search({ object => $patron->borrowernumber })->delete(); |
2046 |
$patron->get_from_storage(); |
2048 |
$patron->get_from_storage(); |
2047 |
$patron->set( { debarred => "" } ); |
2049 |
$patron->set( { debarred => "" } ); |
2048 |
$patron->store; |
2050 |
$patron->store; |
Lines 2057-2062
subtest 'BorrowersLog tests' => sub {
Link Here
|
2057 |
defined $log, |
2059 |
defined $log, |
2058 |
"No action log generated where incoming changed column is empty string and value in storage is NULL" |
2060 |
"No action log generated where incoming changed column is empty string and value in storage is NULL" |
2059 |
); |
2061 |
); |
|
|
2062 |
|
2063 |
t::lib::Mocks::mock_preference( 'CardnumberLog', 1); |
2064 |
$patron->set( { cardnumber => 'TESTCARDNUMBER_1' } )->store; |
2065 |
@logs = $schema->resultset('ActionLog') |
2066 |
->search( { module => 'MEMBERS', action => 'MODIFY', object => $patron->borrowernumber } ); |
2067 |
is( scalar @logs, 1, 'With BorrowersLog, one detailed MODIFY action should be logged for the modification.' ); |
2068 |
@logs = $schema->resultset('ActionLog') |
2069 |
->search( { module => 'MEMBERS', action => 'MODIFY_CARDNUMBER', object => $patron->borrowernumber } ); |
2070 |
is( scalar @logs, 1, 'With CardnumberLog, one detailed MODIFY_CARDNUMBER action should be logged for the modification.' ); |
2071 |
|
2072 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); |
2073 |
$patron->set( { cardnumber => 'TESTCARDNUMBER' } )->store; |
2074 |
@logs = $schema->resultset('ActionLog') |
2075 |
->search( { module => 'MEMBERS', action => 'MODIFY', object => $patron->borrowernumber } ); |
2076 |
is( scalar @logs, 1, 'With Cardnumberlog and not BorrowersLog, no more detailed MODIFY action should be logged for the modification.' ); |
2077 |
@logs = $schema->resultset('ActionLog') |
2078 |
->search( { module => 'MEMBERS', action => 'MODIFY_CARDNUMBER', object => $patron->borrowernumber } ); |
2079 |
is( scalar @logs, 2, 'With CardnumberLogs, one more detailed MODIFY_CARDNUMBER action should be logged for the modification.' ); |
2080 |
$log_info = from_json( $logs[1]->info ); |
2081 |
is( $log_info->{after}, 'TESTCARDNUMBER', 'Got correct new cardnumber' ); |
2082 |
is( $log_info->{before}, 'TESTCARDNUMBER_1', 'Got correct old cardnumber' ); |
2083 |
|
2084 |
t::lib::Mocks::mock_preference( 'CardnumberLog', 0); |
2085 |
$patron->set( { cardnumber => 'TESTCARDNUMBER_1' } )->store; |
2086 |
@logs = $schema->resultset('ActionLog') |
2087 |
->search( { module => 'MEMBERS', action => 'MODIFY', object => $patron->borrowernumber } ); |
2088 |
is( scalar @logs, 1, 'With neither Cardnumberlog nor BorrowersLog, no more detailed MODIFY action should be logged for the modification.' ); |
2089 |
@logs = $schema->resultset('ActionLog') |
2090 |
->search( { module => 'MEMBERS', action => 'MODIFY_CARDNUMBER', object => $patron->borrowernumber } ); |
2091 |
is( scalar @logs, 2, 'With niether CardnumberLog nor BorrowersLog, one detailed MODIFY_CARDNUMBER action should be logged for the modification.' ); |
2092 |
|
2093 |
|
2060 |
}; |
2094 |
}; |
2061 |
$schema->storage->txn_rollback; |
2095 |
$schema->storage->txn_rollback; |
2062 |
|
2096 |
|
2063 |
- |
|
|