|
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( |
| 2071 |
scalar @logs, 1, |
| 2072 |
'With CardnumberLog, one detailed MODIFY_CARDNUMBER action should be logged for the modification.' |
| 2073 |
); |
| 2074 |
|
| 2075 |
t::lib::Mocks::mock_preference( 'BorrowersLog', 0 ); |
| 2076 |
$patron->set( { cardnumber => 'TESTCARDNUMBER' } )->store; |
| 2077 |
@logs = $schema->resultset('ActionLog') |
| 2078 |
->search( { module => 'MEMBERS', action => 'MODIFY', object => $patron->borrowernumber } ); |
| 2079 |
is( |
| 2080 |
scalar @logs, 1, |
| 2081 |
'With Cardnumberlog and not BorrowersLog, no more detailed MODIFY action should be logged for the modification.' |
| 2082 |
); |
| 2083 |
@logs = $schema->resultset('ActionLog') |
| 2084 |
->search( { module => 'MEMBERS', action => 'MODIFY_CARDNUMBER', object => $patron->borrowernumber } ); |
| 2085 |
is( |
| 2086 |
scalar @logs, 2, |
| 2087 |
'With CardnumberLogs, one more detailed MODIFY_CARDNUMBER action should be logged for the modification.' |
| 2088 |
); |
| 2089 |
$log_info = from_json( $logs[1]->info ); |
| 2090 |
is( $log_info->{after}, 'TESTCARDNUMBER', 'Got correct new cardnumber' ); |
| 2091 |
is( $log_info->{before}, 'TESTCARDNUMBER_1', 'Got correct old cardnumber' ); |
| 2092 |
|
| 2093 |
t::lib::Mocks::mock_preference( 'CardnumberLog', 0 ); |
| 2094 |
$patron->set( { cardnumber => 'TESTCARDNUMBER_1' } )->store; |
| 2095 |
@logs = $schema->resultset('ActionLog') |
| 2096 |
->search( { module => 'MEMBERS', action => 'MODIFY', object => $patron->borrowernumber } ); |
| 2097 |
is( |
| 2098 |
scalar @logs, 1, |
| 2099 |
'With neither Cardnumberlog nor BorrowersLog, no more detailed MODIFY action should be logged for the modification.' |
| 2100 |
); |
| 2101 |
@logs = $schema->resultset('ActionLog') |
| 2102 |
->search( { module => 'MEMBERS', action => 'MODIFY_CARDNUMBER', object => $patron->borrowernumber } ); |
| 2103 |
is( |
| 2104 |
scalar @logs, 2, |
| 2105 |
'With neither CardnumberLog nor BorrowersLog, one detailed MODIFY_CARDNUMBER action should be logged for the modification.' |
| 2106 |
); |
| 2107 |
|
| 2060 |
}; |
2108 |
}; |
| 2061 |
$schema->storage->txn_rollback; |
2109 |
$schema->storage->txn_rollback; |
| 2062 |
|
2110 |
|
| 2063 |
- |
|
|